[pulseaudio-discuss] [PATCH v1 7/8] bluetooth: Set to off if transport removed

Mikel Astiz mikel.astiz.oss at gmail.com
Thu Oct 18 01:27:21 PDT 2012


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

The recently added hook can be used to detect that the transport being
used has been removed. In this case, the profile needs to be set to off.
---
 src/modules/bluetooth/module-bluetooth-device.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index 9e943c8..3375886 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -143,6 +143,7 @@ struct userdata {
     char *path;
     pa_bluetooth_transport *transport;
     char *accesstype;
+    pa_hook_slot *transport_removed_slot;
 
     pa_bluetooth_discovery *discovery;
     pa_bool_t auto_connect;
@@ -1963,6 +1964,17 @@ static void bt_transport_config(struct userdata *u) {
 }
 
 /* Run from main thread */
+static pa_hook_result_t transport_removed_cb(pa_bluetooth_transport *t, void *call_data, struct userdata *u) {
+    pa_assert(t);
+    pa_assert(u);
+
+    if (pa_card_set_profile(u->card, "off", FALSE) < 0)
+        pa_log_debug("Failed to switch profile to off");
+
+    return PA_HOOK_OK;
+}
+
+/* Run from main thread */
 static int setup_transport(struct userdata *u) {
     const pa_bluetooth_device *d;
     pa_bluetooth_transport *t;
@@ -1984,6 +1996,9 @@ static int setup_transport(struct userdata *u) {
 
     u->transport = pa_bluetooth_transport_ref(t);
 
+    u->transport_removed_slot = pa_hook_connect(&t->hooks[PA_BLUETOOTH_TRANSPORT_HOOK_REMOVED], PA_HOOK_NORMAL,
+                                                (pa_hook_cb_t) transport_removed_cb, u);
+
     bt_transport_acquire(u, FALSE);
 
     bt_transport_config(u);
@@ -2055,6 +2070,11 @@ static void stop_thread(struct userdata *u) {
         u->hsp.nrec_changed_slot = NULL;
     }
 
+    if (u->transport_removed_slot) {
+        pa_hook_slot_free(u->transport_removed_slot);
+        u->transport_removed_slot = NULL;
+    }
+
     if (u->transport) {
         bt_transport_release(u);
         pa_bluetooth_transport_unref(u->transport);
-- 
1.7.11.7



More information about the pulseaudio-discuss mailing list