]> code.delx.au - pulseaudio/commitdiff
bluetooth: Create a function to remove only one adapter object
authorJoão Paulo Rechi Vita <jprvita@gmail.com>
Tue, 24 Sep 2013 22:45:29 +0000 (19:45 -0300)
committerTanu Kaskinen <tanu.kaskinen@linux.intel.com>
Sun, 29 Sep 2013 13:54:37 +0000 (16:54 +0300)
src/modules/bluetooth/bluez5-util.c

index 2a5b1ab4c7bf546f6b904cad9d9a4c9885be9f02..9e14951319d55f3ee1fc29ae6dd9dbf08ddb3db7 100644 (file)
@@ -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) {