[pulseaudio-discuss] [RFCv2 10/17] bluetooth: Track org.ofono.HandsfreeAudioManager.CardRemoved

jprvita at gmail.com jprvita at gmail.com
Mon Apr 15 14:53:25 PDT 2013


From: João Paulo Rechi Vita <jprvita at openbossa.org>

When a HF card is removed its transport has to be disconnected and
removed from the discovery and device internal structures.
---
 src/modules/bluetooth/bluetooth-util.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index 2ef6535..da1e827 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -1726,6 +1726,30 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us
 
         hfagent_card_found(y, path, &props_i);
 
+    } else if (dbus_message_is_signal(m, "org.ofono.HandsfreeAudioManager", "CardRemoved")) {
+        const char *path;
+        pa_bluetooth_transport *t;
+        bool old_any_connected;
+
+        if (!dbus_message_get_args(m, &err, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID)) {
+            pa_log_error("Failed to parse org.ofono.HandsfreeAudioManager.CardRemoved: %s", err.message);
+            goto fail;
+        }
+
+
+        if ((t = pa_hashmap_remove(y->transports, path)) != NULL) {
+
+            old_any_connected = pa_bluetooth_device_any_audio_connected(t->device);
+
+            t->device->transports[t->profile] = NULL;
+            t->state = PA_BLUETOOTH_TRANSPORT_STATE_DISCONNECTED;
+            pa_hook_fire(&y->hooks[PA_BLUETOOTH_HOOK_TRANSPORT_STATE_CHANGED], t);
+
+            if (old_any_connected != pa_bluetooth_device_any_audio_connected(t->device))
+                run_callback(t->device, false);
+
+            transport_free(t);
+        }
     }
 
 fail:
@@ -2499,6 +2523,7 @@ pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *c) {
                 "type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',"
                 "arg0='org.ofono'",
                 "type='signal',sender='org.ofono',interface='org.ofono.HandsfreeAudioManager',member='CardAdded'",
+                "type='signal',sender='org.ofono',interface='org.ofono.HandsfreeAudioManager',member='CardRemoved'",
                 NULL) < 0) {
         pa_log("Failed to add D-Bus matches: %s", err.message);
         goto fail;
@@ -2585,6 +2610,7 @@ void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y) {
             "type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',"
             "arg0='org.ofono'",
             "type='signal',sender='org.ofono',interface='org.ofono.HandsfreeAudioManager',member='CardAdded'",
+            "type='signal',sender='org.ofono',interface='org.ofono.HandsfreeAudioManager',member='CardRemoved'",
             NULL);
 
         if (y->filter_added)
-- 
1.7.11.7



More information about the pulseaudio-discuss mailing list