Esempio n. 1
0
    def connect_service(self, object_path, uuid, ok, err):
        try:
            self.parent.Plugins.RecentConns
        except KeyError:
            logging.warning("RecentConns plugin is unavailable")
        else:
            self.parent.Plugins.RecentConns.notify(object_path, uuid)

        if uuid == '00000000-0000-0000-0000-000000000000':
            device = Device(object_path)
            device.connect(reply_handler=ok, error_handler=err)
        else:
            service = get_service(Device(object_path), uuid)

            if service.group == 'serial':
                def reply(rfcomm):
                    self.parent.Plugins.run("on_rfcomm_connected", service, rfcomm)
                    ok(rfcomm)

                rets = self.parent.Plugins.run("rfcomm_connect_handler", service, reply, err)
                if True in rets:
                    pass
                else:
                    logging.info("No handler registered")
                    err(dbus.DBusException(
                        "Service not supported\nPossibly the plugin that handles this service is not loaded"))
            else:
                def cb(_inst, ret):
                    if ret:
                        raise StopException

                if not self.parent.Plugins.run_ex("service_connect_handler", cb, service, ok, err):
                    service.connect(reply_handler=ok, error_handler=err)
Esempio n. 2
0
    def connect_service(self, object_path, uuid, ok, err):
        try:
            self.Applet.Plugins.RecentConns
        except KeyError:
            logging.warning("RecentConns plugin is unavailable")
        else:
            self.Applet.Plugins.RecentConns.notify(object_path, uuid)

        if uuid == '00000000-0000-0000-0000-000000000000':
            device = Device(object_path)
            device.connect(reply_handler=ok, error_handler=err)
        else:
            service = get_service(Device(object_path), uuid)

            if service.group == 'serial':
                def reply(rfcomm):
                    self.Applet.Plugins.Run("on_rfcomm_connected", service, rfcomm)
                    ok(rfcomm)

                rets = self.Applet.Plugins.Run("rfcomm_connect_handler", service, reply, err)
                if True in rets:
                    pass
                else:
                    logging.info("No handler registered")
                    err(dbus.DBusException(
                        "Service not supported\nPossibly the plugin that handles this service is not loaded"))
            else:
                def cb(_inst, ret):
                    if ret:
                        raise StopException

                if not self.Applet.Plugins.RunEx("service_connect_handler", cb, service, ok, err):
                    service.connect(reply_handler=ok, error_handler=err)
Esempio n. 3
0
    def connect_service(self, object_path: str, uuid: str, ok: Callable[[], None],
                        err: Callable[[Union[BluezDBusException, NMConnectionError,
                                             RFCOMMError, GLib.Error, str]], None]) -> None:
        try:
            self.parent.Plugins.RecentConns
        except KeyError:
            logging.warning("RecentConns plugin is unavailable")
        else:
            self.parent.Plugins.RecentConns.notify(object_path, uuid)

        if uuid == '00000000-0000-0000-0000-000000000000':
            device = Device(obj_path=object_path)
            device.connect(reply_handler=ok, error_handler=err)
        else:
            service = get_service(Device(obj_path=object_path), uuid)
            assert service is not None

            if any(plugin.service_connect_handler(service, ok, err)
                   for plugin in self.parent.Plugins.get_loaded_plugins(ServiceConnectHandler)):
                pass
            elif isinstance(service, SerialService):
                def reply(rfcomm: str) -> None:
                    assert isinstance(service, SerialService)  # https://github.com/python/mypy/issues/2608
                    for plugin in self.parent.Plugins.get_loaded_plugins(RFCOMMConnectedListener):
                        plugin.on_rfcomm_connected(service, rfcomm)
                    ok()

                if not any(plugin.rfcomm_connect_handler(service, reply, err)
                           for plugin in self.parent.Plugins.get_loaded_plugins(RFCOMMConnectHandler)):
                    service.connect(reply_handler=lambda port: ok(), error_handler=err)
            elif isinstance(service, NetworkService):
                service.connect(reply_handler=lambda interface: ok(), error_handler=err)
            else:
                logging.info("No handler registered")
                err("Service not supported\nPossibly the plugin that handles this service is not loaded")
Esempio n. 4
0
    def connect_service(
        self, object_path: str, uuid: str, ok: Callable[[], None],
        err: Callable[[
            Union[BluezDBusException, NMConnectionError, RFCOMMError,
                  GLib.Error, str]
        ], None]
    ) -> None:
        try:
            self.parent.Plugins.RecentConns
        except KeyError:
            logging.warning("RecentConns plugin is unavailable")
        else:
            self.parent.Plugins.RecentConns.notify(object_path, uuid)

        if uuid == '00000000-0000-0000-0000-000000000000':
            device = Device(obj_path=object_path)
            device.connect(reply_handler=ok, error_handler=err)
        else:

            def cb(_inst, ret):
                if ret:
                    raise StopException

            service = get_service(Device(obj_path=object_path), uuid)
            assert service is not None

            if isinstance(
                    service, SerialService
            ) and 'NMDUNSupport' in self.parent.Plugins.get_loaded():
                self.parent.Plugins.run_ex("service_connect_handler", cb,
                                           service, ok, err)
            elif isinstance(
                    service, SerialService
            ) and 'PPPSupport' in self.parent.Plugins.get_loaded():

                def reply(rfcomm):
                    self.parent.Plugins.run("on_rfcomm_connected", service,
                                            rfcomm)
                    ok()

                rets = self.parent.Plugins.run("rfcomm_connect_handler",
                                               service, reply, err)
                if True in rets:
                    pass
                else:
                    logging.info("No handler registered")
                    err("Service not supported\nPossibly the plugin that handles this service is not loaded"
                        )
            else:
                if not self.parent.Plugins.run_ex("service_connect_handler", cb, service, ok, err) \
                        and isinstance(service, (SerialService, NetworkService)):
                    service.connect(reply_handler=lambda *args: ok(),
                                    error_handler=err)