Esempio n. 1
0
    def connect_service(self, object_path, uuid, ok, err):
        service = get_service(Device(object_path), uuid)

        try:
            self.Applet.Plugins.RecentConns
        except KeyError:
            dprint("RecentConns plugin is unavailable")
        else:
            self.Applet.Plugins.RecentConns.notify(service)

        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:
                dprint("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. 2
0
    def _disconnect_service(self, object_path, uuid, port, ok, err):
        if uuid == '00000000-0000-0000-0000-000000000000':
            device = Device(object_path)
            device.disconnect(reply_handler=ok, error_handler=err)
        else:

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

            service = get_service(Device(object_path), uuid)

            if service.group == 'serial' and 'NMDUNSupport' in self.parent.Plugins.get_loaded(
            ):
                self.parent.Plugins.run_ex("service_disconnect_handler", cb,
                                           service, ok, err)
            elif service.group == 'serial' and 'PPPSupport' in self.parent.Plugins.get_loaded(
            ):
                service.disconnect(port, reply_handler=ok, error_handler=err)

                self.parent.Plugins.run("on_rfcomm_disconnect", port)

                logging.info("Disconnecting rfcomm device")
            else:
                if not self.parent.Plugins.run_ex("service_disconnect_handler",
                                                  cb, service, ok, err):
                    service.disconnect(reply_handler=ok, error_handler=err)
Esempio n. 3
0
    def _disconnect_service(
        self, object_path: str, uuid: str, port: int, ok: Callable[[], None],
        err: Callable[
            [Union[BluezDBusException, NMConnectionError, GLib.Error,
                   str]], None]
    ) -> None:
        if uuid == '00000000-0000-0000-0000-000000000000':
            device = Device(obj_path=object_path)
            device.disconnect(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_disconnect_handler", cb,
                                           service, ok, err)
            elif isinstance(
                    service, SerialService
            ) and 'PPPSupport' in self.parent.Plugins.get_loaded():
                service.disconnect(port, reply_handler=ok, error_handler=err)

                self.parent.Plugins.run("on_rfcomm_disconnect", port)

                logging.info("Disconnecting rfcomm device")
            else:
                if not self.parent.Plugins.run_ex("service_disconnect_handler", cb, service, ok, err) \
                        and isinstance(service, NetworkService):
                    service.disconnect(reply_handler=ok, error_handler=err)
Esempio n. 4
0
    def connect_service(self, object_path, uuid, ok, err):
        service = get_service(Device(object_path), uuid)

        try:
            self.Applet.Plugins.RecentConns
        except KeyError:
            dprint("RecentConns plugin is unavailable")
        else:
            self.Applet.Plugins.RecentConns.notify(service)

        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:
                dprint("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. 5
0
    def _disconnect_service(
        self, object_path: str, uuid: str, port: int, ok: Callable[[], None],
        err: Callable[
            [Union[BluezDBusException, "NMConnectionError", GLib.Error,
                   str]], None]
    ) -> None:
        if uuid == '00000000-0000-0000-0000-000000000000':
            device = Device(obj_path=object_path)
            device.disconnect(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_disconnect_handler(service, ok, err)
                    for plugin in self.parent.Plugins.get_loaded_plugins(
                        ServiceConnectHandler)):
                pass
            elif isinstance(service, SerialService):
                service.disconnect(port, reply_handler=ok, error_handler=err)

                for plugin in self.parent.Plugins.get_loaded_plugins(
                        RFCOMMConnectedListener):
                    plugin.on_rfcomm_disconnect(port)

                logging.info("Disconnecting rfcomm device")
            elif isinstance(service, NetworkService):
                service.disconnect(reply_handler=ok, error_handler=err)
Esempio n. 6
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. 7
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)
Esempio n. 8
0
    def disconnect_service(self, object_path, uuid, port, ok, err):
        service = get_service(Device(object_path), uuid)

        if service.group == 'serial':
            service.disconnect(port)

            self.Applet.Plugins.Run("on_rfcomm_disconnect", port)

            dprint("Disonnecting rfcomm device")
        else:

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

            if not self.Applet.Plugins.RunEx("service_disconnect_handler", cb, service, ok, err):
                service.disconnect(reply_handler=ok, error_handler=err)
Esempio n. 9
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:

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

            service = get_service(Device(object_path), uuid)

            if service.group == 'serial' and 'NMDUNSupport' in self.QueryPlugins(
            ):
                self.parent.Plugins.run_ex("service_connect_handler", cb,
                                           service, ok, err)
            elif service.group == 'serial' and 'PPPSupport' in self.QueryPlugins(
            ):

                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:
                if not self.parent.Plugins.run_ex("service_connect_handler",
                                                  cb, service, ok, err):
                    service.connect(reply_handler=ok, error_handler=err)
Esempio n. 10
0
    def disconnect_service(self, object_path, uuid, port, ok, err):
        service = get_service(Device(object_path), uuid)

        if service.group == 'serial':
            service.disconnect(port)

            self.Applet.Plugins.Run("on_rfcomm_disconnect", port)

            dprint("Disonnecting rfcomm device")
        else:

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

            if not self.Applet.Plugins.RunEx("service_disconnect_handler", cb,
                                             service, ok, err):
                service.disconnect(reply_handler=ok, error_handler=err)
Esempio n. 11
0
    def disconnect_service(self, object_path, uuid, port, ok, err):
        if uuid == '00000000-0000-0000-0000-000000000000':
            device = Device(object_path)
            device.disconnect(reply_handler=ok, error_handler=err)
        else:
            service = get_service(Device(object_path), uuid)

            if service.group == 'serial':
                service.disconnect(port, reply_handler=ok, error_handler=err)

                self.parent.Plugins.run("on_rfcomm_disconnect", port)

                logging.info("Disconnecting rfcomm device")
            else:

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

                if not self.parent.Plugins.run_ex("service_disconnect_handler", cb, service, ok, err):
                    service.disconnect(reply_handler=ok, error_handler=err)