From b16a16abde7bf21a7f2184651c8531d8484c49c9 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Sun, 14 Jul 2019 18:32:34 +1000 Subject: [PATCH] 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 --- README.md | 9 +++++++++ tools/kete.py | 7 +++++++ tuhi/base.py | 9 +++++++++ tuhi/dbusserver.py | 13 +++++++++++++ tuhi/wacom.py | 12 ++++++++++++ 5 files changed, 50 insertions(+) diff --git a/README.md b/README.md index 7b77815..fe71e5b 100644 --- a/README.md +++ b/README.md @@ -378,6 +378,15 @@ org.freedesktop.tuhi1.Device These errnos indicate a bug in the daemon, and the client should 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 diff --git a/tools/kete.py b/tools/kete.py index c120aaa..9810c7d 100755 --- a/tools/kete.py +++ b/tools/kete.py @@ -285,6 +285,13 @@ class TuhiKeteDevice(_DBusObject): elif err < 0: logger.error(f'{self}: an error occured: {os.strerror(-err)}') 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): if changed_props is None: diff --git a/tuhi/base.py b/tuhi/base.py index ee16e2f..488d63f 100644 --- a/tuhi/base.py +++ b/tuhi/base.py @@ -146,6 +146,10 @@ class TuhiDevice(GObject.Object): def battery_state(self, value): self._battery_state = value + @GObject.Property + def sync_state(self): + return self._sync_state + def _connect_device(self, 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) @@ -166,6 +170,7 @@ class TuhiDevice(GObject.Object): 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('battery-status', self._on_battery_status, bluez_device) + self._wacom_device.connect('notify::sync-state', self._on_sync_state) if mode == DeviceMode.REGISTER: self._wacom_device.start_register() @@ -180,6 +185,10 @@ class TuhiDevice(GObject.Object): except KeyError: 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): logger.debug(f'{bluez_device.address}: disconnected') try: diff --git a/tuhi/dbusserver.py b/tuhi/dbusserver.py index 820868b..ccc399c 100755 --- a/tuhi/dbusserver.py +++ b/tuhi/dbusserver.py @@ -106,6 +106,10 @@ INTROSPECTION_XML = ''' + + + + ''' @@ -182,6 +186,7 @@ class TuhiDBusDevice(_TuhiDBus): device.connect('notify::battery-percent', self._on_battery_percent) device.connect('notify::battery-state', self._on_battery_state) device.connect('device-error', self._on_device_error) + device.connect('notify::sync-state', self._on_sync_state) @GObject.Property def listening(self): @@ -330,6 +335,14 @@ class TuhiDBusDevice(_TuhiDBus): self._stop_listening(self.connection, self._listening_client[0], -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): if self.listening: logger.debug(f'{self} - already listening') diff --git a/tuhi/wacom.py b/tuhi/wacom.py index e016872..0563bd2 100644 --- a/tuhi/wacom.py +++ b/tuhi/wacom.py @@ -1115,6 +1115,7 @@ class WacomDevice(GObject.Object): self._is_running = False self._config = None self._wacom_protocol = None + self._sync_state = 0 try: self._config = config.devices[device.address] @@ -1168,6 +1169,14 @@ class WacomDevice(GObject.Object): assert self._wacom_protocol is not None 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): self._uuid = uuid.uuid4().hex[:12] logger.debug(f'{self._device.address}: registering device, assigned {self.uuid}') @@ -1204,10 +1213,13 @@ class WacomDevice(GObject.Object): self.register_device() else: assert self._wacom_protocol is not None + self.sync_state = 1 self._wacom_protocol.retrieve_data() + self.sync_state = 0 except WacomException as e: logger.error(f'**** Exception: {e} ****') exception = e + self.sync_state = 0 finally: self._is_running = False self.emit('done', exception)