[pulseaudio-discuss] [PATCH 4/5] bluetooth: Remove device_remove_all()

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


The function did two things: set device_info_valid to -1 and called
device_free() for each device in the hashmap. Setting
device_info_valid to -1 was unnecessary. The main purpose of that was
to fire DEVICE_CONNECTION_CHANGED as a side effect, but that hook is
fired anyway in device_free(), as a side effect of removing all
transports. Calling device_free() can be delegated to pa_hashmap, when
freeing or emptying it.
---
 src/modules/bluetooth/bluez5-util.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c
index b9a61b4..73e65d1 100644
--- a/src/modules/bluetooth/bluez5-util.c
+++ b/src/modules/bluetooth/bluez5-util.c
@@ -454,17 +454,6 @@ static void set_device_info_valid(pa_bluetooth_device *device, int valid) {
         pa_hook_fire(&device->discovery->hooks[PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED], device);
 }
 
-static void device_remove_all(pa_bluetooth_discovery *y) {
-    pa_bluetooth_device *d;
-
-    pa_assert(y);
-
-    while ((d = pa_hashmap_steal_first(y->devices))) {
-        set_device_info_valid(d, -1);
-        device_free(d);
-   }
-}
-
 static pa_bluetooth_adapter* adapter_create(pa_bluetooth_discovery *y, const char *path) {
     pa_bluetooth_adapter *a;
 
@@ -927,7 +916,7 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us
         if (pa_streq(name, BLUEZ_SERVICE)) {
             if (old_owner && *old_owner) {
                 pa_log_debug("Bluetooth daemon disappeared");
-                device_remove_all(y);
+                pa_hashmap_remove_all(y->devices);
                 pa_hashmap_remove_all(y->adapters);
                 y->objects_listed = false;
             }
@@ -1532,7 +1521,8 @@ pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *c) {
     y->core = c;
     y->adapters = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL,
                                       (pa_free_cb_t) adapter_free);
-    y->devices = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    y->devices = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL,
+                                     (pa_free_cb_t) device_free);
     y->transports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
     PA_LLIST_HEAD_INIT(pa_dbus_pending, y->pending);
 
@@ -1607,10 +1597,8 @@ void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y) {
 
     pa_dbus_free_pending_list(&y->pending);
 
-    if (y->devices) {
-        device_remove_all(y);
+    if (y->devices)
         pa_hashmap_free(y->devices);
-    }
 
     if (y->adapters)
         pa_hashmap_free(y->adapters);
-- 
1.8.3.1



More information about the pulseaudio-discuss mailing list