Merge lp:~charlesk/indicator-bluetooth/lp-1530807-watch-bluez-owner-on-bus into lp:indicator-bluetooth/15.10

Proposed by Charles Kerr
Status: Merged
Approved by: Charles Kerr
Approved revision: 98
Merged at revision: 94
Proposed branch: lp:~charlesk/indicator-bluetooth/lp-1530807-watch-bluez-owner-on-bus
Merge into: lp:indicator-bluetooth/15.10
Diff against target: 142 lines (+56/-18)
1 file modified
src/bluez.vala (+56/-18)
To merge this branch: bzr merge lp:~charlesk/indicator-bluetooth/lp-1530807-watch-bluez-owner-on-bus
Reviewer Review Type Date Requested Status
Xavi Garcia Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+286003@code.launchpad.net

Commit message

Change the indicator's Bluez class to watch for 'org.bluez' to appear/vanish on the system bus.

Description of the change

Several people experiencing bug #1530807 have stated that restarting indicator-bluetooth solves the issue, so the bug appears to be a timing issue with the indicator's startup.

Change the indicator's Bluez class to watch for 'org.bluez' to appear/vanish on the system bus and update accordingly. The class was previously brittle in that it assumed org.bluez would be up and running before the indicator started.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Xavi Garcia (xavi-garcia-mena) wrote :

just one question:
Why does it call init_bluez_state_vars () from the constructor and also from on_bluez_appeared?

do we need the call from on_bluez_appeared?

review: Needs Information
Revision history for this message
Xavi Garcia (xavi-garcia-mena) wrote :

Approving after discussion with alecu.
If we are not restarting the indicator it makes sense to re-initialize everything

review: Approve
Revision history for this message
Charles Kerr (charlesk) wrote :

Xavi, the idea was to have the indicator reset its state whenever org.bluez appeared on the bus, not just for the bootstrap case but also to handle bluez being stopped and restarted.

I agree that reinit'ing is probably not necessary in on_bluez_appeared() because the bootstrap case is handled in the ctor and the restart case is handled in on_bluez_vanished().

