From fb4b7e7a0bb9a09f97d226b50479fe496baf70f1 Mon Sep 17 00:00:00 2001 From: Andrew Zaborowski Date: Tue, 4 Aug 2020 16:52:58 +0200 Subject: [PATCH] wfd-source: Fix some races on iwd name owner change Subscribe to InterfacesAdded/Removed/PropertiesChanged signals before using GetManagedObjects. For some reason when iwd starts after the client, we consistently get the managed objects list from before Adapter interfaces are added but we miss the subsequent InterfacesAdded signals, probably has to do with the GetManagedObjects and the AddMatch calls all being synchronous. Secondly call self.populate_devices() on init as it won't be called if IWD is not on the bus. --- test/wfd-source | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/test/wfd-source b/test/wfd-source index e74d0adf..a83cd0cb 100755 --- a/test/wfd-source +++ b/test/wfd-source @@ -826,6 +826,7 @@ class WFDSource(Gtk.Window): self.rtsp_port = 7236 self.devices = None self.objects = {} + self.populate_devices() self.dbus = dbus.SystemBus() self.dbus.watch_name_owner('net.connman.iwd', self.on_name_owner_change) self.on_name_owner_change('dummy' if self.dbus.name_has_owner('net.connman.iwd') else '') @@ -857,17 +858,6 @@ class WFDSource(Gtk.Window): return True manager = dbus.Interface(self.dbus.get_object('net.connman.iwd', '/'), 'org.freedesktop.DBus.ObjectManager') - self.devices = {} - self.objects = manager.GetManagedObjects() - - for path in self.objects: - if DEVICE_IF in self.objects[path]: - self.add_dev(path) - for path in self.objects: - if PEER_IF in self.objects[path]: - self.add_peer(path) - - self.populate_devices() self.dbus.add_signal_receiver(self.on_properties_changed, bus_name="net.connman.iwd", @@ -883,6 +873,18 @@ class WFDSource(Gtk.Window): dbus_interface="org.freedesktop.DBus.ObjectManager", signal_name="InterfacesRemoved") + self.objects = manager.GetManagedObjects() + self.devices = {} + + for path in self.objects: + if DEVICE_IF in self.objects[path]: + self.add_dev(path) + for path in self.objects: + if PEER_IF in self.objects[path]: + self.add_peer(path) + + self.populate_devices() + svc_mgr = dbus.Interface(self.dbus.get_object('net.connman.iwd', '/net/connman/iwd'), SVC_MGR_IF) svc_mgr.RegisterDisplayService({ 'Source': True,