]> code.delx.au - pulseaudio/commitdiff
bluetooth: Extend discovery to support multiple hooks
authorMikel Astiz <mikel.astiz@bmw-carit.de>
Thu, 6 Dec 2012 14:55:27 +0000 (15:55 +0100)
committerTanu Kaskinen <tanuk@iki.fi>
Wed, 19 Dec 2012 10:31:48 +0000 (12:31 +0200)
Add the infrastructure to support several hooks inside
pa_bluetooth_discovery, while using hook names that describe more
accurately their purpose.

src/modules/bluetooth/bluetooth-util.c
src/modules/bluetooth/bluetooth-util.h
src/modules/bluetooth/module-bluetooth-device.c
src/modules/bluetooth/module-bluetooth-discover.c

index 498f5bb4317a40bdfebb760371aa0d821b806381..5f1ff0141c26301405ef3c09db12e4e970984c47 100644 (file)
@@ -69,7 +69,7 @@ struct pa_bluetooth_discovery {
     PA_LLIST_HEAD(pa_dbus_pending, pending);
     pa_hashmap *devices;
     pa_hashmap *transports;
-    pa_hook hook;
+    pa_hook hooks[PA_BLUETOOTH_HOOK_MAX];
     pa_bool_t filter_added;
 };
 
@@ -475,7 +475,7 @@ static void run_callback(pa_bluetooth_device *d, pa_bool_t dead) {
         return;
 
     d->dead = dead;
-    pa_hook_fire(&d->discovery->hook, d);
+    pa_hook_fire(&d->discovery->hooks[PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED], d);
 }
 
 static void remove_all_devices(pa_bluetooth_discovery *y) {
@@ -947,7 +947,7 @@ pa_bluetooth_device* pa_bluetooth_discovery_get_by_address(pa_bluetooth_discover
     pa_assert(PA_REFCNT_VALUE(y) > 0);
     pa_assert(address);
 
-    if (!pa_hook_is_firing(&y->hook))
+    if (!pa_hook_is_firing(&y->hooks[PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED]))
         pa_bluetooth_discovery_sync(y);
 
     while ((d = pa_hashmap_iterate(y->devices, &state, NULL)))
@@ -964,7 +964,7 @@ pa_bluetooth_device* pa_bluetooth_discovery_get_by_path(pa_bluetooth_discovery *
     pa_assert(PA_REFCNT_VALUE(y) > 0);
     pa_assert(path);
 
-    if (!pa_hook_is_firing(&y->hook))
+    if (!pa_hook_is_firing(&y->hooks[PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED]))
         pa_bluetooth_discovery_sync(y);
 
     if ((d = pa_hashmap_get(y->devices, path)))
@@ -1453,6 +1453,7 @@ static DBusHandlerResult endpoint_handler(DBusConnection *c, DBusMessage *m, voi
 pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *c) {
     DBusError err;
     pa_bluetooth_discovery *y;
+    unsigned i;
     static const DBusObjectPathVTable vtable_endpoint = {
         .message_function = endpoint_handler,
     };
@@ -1470,7 +1471,10 @@ pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *c) {
     y->devices = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
     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_hook_init(&y->hook, y);
+
+    for (i = 0; i < PA_BLUETOOTH_HOOK_MAX; i++)
+        pa_hook_init(&y->hooks[i], y);
+
     pa_shared_set(c, "bluetooth-discovery", y);
 
     if (setup_dbus(y) < 0)
@@ -1530,6 +1534,8 @@ pa_bluetooth_discovery* pa_bluetooth_discovery_ref(pa_bluetooth_discovery *y) {
 }
 
 void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y) {
+    unsigned i;
+
     pa_assert(y);
     pa_assert(PA_REFCNT_VALUE(y) > 0);
 
@@ -1574,7 +1580,8 @@ void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y) {
         pa_dbus_connection_unref(y->connection);
     }
 
-    pa_hook_done(&y->hook);
+    for (i = 0; i < PA_BLUETOOTH_HOOK_MAX; i++)
+        pa_hook_done(&y->hooks[i]);
 
     if (y->core)
         pa_shared_remove(y->core, "bluetooth-discovery");
@@ -1589,11 +1596,11 @@ void pa_bluetooth_discovery_sync(pa_bluetooth_discovery *y) {
     pa_dbus_sync_pending_list(&y->pending);
 }
 
-pa_hook* pa_bluetooth_discovery_hook(pa_bluetooth_discovery *y) {
+pa_hook* pa_bluetooth_discovery_hook(pa_bluetooth_discovery *y, pa_bluetooth_hook_t hook) {
     pa_assert(y);
     pa_assert(PA_REFCNT_VALUE(y) > 0);
 
-    return &y->hook;
+    return &y->hooks[hook];
 }
 
 const char*pa_bluetooth_get_form_factor(uint32_t class) {
index 59d0d2e3a29db4f19fafdebaf99605b963903b18..63f07f346f3bdbab0d435d4da713c09a156f885f 100644 (file)
@@ -65,6 +65,12 @@ enum profile {
 
 #define PA_BLUETOOTH_PROFILE_COUNT PROFILE_OFF
 
+/* Hook data: pa_bluetooth_discovery pointer. */
+typedef enum pa_bluetooth_hook {
+    PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED, /* Call data: pa_bluetooth_device */
+    PA_BLUETOOTH_HOOK_MAX
+} pa_bluetooth_hook_t;
+
 /* Hook data: pa_bluetooth_transport pointer. */
 typedef enum pa_bluetooth_transport_hook {
     PA_BLUETOOTH_TRANSPORT_HOOK_NREC_CHANGED, /* Call data: NULL. */
@@ -150,7 +156,7 @@ bool pa_bluetooth_device_any_audio_connected(const pa_bluetooth_device *d);
 int pa_bluetooth_transport_acquire(pa_bluetooth_transport *t, const char *accesstype, size_t *imtu, size_t *omtu);
 void pa_bluetooth_transport_release(pa_bluetooth_transport *t, const char *accesstype);
 
-pa_hook* pa_bluetooth_discovery_hook(pa_bluetooth_discovery *d);
+pa_hook* pa_bluetooth_discovery_hook(pa_bluetooth_discovery *y, pa_bluetooth_hook_t hook);
 
 const char* pa_bluetooth_get_form_factor(uint32_t class);
 
index da1b61ff3fa86bf08488dba458c16179c41a3b9d..95a0db145e7431be512b1d2b06a541d0b409b4c8 100644 (file)
@@ -2660,11 +2660,12 @@ int pa__init(pa_module* m) {
     if (!(device = find_device(u, address, path)))
         goto fail;
 
-    u->discovery_slot = pa_hook_connect(pa_bluetooth_discovery_hook(u->discovery), PA_HOOK_NORMAL,
-                                        (pa_hook_cb_t) discovery_hook_cb, u);
-
     u->device = device;
 
+    u->discovery_slot =
+        pa_hook_connect(pa_bluetooth_discovery_hook(u->discovery, PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED),
+                        PA_HOOK_NORMAL, (pa_hook_cb_t) discovery_hook_cb, u);
+
     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);
 
index 48d0beecc9d83b7ffee690905a66df3136a7ab32..41981f6afd866f15fef25844e17794512588e89c 100644 (file)
@@ -152,7 +152,8 @@ int pa__init(pa_module* m) {
     if (!(u->discovery = pa_bluetooth_discovery_get(u->core)))
         goto fail;
 
-    u->slot = pa_hook_connect(pa_bluetooth_discovery_hook(u->discovery), PA_HOOK_NORMAL, (pa_hook_cb_t) load_module_for_device, u);
+    u->slot = pa_hook_connect(pa_bluetooth_discovery_hook(u->discovery, PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED),
+                              PA_HOOK_NORMAL, (pa_hook_cb_t) load_module_for_device, u);
 
     if (!async)
         pa_bluetooth_discovery_sync(u->discovery);