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.
This commit is contained in:
Benjamin Tissoires 2018-01-19 15:26:49 +01:00 committed by Peter Hutterer
parent 45196fbdca
commit ea890958d6
2 changed files with 25 additions and 4 deletions

22
tuhi.py
View File

@ -118,8 +118,9 @@ class TuhiDevice(GObject.Object):
assert self._tuhi_dbus_device is None assert self._tuhi_dbus_device is None
self._tuhi_dbus_device = device self._tuhi_dbus_device = device
self._tuhi_dbus_device.connect('pair-requested', self._on_pair_requested) 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): def listening(self):
return self._tuhi_dbus_device.listening 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.config.new_device(bluez_device.address, wacom_device.uuid)
self.paired = True self.paired = True
def _on_listening_updated(self, dbus_device, pspec):
self.notify('listening')
class Tuhi(GObject.Object): class Tuhi(GObject.Object):
__gsignals__ = { __gsignals__ = {
@ -246,6 +250,9 @@ class Tuhi(GObject.Object):
if self._search_stop_handler is not None: if self._search_stop_handler is not None:
self._search_stop_handler(0) 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): def _on_bluez_device_updated(self, manager, bluez_device):
if bluez_device.vendor_id != WACOM_COMPANY_ID: if bluez_device.vendor_id != WACOM_COMPANY_ID:
return return
@ -266,6 +273,7 @@ class Tuhi(GObject.Object):
if bluez_device.address not in self.devices: if bluez_device.address not in self.devices:
d = TuhiDevice(bluez_device, self.config, uuid=uuid, paired=not pairing_device) d = TuhiDevice(bluez_device, self.config, uuid=uuid, paired=not pairing_device)
d.dbus_device = self.server.create_device(d) d.dbus_device = self.server.create_device(d)
d.connect('notify::listening', self._on_listening_updated)
self.devices[bluez_device.address] = d self.devices[bluez_device.address] = d
d = self.devices[bluez_device.address] d = self.devices[bluez_device.address]
@ -275,6 +283,18 @@ class Tuhi(GObject.Object):
elif d.listening: elif d.listening:
d.connect_device() 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): def main(args):
desc = "Daemon to extract the pen stroke data from Wacom SmartPad devices" desc = "Daemon to extract the pen stroke data from Wacom SmartPad devices"

View File

@ -232,8 +232,8 @@ class TuhiDBusDevice(GObject.Object):
self._listening_client = (sender, s) self._listening_client = (sender, s)
logger.debug('Listening started on {} for {}'.format(self.name, sender)) 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, def _on_name_owner_changed_signal_cb(self, connection, sender, object_path,
interface_name, node, interface_name, node,
@ -252,13 +252,14 @@ class TuhiDBusDevice(GObject.Object):
self._listening_client = None self._listening_client = None
logger.debug('Listening stopped on {} for {}'.format(self.name, sender)) 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_int32(0)
status = GLib.Variant.new_tuple(status) status = GLib.Variant.new_tuple(status)
connection.emit_signal(sender, self.objpath, INTF_DEVICE, connection.emit_signal(sender, self.objpath, INTF_DEVICE,
"ListeningStopped", status) "ListeningStopped", status)
self.listening = False self.listening = False
self.notify('listening')
def _json_data(self, args): def _json_data(self, args):
index = args[0] index = args[0]