[RFC 14/24] bluetooth: Track org.ofono.HandsfreeAudioManager.CardRemoved

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Jo?o Paulo Rechi Vita <jprvita@xxxxxxxxxxxxx>

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 4f8ab79..419e7ac 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -1733,6 +1733,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:
@@ -2505,6 +2529,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;
@@ -2591,6 +2616,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



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux