pa_assert(local);
while ((d = pa_hashmap_iterate(y->devices, &state, NULL)))
- if (pa_streq(d->address, remote) && pa_streq(d->adapter->address, local))
- return d->device_info_valid == 1 ? d : NULL;
+ if (d->device_info_valid == 1 && pa_streq(d->address, remote) && pa_streq(d->adapter->address, local))
+ return d;
return NULL;
}
pa_xfree(d->path);
pa_xfree(d->alias);
pa_xfree(d->address);
+ pa_xfree(d->adapter_path);
pa_xfree(d);
}
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;
pa_assert(a->discovery);
PA_HASHMAP_FOREACH(d, a->discovery->devices, state)
- if (d->adapter == a)
+ if (d->adapter == a) {
+ set_device_info_valid(d, -1);
d->adapter = NULL;
+ }
pa_xfree(a->path);
pa_xfree(a->address);
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);
+ if (!d->adapter || !d->adapter->address) {
+ pa_log_error("Device %s is child of nonexistent or corrupted adapter %s", d->path, d->adapter_path);
set_device_info_valid(d, -1);
} else
set_device_info_valid(d, 1);
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;
}
goto fail2;
}
} else {
- /* InterfacesAdded signal is probably on it's way, device_info_valid is kept as 0. */
+ /* InterfacesAdded signal is probably on its way, device_info_valid is kept as 0. */
pa_log_warn("SetConfiguration() received for unknown device %s", dev_path);
d = device_create(y, dev_path);
}
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);
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);