From ea890958d6c85729cf8d67a95d3a982d58c98828 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Fri, 19 Jan 2018 15:26:49 +0100 Subject: [PATCH] Start discovery mode when one device requests it We need to check when the discovery stops (timeout from StartSearch) if we should keep the discover one or not. --- tuhi.py | 22 +++++++++++++++++++++- tuhi/dbusserver.py | 7 ++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/tuhi.py b/tuhi.py index 686bdbc..06c8886 100755 --- a/tuhi.py +++ b/tuhi.py @@ -118,8 +118,9 @@ class TuhiDevice(GObject.Object): assert self._tuhi_dbus_device is None self._tuhi_dbus_device = device self._tuhi_dbus_device.connect('pair-requested', self._on_pair_requested) + self._tuhi_dbus_device.connect('notify::listening', self._on_listening_updated) - @property + @GObject.Property def listening(self): return self._tuhi_dbus_device.listening @@ -186,6 +187,9 @@ class TuhiDevice(GObject.Object): self.config.new_device(bluez_device.address, wacom_device.uuid) self.paired = True + def _on_listening_updated(self, dbus_device, pspec): + self.notify('listening') + class Tuhi(GObject.Object): __gsignals__ = { @@ -246,6 +250,9 @@ class Tuhi(GObject.Object): if self._search_stop_handler is not None: self._search_stop_handler(0) + # restart discovery if some users are already in the listening mode + self._on_listening_updated(None, None) + def _on_bluez_device_updated(self, manager, bluez_device): if bluez_device.vendor_id != WACOM_COMPANY_ID: return @@ -266,6 +273,7 @@ class Tuhi(GObject.Object): if bluez_device.address not in self.devices: d = TuhiDevice(bluez_device, self.config, uuid=uuid, paired=not pairing_device) d.dbus_device = self.server.create_device(d) + d.connect('notify::listening', self._on_listening_updated) self.devices[bluez_device.address] = d d = self.devices[bluez_device.address] @@ -275,6 +283,18 @@ class Tuhi(GObject.Object): elif d.listening: d.connect_device() + def _on_listening_updated(self, tuhi_dbus_device, pspec): + listen = False + for dev in self.devices.values(): + if dev.listening: + listen = True + break + + if listen: + self.bluez.start_discovery() + else: + self.bluez.stop_discovery() + def main(args): desc = "Daemon to extract the pen stroke data from Wacom SmartPad devices" diff --git a/tuhi/dbusserver.py b/tuhi/dbusserver.py index 7e43bb9..ff65a31 100755 --- a/tuhi/dbusserver.py +++ b/tuhi/dbusserver.py @@ -232,8 +232,8 @@ class TuhiDBusDevice(GObject.Object): self._listening_client = (sender, s) logger.debug('Listening started on {} for {}'.format(self.name, sender)) - # FIXME: notify the server to start discovery - self.listening = True + self._listening = True + self.notify('listening') def _on_name_owner_changed_signal_cb(self, connection, sender, object_path, interface_name, node, @@ -252,13 +252,14 @@ class TuhiDBusDevice(GObject.Object): self._listening_client = None logger.debug('Listening stopped on {} for {}'.format(self.name, sender)) - # FIXME: notify the server to stop discovery + self.notify('listening') status = GLib.Variant.new_int32(0) status = GLib.Variant.new_tuple(status) connection.emit_signal(sender, self.objpath, INTF_DEVICE, "ListeningStopped", status) self.listening = False + self.notify('listening') def _json_data(self, args): index = args[0]