From d4368aa608b79f58a279018eb74abd5a6bff30ac Mon Sep 17 00:00:00 2001 From: Mikel Astiz Date: Fri, 26 Oct 2012 08:23:51 +0200 Subject: [PATCH] bluetooth: Handle UUIDs announced later 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. --- .../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 6c0c74627..1236cb584 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 *uuid_added_slot; char *address; char *path; pa_bluetooth_transport *transport; @@ -2535,6 +2536,38 @@ static pa_bluetooth_device* find_device(struct userdata *u, const char *address, return d; } +/* Run from main thread */ +static pa_hook_result_t uuid_added_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); + + pa_card_add_ports(u->card, new_ports); + + pa_device_port_hashmap_free(new_ports); + + return PA_HOOK_OK; +} + /* Run from main thread */ static int setup_dbus(struct userdata *u) { DBusError err; @@ -2658,6 +2691,9 @@ int pa__init(pa_module* m) { u->device = device; + u->uuid_added_slot = pa_hook_connect(&device->hooks[PA_BLUETOOTH_DEVICE_HOOK_UUID_ADDED], PA_HOOK_NORMAL, + (pa_hook_cb_t) uuid_added_cb, u); + /* Add the card structure. This will also initialize the default profile */ if (add_card(u) < 0) goto fail; @@ -2776,6 +2812,9 @@ void pa__done(pa_module *m) { pa_dbus_connection_unref(u->connection); } + if (u->uuid_added_slot) + pa_hook_slot_free(u->uuid_added_slot); + if (u->msg) pa_xfree(u->msg);