[pulseaudio-discuss] [PATCH v0 05/11] bluetooth: Add hook to tell device was removed

Mikel Astiz mikel.astiz.oss at gmail.com
Mon Oct 22 01:46:37 PDT 2012


From: Mikel Astiz <mikel.astiz at bmw-carit.de>

Add a hook to report that the device was removed, and thus references to
it should be released.
---
 src/modules/bluetooth/bluetooth-util.c | 10 ++++++++++
 src/modules/bluetooth/bluetooth-util.h |  8 ++++++++
 2 files changed, 18 insertions(+)

diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index b9ee8cc..1e81864 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -111,6 +111,7 @@ static void uuid_free(pa_bluetooth_uuid *u) {
 
 static pa_bluetooth_device* device_new(const char *path) {
     pa_bluetooth_device *d;
+    unsigned i;
 
     d = pa_xnew(pa_bluetooth_device, 1);
 
@@ -135,6 +136,9 @@ static pa_bluetooth_device* device_new(const char *path) {
     d->headset_state = PA_BT_AUDIO_STATE_INVALID;
     d->hfgw_state = PA_BT_AUDIO_STATE_INVALID;
 
+    for (i = 0; i < PA_BLUETOOTH_DEVICE_HOOK_MAX; i++)
+        pa_hook_init(&d->hooks[i], d);
+
     return d;
 }
 
@@ -154,6 +158,7 @@ static void transport_free(pa_bluetooth_transport *t) {
 static void device_free(pa_bluetooth_device *d) {
     pa_bluetooth_uuid *u;
     pa_bluetooth_transport *t;
+    unsigned i;
 
     pa_assert(d);
 
@@ -164,6 +169,9 @@ static void device_free(pa_bluetooth_device *d) {
 
     pa_hashmap_free(d->transports, NULL, NULL);
 
+    for (i = 0; i < PA_BLUETOOTH_DEVICE_HOOK_MAX; i++)
+        pa_hook_done(&d->hooks[i]);
+
     while ((u = d->uuids)) {
         PA_LLIST_REMOVE(pa_bluetooth_uuid, d->uuids, u);
         uuid_free(u);
@@ -465,6 +473,7 @@ static void remove_all_devices(pa_bluetooth_discovery *y) {
     pa_assert(y);
 
     while ((d = pa_hashmap_steal_first(y->devices))) {
+        pa_hook_fire(&d->hooks[PA_BLUETOOTH_DEVICE_HOOK_REMOVED], NULL);
         run_callback(y, d, TRUE);
         device_free(d);
     }
@@ -785,6 +794,7 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us
         pa_log_debug("Device %s removed", path);
 
         if ((d = pa_hashmap_remove(y->devices, path))) {
+            pa_hook_fire(&d->hooks[PA_BLUETOOTH_DEVICE_HOOK_REMOVED], NULL);
             run_callback(y, d, TRUE);
             device_free(d);
         }
diff --git a/src/modules/bluetooth/bluetooth-util.h b/src/modules/bluetooth/bluetooth-util.h
index 386c22e..4e3b5f0 100644
--- a/src/modules/bluetooth/bluetooth-util.h
+++ b/src/modules/bluetooth/bluetooth-util.h
@@ -91,6 +91,12 @@ typedef enum pa_bt_audio_state {
     PA_BT_AUDIO_STATE_PLAYING
 } pa_bt_audio_state_t;
 
+/* Hook data: pa_bluetooth_device pointer. */
+typedef enum pa_bluetooth_device_hook {
+    PA_BLUETOOTH_DEVICE_HOOK_REMOVED, /* Call data: NULL. */
+    PA_BLUETOOTH_DEVICE_HOOK_MAX
+} pa_bluetooth_device_hook_t;
+
 struct pa_bluetooth_device {
     pa_bool_t dead;
 
@@ -122,6 +128,8 @@ struct pa_bluetooth_device {
 
     /* HandsfreeGateway state */
     pa_bt_audio_state_t hfgw_state;
+
+    pa_hook hooks[PA_BLUETOOTH_DEVICE_HOOK_MAX];
 };
 
 pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *core);
-- 
1.7.11.7



More information about the pulseaudio-discuss mailing list