Since this MP's siloed and tested, though, let's leave this wart in for now and I'll make sure to clean it up when I come back and add bluez5 mock tests after the emergency landing.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/bluez.vala'
--- src/bluez.vala 2015-09-28 04:06:29 +0000
+++ src/bluez.vala 2016-02-14 21:10:44 +0000
@@ -20,12 +20,14 @@
2020
2121
22/**22/**
23 * Bluetooth implementaion which uses org.bluez on DBus 23 * Bluetooth implementaion which uses org.bluez on DBus
24 */24 */
25public class Bluez: Bluetooth, Object25public class Bluez: Bluetooth, Object
26{26{
27 uint name_watch_id = 0;
27 uint next_device_id = 1;28 uint next_device_id = 1;
28 ObjectManager manager;29 ObjectManager manager;
30 static const string BLUEZ_BUSNAME = "org.bluez";
2931
30 private bool _powered = false;32 private bool _powered = false;
3133
@@ -55,14 +57,7 @@
5557
56 public Bluez (KillSwitch? killswitch)58 public Bluez (KillSwitch? killswitch)
57 {59 {
58 try60 init_bluez_state_vars ();
59 {
60 bus = Bus.get_sync (BusType.SYSTEM);
61 }
62 catch (Error e)
63 {
64 critical (@"$(e.message)");
65 }
6661
67 if ((killswitch != null) && (killswitch.is_valid()))62 if ((killswitch != null) && (killswitch.is_valid()))
68 {63 {
@@ -71,20 +66,59 @@
71 update_enabled ();66 update_enabled ();
72 }67 }
7368
74 reset_manager ();69 name_watch_id = Bus.watch_name(BusType.SYSTEM,
75 }70 BLUEZ_BUSNAME,
7671 BusNameWatcherFlags.AUTO_START,
77 private void reset_manager ()72 on_bluez_appeared,
73 on_bluez_vanished);
74 }
75
76 ~Bluez()
77 {
78 Bus.unwatch_name(name_watch_id);
79 }
80
81 private void on_bluez_appeared (DBusConnection connection, string name, string name_owner)
82 {
83 debug(@"$name owned by $name_owner, setting up bluez proxies");
84
85 bus = connection;
86
87 init_bluez_state_vars();
88 reset_manager();
89 }
90
91 private void on_bluez_vanished (DBusConnection connection, string name)
92 {
93 debug(@"$name vanished from the bus");
94
95 reset_bluez();
96 }
97
98 private void init_bluez_state_vars ()
78 {99 {
79 id_to_path = new HashTable<uint,ObjectPath> (direct_hash, direct_equal);100 id_to_path = new HashTable<uint,ObjectPath> (direct_hash, direct_equal);
80 id_to_device = new HashTable<uint,Device> (direct_hash, direct_equal);101 id_to_device = new HashTable<uint,Device> (direct_hash, direct_equal);
81 path_to_id = new HashTable<ObjectPath,uint> (str_hash, str_equal);102 path_to_id = new HashTable<ObjectPath,uint> (str_hash, str_equal);
82 path_to_adapter_proxy = new HashTable<ObjectPath,BluezAdapter> (str_hash, str_equal);103 path_to_adapter_proxy = new HashTable<ObjectPath,BluezAdapter> (str_hash, str_equal);
83 path_to_device_proxy = new HashTable<ObjectPath,BluezDevice> (str_hash, str_equal);104 path_to_device_proxy = new HashTable<ObjectPath,BluezDevice> (str_hash, str_equal);
84105 }
106
107 private void reset_bluez ()
108 {
109 init_bluez_state_vars ();
110
111 devices_changed ();
112 update_combined_adapter_state ();
113 update_connected ();
114 update_enabled ();
115 }
116
117 private void reset_manager()
118 {
85 try119 try
86 {120 {
87 manager = bus.get_proxy_sync ("org.bluez", "/");121 manager = bus.get_proxy_sync (BLUEZ_BUSNAME, "/");
88122
89 // Find the adapters and watch for changes123 // Find the adapters and watch for changes
90 manager.interfaces_added.connect ((object_path, interfaces_and_properties) => {124 manager.interfaces_added.connect ((object_path, interfaces_and_properties) => {
@@ -134,12 +168,14 @@
134168
135 private void update_adapter (ObjectPath object_path)169 private void update_adapter (ObjectPath object_path)
136 {170 {
171 debug(@"bluez5 calling update_adapter for $object_path");
172
137 // Create a proxy if we don't have one173 // Create a proxy if we don't have one
138 var adapter_proxy = path_to_adapter_proxy.lookup (object_path);174 var adapter_proxy = path_to_adapter_proxy.lookup (object_path);
139 if (adapter_proxy == null)175 if (adapter_proxy == null)
140 {176 {
141 try {177 try {
142 adapter_proxy = bus.get_proxy_sync ("org.bluez", object_path);178 adapter_proxy = bus.get_proxy_sync (BLUEZ_BUSNAME, object_path);
143 } catch (Error e) {179 } catch (Error e) {
144 critical (@"$(e.message)");180 critical (@"$(e.message)");
145 return;181 return;
@@ -232,12 +268,14 @@
232 */268 */
233 private void update_device (ObjectPath object_path)269 private void update_device (ObjectPath object_path)
234 {270 {
271 debug(@"bluez5 calling update_device for $object_path");
272
235 // Create a proxy if we don't have one273 // Create a proxy if we don't have one
236 var device_proxy = path_to_device_proxy.lookup (object_path);274 var device_proxy = path_to_device_proxy.lookup (object_path);
237 if (device_proxy == null)275 if (device_proxy == null)
238 {276 {
239 try {277 try {
240 device_proxy = bus.get_proxy_sync ("org.bluez", object_path);278 device_proxy = bus.get_proxy_sync (BLUEZ_BUSNAME, object_path);
241 } catch (Error e) {279 } catch (Error e) {
242 critical (@"$(e.message)");280 critical (@"$(e.message)");
243 return;281 return;
@@ -262,7 +300,7 @@
262 var v = device_proxy.get_cached_property ("Class");300 var v = device_proxy.get_cached_property ("Class");
263 if (v == null)301 if (v == null)
264 type = Device.Type.OTHER;302 type = Device.Type.OTHER;
265 else 303 else
266 type = Device.class_to_device_type (v.get_uint32());304 type = Device.class_to_device_type (v.get_uint32());
267305
268 // look up the device's human-readable name306 // look up the device's human-readable name

Subscribers

People subscribed via source and target branches