[pulseaudio-discuss] [PATCH 10/17] bluetooth: Handle CardRemoved signal

Luiz Augusto von Dentz luiz.dentz at gmail.com
Fri Aug 22 07:04:55 PDT 2014


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

---
 src/modules/bluetooth/backend-ofono.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/src/modules/bluetooth/backend-ofono.c b/src/modules/bluetooth/backend-ofono.c
index e07db01..a499711 100644
--- a/src/modules/bluetooth/backend-ofono.c
+++ b/src/modules/bluetooth/backend-ofono.c
@@ -269,6 +269,31 @@ fail:
     pa_xfree(card);
 }
 
+static void hf_audio_agent_card_removed(pa_bluetooth_backend *backend, const char *path) {
+    hf_audio_card *card;
+    bool old_any_connected;
+
+    pa_assert(backend);
+    pa_assert(path);
+
+    pa_log_debug("HF card removed: %s", path);
+
+    card = pa_hashmap_remove(backend->cards, path);
+    if (!card)
+        return;
+
+    old_any_connected = pa_bluetooth_device_any_transport_connected(card->transport->device);
+
+    card->transport->state = PA_BLUETOOTH_TRANSPORT_STATE_DISCONNECTED;
+    card->transport->device->transports[card->transport->profile] = NULL;
+    pa_hook_fire(pa_bluetooth_discovery_hook(backend->discovery, PA_BLUETOOTH_HOOK_TRANSPORT_STATE_CHANGED), card->transport);
+
+    if (old_any_connected != pa_bluetooth_device_any_transport_connected(card->transport->device))
+        pa_hook_fire(pa_bluetooth_discovery_hook(backend->discovery, PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED), card->transport->device);
+
+    hf_audio_card_free(card);
+}
+
 static void hf_audio_agent_get_cards_reply(DBusPendingCall *pending, void *userdata) {
     DBusMessage *r;
     pa_dbus_pending *p;
@@ -444,6 +469,15 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *da
         dbus_message_iter_recurse(&arg_i, &props_i);
 
         hf_audio_agent_card_found(backend, p, &props_i);
+    } else if (dbus_message_is_signal(m, "org.ofono.HandsfreeAudioManager", "CardRemoved")) {
+        const char *p;
+
+        if (!dbus_message_get_args(m, &err, DBUS_TYPE_OBJECT_PATH, &p, DBUS_TYPE_INVALID)) {
+            pa_log_error("Failed to parse org.ofono.HandsfreeAudioManager.CardRemoved: %s", err.message);
+            goto fail;
+        }
+
+        hf_audio_agent_card_removed(backend, p);
     }
 
 fail:
-- 
1.9.3



More information about the pulseaudio-discuss mailing list