def main():
    """ Main loop iteration receiving input commands.
    """
    c = create_control_point()
    c.start()
    run_async_function(_handle_cmds, (c, ))
    reactor.add_after_stop_func(c.stop)
    reactor.main()
def main():
    """ Main loop iteration receiving input commands.
    """
    c = create_control_point()
    c.start()
    run_async_function(_handle_cmds, (c, ))
    reactor.add_after_stop_func(c.stop)
    reactor.main()
Example #3
0
    def __init__(self):

        self.control_point = ControlPointSonos(self.ws_port)
        self.control_point.subscribe("new_device_event", self.on_new_device)
        self.control_point.subscribe("removed_device_event", self.on_del_device)
        self.control_point.subscribe('device_event_seq', self.on_device_event_seq)
        self.control_point.start()

        # start MSEARCH
        run_async_function(self.control_point.start_search, (600.0, "ssdp:all"), 0.001)
Example #4
0
 def start(self):
     """ Starts the webserver.
     """
     if not self.is_running():
         if not self.adapter:
             raise RuntimeError('Adapter not set.')
         threaded_call.run_async_function(self.adapter.start)
         self.running = True
     else:
         log.warning(self.msg_already_started)
Example #5
0
 def start(self):
     """ Starts the webserver.
     """
     if not self.is_running():
         if not self.adapter:
             raise RuntimeError('Adapter not set.')
         threaded_call.run_async_function(self.adapter.start)
         self.running = True
     else:
         log.warning(self.msg_already_started)
Example #6
0
    def send_data(self, data, address):
        """ Sends data to the specified address. This is a non-blocking method.

        @param data: raw data
        @param host: target host
        @param port: target port

        @type data: string
        @type host: string
        @type port: integer
        """
        (host, port) = address
        run_async_function(self._send_data, (data, (host, port)))
Example #7
0
    def forward_data(self, data, addr=''):
        """ Forwards data to the subscribed observers and to the data callback.

        @param data: raw data to be forwarded
        @param addr: can be a 2-tuple (host, port)

        @type data: string
        @type addr: None or tuple
        """
#        print "@@@@@@@@ FORWARD DATA: " + str(self.data_callback) + " obs: " + str(self.observers)
#@@@@@@@@ FORWARD DATA: <bound method MSearch._datagram_received of <brisa.upnp.control_point.msearch.MSearch object at 0x250bf10>> obs: [<brisa.upnp.ssdp.SSDPServer object at 0x7f57b005d2d0>]
#@@@@@@@@ FORWARD DATA: <bound method SSDPServer._datagram_received of <brisa.upnp.ssdp.SSDPServer object at 0x250bdd0>> obs: [<brisa.upnp.ssdp.SSDPServer object at 0x7f57b005d2d0>]
#        print "######## NetworkListener forward data: " + str(data)
#        print "######## NetworkListener forward addr: " + str(addr)
#        print self.data_callback.__name__
#        c = str(self.data_callback.im_class)
#        if 'SSDP' in c:
#            print "SSDP"

#        print self.observers

        for listener in self.observers:
            if addr:
#                run_async_function(listener.data_received, (data, addr))
                run_async_function(listener._datagram_received, (data, addr))
            else:
#                run_async_function(listener.data_received, (data, ()))
                run_async_function(listener._datagram_received, (data, ()))

        if self.data_callback:
            if addr:
                run_async_function(self.data_callback, (data, addr))
            else:
                run_async_function(self.data_callback, (data, ()))
Example #8
0
    def render_NOTIFY(self, request, response):
        """ Renders the notify message for an event.

        @param request: request object (Cherrypy)
        @param response: response object (Cherrypy)

        @note: see Cherrypy documentation for further info about request and
        response attributes and methods.
        """
        data = request.read()
        # extraneous characters after the end of XML will choke ElementTree
        data = data[data.find("<") : data.rfind(">") + 1]

        run_async_function(self.forward_notification, (request.headers, data), 0.0001)
        return ""
