From d4dd672b2f13545e230c1d9bc80f79c287bf7908 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Tue, 13 Feb 2018 20:01:56 +0100 Subject: [PATCH] live-mode: properly pack the fds over DBus Keeping this one as a separate commit, so we can use it as a future reference. --- tools/kete.py | 15 ++++++++++++--- tuhi/dbusserver.py | 26 ++++++++++++++++++++------ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/tools/kete.py b/tools/kete.py index 2ba0011..ae4d31c 100755 --- a/tools/kete.py +++ b/tools/kete.py @@ -246,8 +246,17 @@ class TuhiKeteDevice(_DBusObject): raise e def start_live(self, fd): - self.proxy.StartLive('(h)', fd) - self.live = True + fd_list = Gio.UnixFDList.new() + fd_list.append(fd) + + res, fds = self.proxy.call_with_unix_fd_list_sync('org.freedesktop.tuhi1.Device.StartLive', + GLib.Variant('(h)', (fd,)), + Gio.DBusCallFlags.NO_AUTO_START, + -1, + fd_list, + None) + if res[0] == 0: + self.live = True def stop_live(self): self.proxy.StopLive() @@ -605,7 +614,7 @@ class LiveChanger(Worker): return logger.debug(f'{self.device}: starting live mode') - self.device.start_live(0) + self.device.start_live(-1) def stop(self): logger.debug(f'{self.device}: stopping live mode') diff --git a/tuhi/dbusserver.py b/tuhi/dbusserver.py index 38a5273..4582dec 100755 --- a/tuhi/dbusserver.py +++ b/tuhi/dbusserver.py @@ -78,8 +78,8 @@ INTROSPECTION_XML = ''' - - + + @@ -267,8 +267,7 @@ class TuhiDBusDevice(_TuhiDBus): self._stop_listening(connection, sender) invocation.return_value() elif methodname == 'StartLive': - self._start_live(connection, sender, args) - invocation.return_value() + self._start_live(connection, sender, args, invocation) elif methodname == 'StopLive': self._stop_live(connection, sender) invocation.return_value() @@ -375,7 +374,7 @@ class TuhiDBusDevice(_TuhiDBus): self.listening = False self.notify('listening') - def _start_live(self, connection, sender, args): + def _start_live(self, connection, sender, args, invocation): if self.live: logger.debug(f'{self} - already in live mode') @@ -397,8 +396,23 @@ class TuhiDBusDevice(_TuhiDBus): self._live_client = (sender, s) logger.debug(f'Live mode started on {self.name} for {sender}') + message = invocation.get_message() + fds_list = message.get_unix_fd_list() + + if fds_list is None or fds_list.get_length() != 1: + logger.error(f'uhid fds not provided') + result = GLib.Variant.new_int32(-errno.EINVAL) + invocation.return_value(GLib.Variant.new_tuple(result)) + return + + fds_list = fds_list.steal_fds() + + self._uhid_fd = fds_list[0] + self.live = True - self._uhid_fd = args[0] + + result = GLib.Variant.new_int32(0) + invocation.return_value(GLib.Variant.new_tuple(result)) def _stop_live(self, connection, sender, errno=0): if not self.live or sender != self._live_client[0]: