Exemplo n.º 1
0
    def __init__(self):
        self.paths = path()
        bus_name = dbus.service.BusName("custom.LBRC", bus=dbus.SessionBus())
        dbus.service.Object.__init__(self, bus_name, "/custom/LBRC")
        self.btserver = BTServer()

        self.config = config()

        self.event_listener = []

        for i in (UinputDispatcher, CommandExecutor, DBUSCaller, ProfileSwitcher, MPlayer):
            self._register_listener(i)

        # load of config data
        self.cur_profile = None
        self.reload_config()

        self.btserver.connect("keycode", self.handler)
        self.btserver.connect(
            "connect", lambda btserver, btadress, port: self.connect_cb(bluetooth.lookup_name(btadress), btadress, port)
        )
        self.btserver.connect(
            "disconnect",
            lambda btserver, btadress, port: self.disconnect_cb(bluetooth.lookup_name(btadress), btadress, port),
        )
        # load the default profile
        self._load_default_profile()
Exemplo n.º 2
0
    def __init__(self, **kwds):
        self.logger = logging.getLogger('LBRC')
        self.shutdown_commands = []
        bus_name = dbus.service.BusName(DBUSNAME, bus=dbus.SessionBus())
        dbus.service.Object.__init__(self, bus_name, "/core")
        
        self.loghandler = DBUSLogHandler(bus_name, "/log")
        logging.getLogger().addHandler(self.loghandler)
        if 'debug' in kwds:
            self.loghandler.setLevel(kwds['debug'])
            
        self.paths = path()
        self.btserver = BTServer()
        self.config = config()
        
        self.profile_control = ProfileControl(self.config)
        self.dbus_profile_control = DBUSProfileControl(bus_name,
                                                       "/profile",
                                                       self.profile_control)
        self.connection_control = ConnectionControl(bus_name, 
                                                    "/connection", 
                                                    self.btserver)
        
        self.event_listener = []
        
        for i in (UinputDispatcher, CommandExecutor, DBUSCaller, 
                  ProfileSwitcher, MPlayer, PresentationCompanion,
                  VolumeControl, XInput):
            self._register_listener(i)

        self.logger.debug("Register done")
        self.profile_control.connect("profile_changed", self._profile_change_cb)
        self.logger.debug("Initial Profile set")
        self.btserver.connect('keycode', self._dispatch)
        self.logger.debug("Init dispatcher")

        self.btserver.connect("connect", self._connection_established_cb)
        self.btserver.connect("disconnect", self._connection_closed_cb)

        #load of config data 
        self.reload_config()
        self.logger.debug("Reload config")
Exemplo n.º 3
0
class LBRCdbus(dbus.service.Object):
    def __init__(self):
        self.paths = path()
        bus_name = dbus.service.BusName("custom.LBRC", bus=dbus.SessionBus())
        dbus.service.Object.__init__(self, bus_name, "/custom/LBRC")
        self.btserver = BTServer()

        self.config = config()

        self.event_listener = []

        for i in (UinputDispatcher, CommandExecutor, DBUSCaller, ProfileSwitcher, MPlayer):
            self._register_listener(i)

        # load of config data
        self.cur_profile = None
        self.reload_config()

        self.btserver.connect("keycode", self.handler)
        self.btserver.connect(
            "connect", lambda btserver, btadress, port: self.connect_cb(bluetooth.lookup_name(btadress), btadress, port)
        )
        self.btserver.connect(
            "disconnect",
            lambda btserver, btadress, port: self.disconnect_cb(bluetooth.lookup_name(btadress), btadress, port),
        )
        # load the default profile
        self._load_default_profile()

    def _register_listener(self, constructor):
        # TODO: at some point we have to do conflict resolving (when we define what is a conflict ...)
        try:
            listener = constructor(self.config)
            try:
                listener.set_bluetooth_connector(self.btserver)
            except AttributeError:
                pass
            try:
                listener.set_core(self)
            except AttributeError:
                pass
            self.event_listener.append(listener)
        except Exception, e:
            logging.warn("Failed to initalize " + str(constructor) + "\n" + str(e))
            return
