[pulseaudio-discuss] [PATCH next v1 3/7] bluetooth: Add transport hooks into pa_bluetooth_hook_t

Mikel Astiz mikel.astiz.oss at gmail.com
Sun Dec 9 23:30:39 PST 2012


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

Add the transport-handling hooks to the centralized list of hooks in
pa_bluetooth_hook_t. These are intended to replace the now deprecated
transport-specific hook list in pa_bluetooth_transport_hook_t.
---
 src/modules/bluetooth/bluetooth-util.c | 10 ++++++++++
 src/modules/bluetooth/bluetooth-util.h |  2 ++
 2 files changed, 12 insertions(+)

diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index d57f3ee..cb66575 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -204,6 +204,8 @@ static void device_free(pa_bluetooth_device *d) {
 
         d->transports[i] = NULL;
         pa_hashmap_remove(d->discovery->transports, t->path);
+        t->state = PA_BLUETOOTH_TRANSPORT_STATE_DISCONNECTED;
+        pa_hook_fire(&d->discovery->hooks[PA_BLUETOOTH_HOOK_TRANSPORT_STATE_CHANGED], t);
         pa_hook_fire(&t->hooks[PA_BLUETOOTH_TRANSPORT_HOOK_REMOVED], NULL);
         transport_free(t);
     }
@@ -503,6 +505,7 @@ static int parse_audio_property(pa_bluetooth_device *d, const char *interface, D
 
             if (pa_streq(key, "State")) {
                 pa_bt_audio_state_t state = pa_bt_audio_state_from_string(value);
+                pa_bluetooth_transport_state_t old_state;
 
                 pa_log_debug("dbus: property 'State' changed to value '%s'", value);
 
@@ -521,7 +524,11 @@ static int parse_audio_property(pa_bluetooth_device *d, const char *interface, D
                 if (!transport)
                     break;
 
+                old_state = transport->state;
                 transport->state = pa_bt_audio_state_to_transport_state(state);
+
+                if (transport->state != old_state)
+                    pa_hook_fire(&d->discovery->hooks[PA_BLUETOOTH_HOOK_TRANSPORT_STATE_CHANGED], transport);
             }
 
             break;
@@ -814,6 +821,7 @@ static int pa_bluetooth_transport_parse_property(pa_bluetooth_transport *t, DBus
             if (pa_streq(key, "NREC") && t->nrec != value) {
                 t->nrec = value;
                 pa_log_debug("Transport %s: Property 'NREC' changed to %s.", t->path, t->nrec ? "True" : "False");
+                pa_hook_fire(&t->device->discovery->hooks[PA_BLUETOOTH_HOOK_TRANSPORT_NREC_CHANGED], t);
                 pa_hook_fire(&t->hooks[PA_BLUETOOTH_TRANSPORT_HOOK_NREC_CHANGED], NULL);
             }
 
@@ -1250,6 +1258,8 @@ static DBusMessage *endpoint_clear_configuration(DBusConnection *c, DBusMessage
         pa_log_debug("Clearing transport %s profile %d", t->path, t->profile);
         t->device->transports[t->profile] = NULL;
         pa_hashmap_remove(y->transports, t->path);
+        t->state = PA_BLUETOOTH_TRANSPORT_STATE_DISCONNECTED;
+        pa_hook_fire(&y->hooks[PA_BLUETOOTH_HOOK_TRANSPORT_STATE_CHANGED], t);
         pa_hook_fire(&t->hooks[PA_BLUETOOTH_TRANSPORT_HOOK_REMOVED], NULL);
         transport_free(t);
     }
diff --git a/src/modules/bluetooth/bluetooth-util.h b/src/modules/bluetooth/bluetooth-util.h
index cc8b08b..b35e533 100644
--- a/src/modules/bluetooth/bluetooth-util.h
+++ b/src/modules/bluetooth/bluetooth-util.h
@@ -74,6 +74,8 @@ struct pa_bluetooth_hook_uuid_data {
 typedef enum pa_bluetooth_hook {
     PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED, /* Call data: pa_bluetooth_device */
     PA_BLUETOOTH_HOOK_DEVICE_UUID_ADDED, /* Call data: pa_bluetooth_hook_uuid_data */
+    PA_BLUETOOTH_HOOK_TRANSPORT_STATE_CHANGED, /* Call data: pa_bluetooth_transport */
+    PA_BLUETOOTH_HOOK_TRANSPORT_NREC_CHANGED, /* Call data: pa_bluetooth_transport */
     PA_BLUETOOTH_HOOK_MAX
 } pa_bluetooth_hook_t;
 
-- 
1.7.11.7



More information about the pulseaudio-discuss mailing list