]> code.delx.au - pulseaudio/commitdiff
bluetooth: Remove device_remove_all()
authorTanu Kaskinen <tanu.kaskinen@linux.intel.com>
Fri, 15 Nov 2013 14:29:40 +0000 (16:29 +0200)
committerTanu Kaskinen <tanu.kaskinen@linux.intel.com>
Wed, 20 Nov 2013 13:49:06 +0000 (15:49 +0200)
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

index b9a61b405927c3cb8a4720c874bec1152a59ed21..73e65d1f369fe98844689f377b64e9c269dd8c92 100644 (file)
@@ -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);