[pulseaudio-commits] 5 commits - src/modules
Tanu Kaskinen
tanuk at kemper.freedesktop.org
Wed Nov 20 05:52:37 PST 2013
src/modules/bluetooth/bluez5-util.c | 53 +++++++++++++++++++++++-------------
1 file changed, 34 insertions(+), 19 deletions(-)
New commits:
commit e9d760b55562b12c8df6070cf4c7e1b839ef197b
Author: Tanu Kaskinen <tanu.kaskinen at linux.intel.com>
Date: Fri Nov 15 16:29:41 2013 +0200
bluetooth: Set device_info_valid to -1 when the device's adapter disappears
When parsing device properties, missing adapter will result in
device_info_valid being set to -1. It is then logical that if the
adapter goes missing at a later point, device_info_valid gets set to
-1 also in that situation.
diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c
index 73e65d1..c8ff219 100644
--- a/src/modules/bluetooth/bluez5-util.c
+++ b/src/modules/bluetooth/bluez5-util.c
@@ -477,8 +477,10 @@ static void adapter_free(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);
commit e2dea40f4af744b97b80c49679fadc7f9acd3f7c
Author: Tanu Kaskinen <tanu.kaskinen at linux.intel.com>
Date: Fri Nov 15 16:29:40 2013 +0200
bluetooth: Remove device_remove_all()
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.
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);
commit 454ca62b235a2f9089e3780b14ae01397515081e
Author: Tanu Kaskinen <tanu.kaskinen at linux.intel.com>
Date: Fri Nov 15 16:29:39 2013 +0200
bluetooth: Fire DEVICE_CONNECTION_CHANGED in set_device_info_valid()
Normally DEVICE_CONNECTION_CHANGED is fired when the first transport
becomes connected, but it may happen that the first transport becomes
connected already before the device properties have been received. In
that case the hook should be fired at the time the device properties
are received. This patch makes the hook to be fired at the right time.
diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c
index e326695..b9a61b4 100644
--- a/src/modules/bluetooth/bluez5-util.c
+++ b/src/modules/bluetooth/bluez5-util.c
@@ -439,13 +439,19 @@ static void device_remove(pa_bluetooth_discovery *y, const char *path) {
}
static void set_device_info_valid(pa_bluetooth_device *device, int valid) {
+ bool old_any_connected;
+
pa_assert(device);
pa_assert(valid == -1 || valid == 0 || valid == 1);
if (valid == device->device_info_valid)
return;
+ old_any_connected = pa_bluetooth_device_any_transport_connected(device);
device->device_info_valid = valid;
+
+ if (pa_bluetooth_device_any_transport_connected(device) != old_any_connected)
+ pa_hook_fire(&device->discovery->hooks[PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED], device);
}
static void device_remove_all(pa_bluetooth_discovery *y) {
@@ -455,7 +461,6 @@ static void device_remove_all(pa_bluetooth_discovery *y) {
while ((d = pa_hashmap_steal_first(y->devices))) {
set_device_info_valid(d, -1);
- pa_hook_fire(&y->hooks[PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED], d);
device_free(d);
}
}
commit 6633c1f9ff3b9a1fc8431c50baad2337ccdc8a36
Author: Tanu Kaskinen <tanu.kaskinen at linux.intel.com>
Date: Fri Nov 15 16:29:38 2013 +0200
bluetooth: Don't mark device valid before it has an adapter
At this point this doesn't make any other practical difference than
making the code more logical, but in the next patch I'll fire the
DEVICE_CONNECTION_CHANGED hook in set_device_info_valid(), and at that
point it's important that the device isn't marked valid too early,
because otherwise external code would see "valid" devices that however
don't have the adapter set.
diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c
index 23a53f1..e326695 100644
--- a/src/modules/bluetooth/bluez5-util.c
+++ b/src/modules/bluetooth/bluez5-util.c
@@ -634,7 +634,12 @@ static int parse_device_properties(pa_bluetooth_device *d, DBusMessageIter *i, b
return -1;
}
- set_device_info_valid(d, 1);
+ if (!is_property_change && d->adapter)
+ set_device_info_valid(d, 1);
+
+ /* If d->adapter is NULL, device_info_valid will be left as 0, and updated
+ * after all interfaces have been parsed. */
+
return 0;
}
@@ -813,14 +818,19 @@ static void parse_interfaces_and_properties(pa_bluetooth_discovery *y, DBusMessa
dbus_message_iter_next(&element_i);
}
- PA_HASHMAP_FOREACH(d, y->devices, state)
+ PA_HASHMAP_FOREACH(d, y->devices, state) {
+ if (d->device_info_valid != 0)
+ continue;
+
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);
set_device_info_valid(d, -1);
- }
+ } else
+ set_device_info_valid(d, 1);
}
+ }
return;
}
commit f4f4c42fc611b0bca2293e9b517a88a525f2c1fb
Author: Tanu Kaskinen <tanu.kaskinen at linux.intel.com>
Date: Fri Nov 15 16:29:37 2013 +0200
bluetooth: Use a helper function for setting device_info_valid
The helper function doesn't yet bring much benefits in this form, but
I'll add more functionality later.
diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c
index 4d3fbbc..23a53f1 100644
--- a/src/modules/bluetooth/bluez5-util.c
+++ b/src/modules/bluetooth/bluez5-util.c
@@ -438,13 +438,23 @@ static void device_remove(pa_bluetooth_discovery *y, const char *path) {
}
}
+static void set_device_info_valid(pa_bluetooth_device *device, int valid) {
+ pa_assert(device);
+ pa_assert(valid == -1 || valid == 0 || valid == 1);
+
+ if (valid == device->device_info_valid)
+ return;
+
+ device->device_info_valid = valid;
+}
+
static void device_remove_all(pa_bluetooth_discovery *y) {
pa_bluetooth_device *d;
pa_assert(y);
while ((d = pa_hashmap_steal_first(y->devices))) {
- d->device_info_valid = -1;
+ set_device_info_valid(d, -1);
pa_hook_fire(&y->hooks[PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED], d);
device_free(d);
}
@@ -620,11 +630,11 @@ static int parse_device_properties(pa_bluetooth_device *d, DBusMessageIter *i, b
if (!d->address || !d->adapter_path || !d->alias) {
pa_log_error("Non-optional information missing for device %s", d->path);
- d->device_info_valid = -1;
+ set_device_info_valid(d, -1);
return -1;
}
- d->device_info_valid = 1;
+ set_device_info_valid(d, 1);
return 0;
}
@@ -808,7 +818,7 @@ static void parse_interfaces_and_properties(pa_bluetooth_discovery *y, DBusMessa
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);
- d->device_info_valid = -1;
+ set_device_info_valid(d, -1);
}
}
More information about the pulseaudio-commits
mailing list