bluetooth: Add hook to tell device was removed
authorMikel Astiz <mikel.astiz@bmw-carit.de>
Mon, 22 Oct 2012 08:46:37 +0000 (10:46 +0200)
committerTanu Kaskinen <tanuk@iki.fi>
Mon, 22 Oct 2012 15:44:54 +0000 (18:44 +0300)
Add a hook to report that the device was removed, and thus references to
it should be released.

src/modules/bluetooth/bluetooth-util.c
src/modules/bluetooth/bluetooth-util.h

index b9ee8cc..1e81864 100644 (file)
@@ -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);
         }
index 386c22e..4e3b5f0 100644 (file)
@@ -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);