Example #9
0
    def render_NOTIFY(self, request, response):
        """ Renders the notify message for an event.

        @param request: request object (Cherrypy)
        @param response: response object (Cherrypy)

        @note: see Cherrypy documentation for further info about request and
        response attributes and methods.
        """
        data = request.read()
        # extraneous characters after the end of XML will choke ElementTree
        data = data[data.find("<"):data.rfind(">") + 1]

        run_async_function(self.forward_notification, (request.headers, data),
                           0.0001)
        return ""
    def run(self):
        self.running = True

        self._load()
        self.root_device.start()
        run_async_function(reactor.main)
        try:
            while self.running:
                command = str(raw_input('>>> '))

                if command.find('set_var') == 0:
                    new_value = command.split(' ')[1]
                    self.myservice.set_state_variable('A_ARG_TYPE_Textin', new_value)
                else:        
                    try:
                        self.commands[command]()
                    except KeyError:
                        print 'invalid command, try help'
                command = ''
        except KeyboardInterrupt, k:
            pass
Example #11
0
    def forward_data(self, data, addr=''):
        """ Forwards data to the subscribed observers and to the data callback.

        @param data: raw data to be forwarded
        @param addr: can be a 2-tuple (host, port)

        @type data: string
        @type addr: None or tuple
        """
        for listener in self.observers:
            if addr:
                run_async_function(listener.data_received, (data, addr))
            else:
                run_async_function(listener.data_received, (data, ()))

        if self.data_callback:
            if addr:
                run_async_function(self.data_callback, (data, addr))
            else:
                run_async_function(self.data_callback, (data, ()))
    def forward_data(self, data, addr=''):
        """ Forwards data to the subscribed observers and to the data callback.

        @param data: raw data to be forwarded
        @param addr: can be a 2-tuple (host, port)

        @type data: string
        @type addr: None or tuple
        """
        for listener in self.observers:
            if addr:
                run_async_function(listener.data_received, (data, addr))
            else:
                run_async_function(listener.data_received, (data, ()))

        if self.data_callback:
            if addr:
                run_async_function(self.data_callback, (data, addr))
            else:
                run_async_function(self.data_callback, (data, ()))
Example #13
0
class TCPTransport(object):
    # TODO fixme to use thread manager fd facility
    """ Provides methods for sending data through TCP. Receiving host must be
    listening for connections.
    """
    def __init__(self):
        """ Constructor for the TCPTransport class.
        """
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    def send_data(self, data, (host, port)):
        """ Sends data to the specified address. This is a non-blocking method.

        @param data: raw data
        @param host: target host
        @param port: target port

        @type data: string
        @type host: string
        @type port: integer
        """
        run_async_function(self._send_data, (data, (host, port)))
Example #14
0
    self.service = 'urn:schemas-icucinema-co-uk:service:Lighting:1'
    self.utype = 'urn:schemas-icucinema-co-uk:device:LXDesk:1'

  def device_found(self, dev):
    print "Found Lighting controller"
    self.dev = dev

  def set(self, up, down):
    d = self.dev.get_service_by_type(self.service)
    d.SetLevels(UpLevel=int(up), DownLevel=int(down))

cp500_ctl = CP500Controller()
cp500_ctl.start()
cp500_ctl.start_search(2, cp500_ctl.utype)
reactor.add_after_stop_func(cp500_ctl.destroy)

screen_ctl = ScreenController()
screen_ctl.start()
screen_ctl.start_search(2, screen_ctl.utype)
reactor.add_after_stop_func(screen_ctl.destroy)

lx_ctl = LXController()
lx_ctl.start()
lx_ctl.start_search(2, lx_ctl.utype)
reactor.add_after_stop_func(lx_ctl.destroy)

if __name__ == "__main__":
  server = SocketServer.UDPServer(('', 9999), CommandServer)
  run_async_function(server.serve_forever)
  reactor.main()
def main():
    c = create()
    c.start()
    reactor.add_after_stop_func(c.stop)
    run_async_function(run, (c, ))
    reactor.main()
Example #16
0
 def run(self):
     self.start()
     run_async_function(self._handle_cmds)
     reactor.add_after_stop_func(self.stop)
     reactor.main()
Example #17
0
def main():
    c = create() # create control point
    c.start()
    reactor.add_after_stop_func(c.stop)
    run_async_function(run, (c, ))
    reactor.main()