[pulseaudio-discuss] [PATCH v0 11/11] bluetooth: Handle UUIDs announced later
Mikel Astiz
mikel.astiz.oss at gmail.com
Mon Oct 22 01:46:43 PDT 2012
From: Mikel Astiz <mikel.astiz at bmw-carit.de>
In some cases (typically during pairing) UUIDs might be reported by
BlueZ incrementally, that is, as soon as they have been discovered. At
this point module-bluetooth-device might already be loaded, so the late
UUID announcements need to be handled and additional card profiles
might need to be created accordingly.
---
src/modules/bluetooth/module-bluetooth-device.c | 39 +++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index 8c2efa4..0187c83 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -140,6 +140,7 @@ struct userdata {
pa_module *module;
pa_bluetooth_device *device;
+ pa_hook_slot *new_uuid_slot;
char *address;
char *path;
pa_bluetooth_transport *transport;
@@ -2495,6 +2496,39 @@ static pa_bluetooth_device* find_device(struct userdata *u, const char *address,
}
/* Run from main thread */
+static pa_hook_result_t new_uuid_cb(pa_bluetooth_device *d, const char *uuid, struct userdata *u) {
+ pa_card_profile *p;
+ pa_hashmap *new_ports;
+
+ pa_assert(d);
+ pa_assert(uuid);
+ pa_assert(u);
+
+ p = create_card_profile(u, uuid);
+
+ if (!p)
+ return PA_HOOK_OK;
+
+ if (pa_hashmap_get(u->card->profiles, p->name)) {
+ pa_card_profile_free(p);
+ return PA_HOOK_OK;
+ }
+
+ pa_card_add_profile(u->card, p);
+
+ new_ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+
+ create_ports_for_profile(u, new_ports, p);
+
+ if (pa_card_add_ports(u->card, new_ports) < 0) {
+ pa_device_port_hashmap_free(new_ports);
+ return PA_HOOK_OK;
+ }
+
+ return PA_HOOK_OK;
+}
+
+/* Run from main thread */
static int setup_dbus(struct userdata *u) {
DBusError err;
@@ -2597,6 +2631,8 @@ int pa__init(pa_module* m) {
u->device = device;
+ u->new_uuid_slot = pa_hook_connect(&device->hooks[PA_BLUETOOTH_DEVICE_HOOK_UUID], PA_HOOK_NORMAL, (pa_hook_cb_t) new_uuid_cb, u);
+
/* Add the card structure. This will also initialize the default profile */
if (add_card(u) < 0)
goto fail;
@@ -2714,6 +2750,9 @@ void pa__done(pa_module *m) {
pa_dbus_connection_unref(u->connection);
}
+ if (u->new_uuid_slot)
+ pa_hook_slot_free(u->new_uuid_slot);
+
if (u->msg)
pa_xfree(u->msg);
--
1.7.11.7
More information about the pulseaudio-discuss
mailing list