Add a SyncState signal to the DBus interface

Propagated whenever we start talking to the device (and then again when we
stop). The purpose of this signal is merely that a UI can show e.g. a progress
bar while we're talking to the device to ensure the user something is
happening.

Fixes #138
pull/146/head
Peter Hutterer 2019-07-14 18:32:34 +10:00 committed by Benjamin Tissoires
parent 05fd213940
commit b16a16abde
5 changed files with 50 additions and 0 deletions

View File

@ -378,6 +378,15 @@ org.freedesktop.tuhi1.Device
These errnos indicate a bug in the daemon, and the client should These errnos indicate a bug in the daemon, and the client should
display a message to that effect. display a message to that effect.
Signal: SyncState(i)
An enum to represent the current synchronization state of the device.
When on (1), Tuhi is currently trying to download data from the
device. When off (0), Tuhi is not currently connecting to the device.
This signal should be used for UI feedback.
This signal is only send when the device is **not** in Live mode.
``` ```
JSON File Format JSON File Format

View File

@ -285,6 +285,13 @@ class TuhiKeteDevice(_DBusObject):
elif err < 0: elif err < 0:
logger.error(f'{self}: an error occured: {os.strerror(-err)}') logger.error(f'{self}: an error occured: {os.strerror(-err)}')
self.notify('listening') self.notify('listening')
elif signal == 'SyncState':
state = parameters[0]
if state:
logger.debug(f'{self}: Downloading from device')
else:
logger.debug(f'{self}: Download done')
def _on_properties_changed(self, proxy, changed_props, invalidated_props): def _on_properties_changed(self, proxy, changed_props, invalidated_props):
if changed_props is None: if changed_props is None:

View File

@ -146,6 +146,10 @@ class TuhiDevice(GObject.Object):
def battery_state(self, value): def battery_state(self, value):
self._battery_state = value self._battery_state = value
@GObject.Property
def sync_state(self):
return self._sync_state
def _connect_device(self, mode): def _connect_device(self, mode):
self._signals['connected'] = self._bluez_device.connect('connected', self._on_bluez_device_connected, mode) self._signals['connected'] = self._bluez_device.connect('connected', self._on_bluez_device_connected, mode)
self._signals['disconnected'] = self._bluez_device.connect('disconnected', self._on_bluez_device_disconnected) self._signals['disconnected'] = self._bluez_device.connect('disconnected', self._on_bluez_device_disconnected)
@ -166,6 +170,7 @@ class TuhiDevice(GObject.Object):
self._wacom_device.connect('button-press-required', self._on_button_press_required) self._wacom_device.connect('button-press-required', self._on_button_press_required)
self._wacom_device.connect('notify::uuid', self._on_uuid_updated, bluez_device) self._wacom_device.connect('notify::uuid', self._on_uuid_updated, bluez_device)
self._wacom_device.connect('battery-status', self._on_battery_status, bluez_device) self._wacom_device.connect('battery-status', self._on_battery_status, bluez_device)
self._wacom_device.connect('notify::sync-state', self._on_sync_state)
if mode == DeviceMode.REGISTER: if mode == DeviceMode.REGISTER:
self._wacom_device.start_register() self._wacom_device.start_register()
@ -180,6 +185,10 @@ class TuhiDevice(GObject.Object):
except KeyError: except KeyError:
pass pass
def _on_sync_state(self, device, pspec):
self._sync_state = device.sync_state
self.notify('sync-state')
def _on_bluez_device_disconnected(self, bluez_device): def _on_bluez_device_disconnected(self, bluez_device):
logger.debug(f'{bluez_device.address}: disconnected') logger.debug(f'{bluez_device.address}: disconnected')
try: try:

View File

@ -106,6 +106,10 @@ INTROSPECTION_XML = '''
<signal name='LiveStopped'> <signal name='LiveStopped'>
<arg name='status' type='i' /> <arg name='status' type='i' />
</signal> </signal>
<signal name='SyncState'>
<arg name='status' type='i' />
</signal>
</interface> </interface>
</node> </node>
''' '''
@ -182,6 +186,7 @@ class TuhiDBusDevice(_TuhiDBus):
device.connect('notify::battery-percent', self._on_battery_percent) device.connect('notify::battery-percent', self._on_battery_percent)
device.connect('notify::battery-state', self._on_battery_state) device.connect('notify::battery-state', self._on_battery_state)
device.connect('device-error', self._on_device_error) device.connect('device-error', self._on_device_error)
device.connect('notify::sync-state', self._on_sync_state)
@GObject.Property @GObject.Property
def listening(self): def listening(self):
@ -330,6 +335,14 @@ class TuhiDBusDevice(_TuhiDBus):
self._stop_listening(self.connection, self._listening_client[0], self._stop_listening(self.connection, self._listening_client[0],
-exception.errno) -exception.errno)
def _on_sync_state(self, device, pspec):
if self._listening_client is None:
return
dest = self._listening_client[0]
status = GLib.Variant.new_int32(device.sync_state)
self.signal('SyncState', status, dest=dest)
def _start_listening(self, connection, sender): def _start_listening(self, connection, sender):
if self.listening: if self.listening:
logger.debug(f'{self} - already listening') logger.debug(f'{self} - already listening')

View File

@ -1115,6 +1115,7 @@ class WacomDevice(GObject.Object):
self._is_running = False self._is_running = False
self._config = None self._config = None
self._wacom_protocol = None self._wacom_protocol = None
self._sync_state = 0
try: try:
self._config = config.devices[device.address] self._config = config.devices[device.address]
@ -1168,6 +1169,14 @@ class WacomDevice(GObject.Object):
assert self._wacom_protocol is not None assert self._wacom_protocol is not None
return self._wacom_protocol.protocol return self._wacom_protocol.protocol
@GObject.Property
def sync_state(self):
return self._sync_state
@sync_state.setter
def sync_state(self, state):
self._sync_state = state
def register_device(self): def register_device(self):
self._uuid = uuid.uuid4().hex[:12] self._uuid = uuid.uuid4().hex[:12]
logger.debug(f'{self._device.address}: registering device, assigned {self.uuid}') logger.debug(f'{self._device.address}: registering device, assigned {self.uuid}')
@ -1204,10 +1213,13 @@ class WacomDevice(GObject.Object):
self.register_device() self.register_device()
else: else:
assert self._wacom_protocol is not None assert self._wacom_protocol is not None
self.sync_state = 1
self._wacom_protocol.retrieve_data() self._wacom_protocol.retrieve_data()
self.sync_state = 0
except WacomException as e: except WacomException as e:
logger.error(f'**** Exception: {e} ****') logger.error(f'**** Exception: {e} ****')
exception = e exception = e
self.sync_state = 0
finally: finally:
self._is_running = False self._is_running = False
self.emit('done', exception) self.emit('done', exception)