[pulseaudio-discuss] [PATCH 09/17] bluetooth: Handle CardAdded signal

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


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

---
 src/modules/bluetooth/backend-ofono.c | 40 +++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 11 deletions(-)

diff --git a/src/modules/bluetooth/backend-ofono.c b/src/modules/bluetooth/backend-ofono.c
index 404a6b5..e07db01 100644
--- a/src/modules/bluetooth/backend-ofono.c
+++ b/src/modules/bluetooth/backend-ofono.c
@@ -247,20 +247,21 @@ static void hf_audio_agent_card_found(pa_bluetooth_backend *backend, const char
         dbus_message_iter_next(props_i);
     }
 
-    pa_hashmap_put(backend->cards, card->path, card);
-
     d = pa_bluetooth_discovery_get_device_by_address(backend->discovery, card->remote, card->local);
-    if (d) {
-        card->transport = pa_bluetooth_transport_new(d, backend->ofono_bus_id, path, PA_BLUETOOTH_PROFILE_HEADSET_AUDIO_GATEWAY, NULL, 0);
-        card->transport->acquire = hf_audio_agent_transport_acquire;
-        card->transport->release = hf_audio_agent_transport_release;
-        card->transport->userdata = backend;
+    if (!d) {
+        pa_log_error("Device doesnt exist for %s", path);
+        goto fail;
+    }
 
-        d->transports[PA_BLUETOOTH_PROFILE_HEADSET_AUDIO_GATEWAY] = card->transport;
+    pa_hashmap_put(backend->cards, card->path, card);
 
-        pa_bluetooth_transport_put(card->transport);
-    } else
-        pa_log_error("Device doesnt exist for %s", path);
+    card->transport = pa_bluetooth_transport_new(d, backend->ofono_bus_id, path, PA_BLUETOOTH_PROFILE_HEADSET_AUDIO_GATEWAY, NULL, 0);
+    card->transport->acquire = hf_audio_agent_transport_acquire;
+    card->transport->release = hf_audio_agent_transport_release;
+    card->transport->userdata = backend;
+
+    d->transports[PA_BLUETOOTH_PROFILE_HEADSET_AUDIO_GATEWAY] = card->transport;
+    pa_bluetooth_transport_put(card->transport);
 
     return;
 
@@ -426,6 +427,23 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *da
             }
         }
 
+    } else if (dbus_message_is_signal(m, "org.ofono.HandsfreeAudioManager", "CardAdded")) {
+        const char *p;
+        DBusMessageIter arg_i, props_i;
+
+        if (!dbus_message_iter_init(m, &arg_i) || !pa_streq(dbus_message_get_signature(m), "oa{sv}")) {
+            pa_log_error("Failed to parse org.ofono.HandsfreeAudioManager.CardAdded");
+            goto fail;
+        }
+
+        dbus_message_iter_get_basic(&arg_i, &p);
+
+        pa_assert_se(dbus_message_iter_next(&arg_i));
+        pa_assert(dbus_message_iter_get_arg_type(&arg_i) == DBUS_TYPE_ARRAY);
+
+        dbus_message_iter_recurse(&arg_i, &props_i);
+
+        hf_audio_agent_card_found(backend, p, &props_i);
     }
 
 fail:
-- 
1.9.3



More information about the pulseaudio-discuss mailing list