[pulseaudio-discuss] [PATCH v5 09/39] bluetooth: Create a function to remove only one adapter object

jprvita at gmail.com jprvita at gmail.com
Tue Sep 24 15:45:29 PDT 2013


From: João Paulo Rechi Vita <jprvita at gmail.com>

---
 src/modules/bluetooth/bluez5-util.c | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c
index 2a5b1ab..9e14951 100644
--- a/src/modules/bluetooth/bluez5-util.c
+++ b/src/modules/bluetooth/bluez5-util.c
@@ -364,6 +364,33 @@ static pa_bluetooth_adapter* adapter_create(pa_bluetooth_discovery *y, const cha
     return a;
 }
 
+static void adapter_free(pa_bluetooth_adapter *a) {
+    pa_bluetooth_device *d;
+    void *state;
+
+    pa_assert(a);
+    pa_assert(a->discovery);
+
+    PA_HASHMAP_FOREACH(d, a->discovery->devices, state)
+        if (d->adapter == a)
+            d->adapter = NULL;
+
+    pa_xfree(a->path);
+    pa_xfree(a->address);
+    pa_xfree(a);
+}
+
+static void adapter_remove(pa_bluetooth_discovery *y, const char *path) {
+    pa_bluetooth_adapter *a;
+
+    if (!(a = pa_hashmap_remove(y->adapters, path)))
+        pa_log_warn("Unknown adapter removed %s", path);
+    else {
+        pa_log_debug("Adapter %s removed", path);
+        adapter_free(a);
+    }
+}
+
 static void adapter_remove_all(pa_bluetooth_discovery *y) {
     pa_bluetooth_adapter *a;
 
@@ -371,11 +398,8 @@ static void adapter_remove_all(pa_bluetooth_discovery *y) {
 
     /* When this function is called all devices have already been freed */
 
-    while ((a = pa_hashmap_steal_first(y->adapters))) {
-        pa_xfree(a->path);
-        pa_xfree(a->address);
-        pa_xfree(a);
-    }
+    while ((a = pa_hashmap_steal_first(y->adapters)))
+        adapter_free(a);
 }
 
 static void get_managed_objects_reply(DBusPendingCall *pending, void *userdata) {
-- 
1.8.3.1



More information about the pulseaudio-discuss mailing list