[pulseaudio-discuss] [PATCH next v0 02/11] bluetooth: Extend discovery to support multiple hooks
Mikel Astiz
mikel.astiz.oss at gmail.com
Thu Dec 6 06:55:27 PST 2012
From: Mikel Astiz <mikel.astiz at bmw-carit.de>
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 | 23 +++++++++++++++--------
src/modules/bluetooth/bluetooth-util.h | 8 +++++++-
src/modules/bluetooth/module-bluetooth-device.c | 7 ++++---
src/modules/bluetooth/module-bluetooth-discover.c | 3 ++-
4 files changed, 28 insertions(+), 13 deletions(-)
diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index 498f5bb..5f1ff01 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -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) {
diff --git a/src/modules/bluetooth/bluetooth-util.h b/src/modules/bluetooth/bluetooth-util.h
index 59d0d2e..63f07f3 100644
--- a/src/modules/bluetooth/bluetooth-util.h
+++ b/src/modules/bluetooth/bluetooth-util.h
@@ -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);
diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index da1b61f..95a0db1 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -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);
diff --git a/src/modules/bluetooth/module-bluetooth-discover.c b/src/modules/bluetooth/module-bluetooth-discover.c
index 48d0bee..41981f6 100644
--- a/src/modules/bluetooth/module-bluetooth-discover.c
+++ b/src/modules/bluetooth/module-bluetooth-discover.c
@@ -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);
--
1.7.11.7
More information about the pulseaudio-discuss
mailing list