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:
parent
45196fbdca
commit
ea890958d6
22
tuhi.py
22
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"
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in New Issue