예제 #1
0
 def __init__(self):
     ControlPointWB.__init__(self)
     self.running = True
     self._initial_subscribes()
     self.devices_found = []
     self.commands = {'start': self._search,
                      'stop': self._stop,
                      'list': self._cmd_list_devices,
                      'exit': self._exit,
                      'help': self._help}
예제 #2
0
    def start(self):
        self._log.debug( 'starting' )
        
        BaseHandler.start(self)
        
        self._upnpcfg['controlpoint'] = 'yes'   # force it
        
        self._controlpoint = ControlPointWB()
        
        # subscribe to gateway events that are of interest
        self._localRouter.subscribe( self._subscribeTime, self, 'http://id.webbrick.co.uk/events/time/runtime' )
        
        # subscribe to media control events
        self._localRouter.subscribe( self._subscribeTime, self, 'http://id.webbrick.co.uk/events/upnp/debug' )
        self._localRouter.subscribe( self._subscribeTime, self, 'http://id.webbrick.co.uk/events/av/transport/control' )
        self._localRouter.subscribe( self._subscribeTime, self, 'http://id.webbrick.co.uk/events/av/connection/control' )

        # subscribe to brisa events events
        self._controlpoint.subscribe('new_device_event', self.on_new_device)
        self._controlpoint.subscribe('removed_device_event', self.on_removed_device)
        
        # start the control point
        self._controlpoint.start()
        
        # TODO: Does this have to be doen here or can we do this in the stop function?
        reactor.add_after_stop_func(self._controlpoint.destroy)
        
        # start seperate thread for brisa reactor
        threading.Thread.start(self)
예제 #3
0
class UPNPBrisa( BaseHandler, threading.Thread ):
    """
        Class to provide a UPnP controlpoint based on Brisa framework
        Features: 
            -
             
        TODO:
            -     
    """   
    
    CDS_namespace = 'urn:schemas-upnp-org:service:ContentDirectory:1'
    AVT_namespace = 'urn:schemas-upnp-org:service:AVTransport:1'
    DMS_type = 'urn:schemas-upnp-org:device:MediaServer:'
    DMR_type = 'urn:schemas-upnp-org:device:MediaRenderer:'     
    
    def __init__ (self, localRouter):
        BaseHandler.__init__(self, localRouter)
        self._devicesFound = {}
        self._devicesIncluded = {}
        self._renderers = {}
        self._includeList = None
        self._excludeList = None
        self._controlpoint = None
        threading.Thread.__init__(self)
        self.setDaemon( True )

    def configure( self, cfgDict ):
        self._upnpcfg = cfgDict
        # Process excludedevice
        if self._upnpcfg.has_key('excludedevice') and self._upnpcfg['excludedevice'].has_key('modelName'):
            excs = self._upnpcfg['excludedevice']['modelName']
            self._excludeList = list()
            if isinstance( excs, list ):
                for ntry in excs:
                    self._log.debug("excludedevice %s", ntry)
                    self._excludeList.append( ntry[''].lower() )
            else:
                self._log.debug("exclude %s", excs)
                self._excludeList.append( excs[''].lower() )
        # Process includedevice    
        if self._upnpcfg.has_key('includedevice') and self._upnpcfg['includedevice'].has_key('modelName'):
            incs = self._upnpcfg['includedevice']['modelName']
            self._includeList = list()
            if isinstance( incs, list ):
                for ntry in incs:
                    self._log.debug("include %s", ntry)
                    self._includeList.append( ntry[''].lower() )
            else:
                self._log.debug("includedevice %s", incs)
                self._includeList.append( incs[''].lower() )

    def start(self):
        self._log.debug( 'starting' )
        
        BaseHandler.start(self)
        
        self._upnpcfg['controlpoint'] = 'yes'   # force it
        
        self._controlpoint = ControlPointWB()
        
        # subscribe to gateway events that are of interest
        self._localRouter.subscribe( self._subscribeTime, self, 'http://id.webbrick.co.uk/events/time/runtime' )
        
        # subscribe to media control events
        self._localRouter.subscribe( self._subscribeTime, self, 'http://id.webbrick.co.uk/events/upnp/debug' )
        self._localRouter.subscribe( self._subscribeTime, self, 'http://id.webbrick.co.uk/events/av/transport/control' )
        self._localRouter.subscribe( self._subscribeTime, self, 'http://id.webbrick.co.uk/events/av/connection/control' )

        # subscribe to brisa events events
        self._controlpoint.subscribe('new_device_event', self.on_new_device)
        self._controlpoint.subscribe('removed_device_event', self.on_removed_device)
        
        # start the control point
        self._controlpoint.start()
        
        # TODO: Does this have to be doen here or can we do this in the stop function?
        reactor.add_after_stop_func(self._controlpoint.destroy)
        
        # start seperate thread for brisa reactor
        threading.Thread.start(self)
        
         
        
    def stop(self):
        self._log.debug( 'stop' )
        self._localRouter.unsubscribe( self, 'http://id.webbrick.co.uk/events/upnp/debug' )
        self._localRouter.unsubscribe( self, 'http://id.webbrick.co.uk/events/av/transport/control' )
        self._localRouter.unsubscribe( self, 'http://id.webbrick.co.uk/events/av/connection/control' )
        
        # unsubscribe from brisa events events
        self._controlpoint.unsubscribe('new_device_event', self.on_new_device)
        self._controlpoint.unsubscribe('removed_device_event', self.on_removed_device)
        
        # stop the control point
        # TODO: Atm done in start by adding after_stop_func to raector
        # self._controlpoint.stop()

        BaseHandler.stop(self)
        print "about to stop"
        reactor.main_quit()
        
    def run(self):
        """
            Called on new thread, when the Tread is started
            Lets Brisa Reactor run on seperate thread
            NOTE: Need to avoid race conditions in the rest of the design! 
        """
        self._log.debug( 'Enter run on Brisa Reactor Thread' )
        reactor.main()
    
    def doHandleEvent( self, handler, inEvent ):
        try: 
            self._log.debug( 'doHandleEvent %s', inEvent )
            if inEvent.getType() == 'http://id.webbrick.co.uk/events/upnp/debug':
                self.doHandleUpnpDebug( inEvent )

            elif inEvent.getType() == "http://id.webbrick.co.uk/events/av/transport/control" :
                self.doHandleAVTransport( inEvent )
                
            elif inEvent.getType() == "http://id.webbrick.co.uk/events/av/connection/control" :
                self.doHandleZone( inEvent )
            
            elif inEvent.getType() == "http://id.webbrick.co.uk/events/time/runtime" :
                self.doHandleRuntime( inEvent )
            
            else:
                # unexpected 
                self._log.error( "Not expecting this event %s", inEvent.getType() )
        except Exception, ex: 
            self._log.exception(ex)

        return makeDeferred(StatusVal.OK)