From: Jo?o Paulo Rechi Vita <jprvita@xxxxxxxxxxxxx> Each Bluetooth HFP modem is represented as a Handsfree Audio Card in oFono's Handsfree Audio Manager. This commits adds support for querying the list of hands-free audio cards from oFono. --- src/modules/bluetooth/bluetooth-util.c | 70 ++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c index 7aeec00..dd01b5a 100644 --- a/src/modules/bluetooth/bluetooth-util.c +++ b/src/modules/bluetooth/bluetooth-util.c @@ -1129,6 +1129,75 @@ static void init_bluez(pa_bluetooth_discovery *y) { send_and_add_to_pending(y, m, get_managed_objects_reply, NULL); } +static void hfagent_get_cards_reply(DBusPendingCall *pending, void *userdata) { + DBusMessage *r; + pa_dbus_pending *p; + pa_bluetooth_discovery *y; + DBusMessageIter i, array_i, struct_i, props_i; + char c; + + pa_assert_se(p = userdata); + pa_assert_se(y = 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); + + pa_log("Found HF card %s", path); + + dbus_message_iter_next(&array_i); + } + +finish: + dbus_message_unref(r); + + PA_LLIST_REMOVE(pa_dbus_pending, y->pending, p); + pa_dbus_pending_free(p); +} + +static void hfagent_get_cards(pa_bluetooth_discovery *y) { + DBusMessage *m; + + pa_assert(y); + + pa_assert_se(m = dbus_message_new_method_call("org.ofono", "/", "org.ofono.HandsfreeAudioManager", "GetCards")); + send_and_add_to_pending(y, m, hfagent_get_cards_reply, NULL); +} + static void hfagent_register_reply(DBusPendingCall *pending, void *userdata) { DBusMessage *r; pa_dbus_pending *p; @@ -1146,6 +1215,7 @@ static void hfagent_register_reply(DBusPendingCall *pending, void *userdata) { y->ofono_bus_id = pa_xstrdup(dbus_message_get_sender(r)); y->hf_cards = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); + hfagent_get_cards(y); finish: dbus_message_unref(r); -- 1.7.11.7