Exemplo n.º 4
0
class Core(dbus.service.Object):
    def __init__(self, **kwds):
        self.logger = logging.getLogger('LBRC')
        self.shutdown_commands = []
        bus_name = dbus.service.BusName(DBUSNAME, bus=dbus.SessionBus())
        dbus.service.Object.__init__(self, bus_name, "/core")
        
        self.loghandler = DBUSLogHandler(bus_name, "/log")
        logging.getLogger().addHandler(self.loghandler)
        if 'debug' in kwds:
            self.loghandler.setLevel(kwds['debug'])
            
        self.paths = path()
        self.btserver = BTServer()
        self.config = config()
        
        self.profile_control = ProfileControl(self.config)
        self.dbus_profile_control = DBUSProfileControl(bus_name,
                                                       "/profile",
                                                       self.profile_control)
        self.connection_control = ConnectionControl(bus_name, 
                                                    "/connection", 
                                                    self.btserver)
        
        self.event_listener = []
        
        for i in (UinputDispatcher, CommandExecutor, DBUSCaller, 
                  ProfileSwitcher, MPlayer, PresentationCompanion,
                  VolumeControl, XInput):
            self._register_listener(i)

        self.logger.debug("Register done")
        self.profile_control.connect("profile_changed", self._profile_change_cb)
        self.logger.debug("Initial Profile set")
        self.btserver.connect('keycode', self._dispatch)
        self.logger.debug("Init dispatcher")

        self.btserver.connect("connect", self._connection_established_cb)
        self.btserver.connect("disconnect", self._connection_closed_cb)

        #load of config data 
        self.reload_config()
        self.logger.debug("Reload config")

    def _connection_closed_cb(self, server, bluetoothaddress, port):
        self.logger.debug("_connection_closed_cb called")
        for listener in self.event_listener:
            if callable(listener.__getattribute__("connection_closed")):
                listener.connection_closed()
        return False
            
    def _connection_established_cb(self, server, bluetoothaddress, port):
        self.logger.debug("_connection_established_cb called")
        for listener in self.event_listener:
            if callable(listener.__getattribute__("connection_established")):
                listener.connection_established()
        return False

    def _profile_change_cb(self, profile_control, config_file, profile):
        self.logger.debug("Recieved signal to switch to %s profile %s"%(config_file, profile))
        for listener in self.event_listener:
            listener.set_profile(config_file, profile)

    def _register_listener(self, constructor):
        try: 
            listener = constructor(self.config)
            if callable(listener.__getattribute__('set_bluetooth_connector')):
                listener.set_bluetooth_connector(self.btserver)
            if callable(listener.__getattribute__('set_core')):
                listener.set_core(self)
            self.event_listener.append(listener)
            self.logger.debug("Initialized Event Listener: %s" 
                                                     % str(constructor))
        except Exception, exception: 
            self.logger.warn("Failed to initalize %s\n%s" %(str(constructor),
                                                            str(exception)))
Exemplo n.º 5
0
class Core(dbus.service.Object):
    def __init__(self, **kwds):
        self.shutdown_commands = []
        bus_name = dbus.service.BusName(DBUSNAME, bus=dbus.SessionBus())
        dbus.service.Object.__init__(self, bus_name, "/core")
        
        self.loghandler = DBUSLogHandler(bus_name, "/log")
        logging.getLogger().addHandler(self.loghandler)
        if 'debug' in kwds:
            self.loghandler.setLevel(kwds['debug'])
            
        self.paths = path()
        self.btserver = BTServer()
        self.config = config()
        
        self.profile_control = ProfileControl(self.config)
        self.dbus_profile_control = DBUSProfileControl(bus_name, "/profile", self.profile_control)
        self.connection_control = ConnectionControl(bus_name, "/connection", self.btserver)
        
        self.event_listener = []
        
        for i in (UinputDispatcher, CommandExecutor, DBUSCaller, ProfileSwitcher, 
                  MPlayer, PresentationCompanion, VolumeControl):
            self._register_listener(i)

        logging.debug("Register done")
        self.profile_control.connect("profile_changed", self._profile_change_cb)
        logging.debug("Initial Profile set")
        self.btserver.connect('keycode', self._dispatch)
        logging.debug("Init dispatcher")

        self.btserver.connect("connect", self._connection_established_cb)
        self.btserver.connect("disconnect", self._connection_closed_cb)

        #load of config data 
        self.reload_config()
        logging.debug("Reload config")

    def _connection_closed_cb(self, server, bluetoothaddress, port):
        logging.debug("_connection_closed_cb called")
        for listener in self.event_listener:
            try:
                listener.connection_closed()
            except AttributeError:
                pass
        return False
            
    def _connection_established_cb(self, server, bluetoothaddress, port):
        logging.debug("_connection_established_cb called")
        for listener in self.event_listener:
            try:
                listener.connection_established()
            except AttributeError:
                pass
        return False

    def _profile_change_cb(self, profile_control, config, profile):
        for listener in self.event_listener:
            listener.set_profile(config, profile)

    def _register_listener(self, constructor):
        # TODO: at some point we have to do conflict resolving (when we define what is a conflict ...)
        try: 
            listener = constructor(self.config)
            try: listener.set_bluetooth_connector(self.btserver)
            except AttributeError: pass
            try: listener.set_core(self)
            except AttributeError: pass
            self.event_listener.append(listener)
            logging.debug("Initiablized Event Listener: " + str(constructor))
        except Exception, e: 
            logging.warn("Failed to initalize " + str(constructor) + "\n" + str(e))
            return