[pulseaudio-discuss] [RFCv0 10/21] bluetooth: List HandsfreeAudioCard objects from oFono

jprvita at gmail.com jprvita at gmail.com
Tue Feb 4 14:03:55 PST 2014


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

---
 src/modules/bluetooth/hfaudioagent-ofono.c | 71 +++++++++++++++++++++++++++++-
 1 file changed, 70 insertions(+), 1 deletion(-)

diff --git a/src/modules/bluetooth/hfaudioagent-ofono.c b/src/modules/bluetooth/hfaudioagent-ofono.c
index b572c8a..c939988 100644
--- a/src/modules/bluetooth/hfaudioagent-ofono.c
+++ b/src/modules/bluetooth/hfaudioagent-ofono.c
@@ -84,6 +84,75 @@ static pa_dbus_pending* pa_bluetooth_dbus_send_and_add_to_pending(hf_audio_agent
     return p;
 }
 
+static void hf_audio_agent_get_cards_reply(DBusPendingCall *pending, void *userdata) {
+    DBusMessage *r;
+    pa_dbus_pending *p;
+    hf_audio_agent_data *hfdata;
+    DBusMessageIter i, array_i, struct_i, props_i;
+    char c;
+
+    pa_assert_se(p = userdata);
+    pa_assert_se(hfdata = p->context_data);
+    pa_assert_se(r = dbus_pending_call_steal_reply(pending));
+
+    if (dbus_message_get_type(r) == DBUS_MESSAGE_TYPE_ERROR) {
+        pa_log_error("Failed to get a list of handsfree audio cards from ofono: %s: %s",
+                     dbus_message_get_error_name(r), pa_dbus_get_error_message(r));
+        goto finish;
+    }
+
+    dbus_message_iter_init(r, &i);
+    if ((c = dbus_message_iter_get_arg_type(&i)) != DBUS_TYPE_ARRAY) {
+        pa_log_error("Invalid arguments in GetCards() reply: expected \'a\', received \'%c\'", c);
+        goto finish;
+    }
+
+    dbus_message_iter_recurse(&i, &array_i);
+    while (dbus_message_iter_get_arg_type(&array_i) != DBUS_TYPE_INVALID) {
+        const char *path;
+
+        if ((c = dbus_message_iter_get_arg_type(&array_i)) != DBUS_TYPE_STRUCT) {
+            pa_log_error("Invalid arguments in GetCards() reply: expected \'r\', received \'%c\'", c);
+            goto finish;
+        }
+
+        dbus_message_iter_recurse(&array_i, &struct_i);
+        if ((c = dbus_message_iter_get_arg_type(&struct_i)) != DBUS_TYPE_OBJECT_PATH) {
+            pa_log_error("Invalid arguments in GetCards() reply: expected \'o\', received \'%c\'", c);
+            goto finish;
+        }
+
+        dbus_message_iter_get_basic(&struct_i, &path);
+
+        dbus_message_iter_next(&struct_i);
+        if ((c = dbus_message_iter_get_arg_type(&struct_i)) != DBUS_TYPE_ARRAY) {
+            pa_log_error("Invalid arguments in GetCards() reply: expected \'a\', received \'%c\'", c);
+            goto finish;
+        }
+
+        dbus_message_iter_recurse(&struct_i, &props_i);
+
+        /* TODO: Parse HandsfreeAudioCard properties */
+
+        dbus_message_iter_next(&array_i);
+    }
+
+finish:
+    dbus_message_unref(r);
+
+    PA_LLIST_REMOVE(pa_dbus_pending, hfdata->pending, p);
+    pa_dbus_pending_free(p);
+}
+
+static void hf_audio_agent_get_cards(hf_audio_agent_data *hfdata) {
+    DBusMessage *m;
+
+    pa_assert(hfdata);
+
+    pa_assert_se(m = dbus_message_new_method_call(OFONO_SERVICE, "/", HF_AUDIO_MANAGER_INTERFACE, "GetCards"));
+    pa_bluetooth_dbus_send_and_add_to_pending(hfdata, m, hf_audio_agent_get_cards_reply, NULL);
+}
+
 static void hf_audio_agent_register_reply(DBusPendingCall *pending, void *userdata) {
     DBusMessage *r;
     pa_dbus_pending *p;
@@ -101,7 +170,7 @@ static void hf_audio_agent_register_reply(DBusPendingCall *pending, void *userda
 
     hfdata->ofono_bus_id = pa_xstrdup(dbus_message_get_sender(r));
 
-    /* TODO: List all HandsfreeAudioCard objects */
+    hf_audio_agent_get_cards(hfdata);
 
 finish:
     dbus_message_unref(r);
-- 
1.8.3.1



More information about the pulseaudio-discuss mailing list