[pulseaudio-discuss] [PATCH 2/5] bluetooth: Don't mark device valid before it has an adapter

Tanu Kaskinen tanu.kaskinen at linux.intel.com
Fri Nov 15 06:29:38 PST 2013


At this point this doesn't make any other practical difference than
making the code more logical, but in the next patch I'll fire the
DEVICE_CONNECTION_CHANGED hook in set_device_info_valid(), and at that
point it's important that the device isn't marked valid too early,
because otherwise external code would see "valid" devices that however
don't have the adapter set.
---
 src/modules/bluetooth/bluez5-util.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c
index 23a53f1..e326695 100644
--- a/src/modules/bluetooth/bluez5-util.c
+++ b/src/modules/bluetooth/bluez5-util.c
@@ -634,7 +634,12 @@ static int parse_device_properties(pa_bluetooth_device *d, DBusMessageIter *i, b
         return -1;
     }
 
-    set_device_info_valid(d, 1);
+    if (!is_property_change && d->adapter)
+        set_device_info_valid(d, 1);
+
+    /* If d->adapter is NULL, device_info_valid will be left as 0, and updated
+     * after all interfaces have been parsed. */
+
     return 0;
 }
 
@@ -813,14 +818,19 @@ static void parse_interfaces_and_properties(pa_bluetooth_discovery *y, DBusMessa
         dbus_message_iter_next(&element_i);
     }
 
-    PA_HASHMAP_FOREACH(d, y->devices, state)
+    PA_HASHMAP_FOREACH(d, y->devices, state) {
+        if (d->device_info_valid != 0)
+            continue;
+
         if (!d->adapter && d->adapter_path) {
             d->adapter = pa_hashmap_get(d->discovery->adapters, d->adapter_path);
             if (!d->adapter) {
                 pa_log_error("Device %s is child of nonexistent adapter %s", d->path, d->adapter_path);
                 set_device_info_valid(d, -1);
-            }
+            } else
+                set_device_info_valid(d, 1);
         }
+    }
 
     return;
 }
-- 
1.8.3.1



More information about the pulseaudio-discuss mailing list