[pulseaudio-discuss] [RFC 10/24] bluetooth: Parse HF cards properties
jprvita at gmail.com
jprvita at gmail.com
Tue Mar 26 22:16:49 PDT 2013
From: João Paulo Rechi Vita <jprvita at openbossa.org>
---
src/modules/bluetooth/bluetooth-util.c | 79 +++++++++++++++++++++++++++++++++-
1 file changed, 78 insertions(+), 1 deletion(-)
diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index 0645faa..2a4b694 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -128,6 +128,17 @@ struct pa_bluetooth_discovery {
pa_hashmap *hf_cards;
};
+struct handsfree_card {
+ pa_bluetooth_discovery *y;
+
+ const char *path;
+ const char *remote;
+ const char *local;
+
+ int fd;
+ uint8_t codec;
+};
+
static void get_properties_reply(DBusPendingCall *pending, void *userdata);
static pa_dbus_pending* send_and_add_to_pending(pa_bluetooth_discovery *y, DBusMessage *m, DBusPendingCallNotifyFunction func,
void *call_data);
@@ -1129,6 +1140,72 @@ static void init_bluez(pa_bluetooth_discovery *y) {
send_and_add_to_pending(y, m, get_managed_objects_reply, NULL);
}
+static void hfagent_card_found(pa_bluetooth_discovery *y, const char *path, DBusMessageIter *props_i) {
+ DBusMessageIter i, value_i;
+ const char *key, *value;
+ struct handsfree_card *hf_card;
+
+ pa_assert(y);
+ pa_assert(path);
+ pa_assert(props_i);
+
+ pa_log_debug("New HF card found: %s", path);
+
+ hf_card = pa_xnew0(struct handsfree_card, 1);
+ hf_card->y = y;
+ hf_card->path = pa_xstrdup(path);
+ hf_card->fd = -1;
+ hf_card->codec = 0;
+
+ while (dbus_message_iter_get_arg_type(props_i) != DBUS_TYPE_INVALID) {
+ char c;
+
+ if ((c = dbus_message_iter_get_arg_type(props_i)) != DBUS_TYPE_DICT_ENTRY) {
+ pa_log_error("Invalid properties for %s: expected \'e\', received \'%c\'", path, c);
+ goto fail;
+ }
+
+ dbus_message_iter_recurse(props_i, &i);
+
+ if ((c = dbus_message_iter_get_arg_type(&i)) != DBUS_TYPE_STRING) {
+ pa_log_error("Invalid properties for %s: expected \'s\', received \'%c\'", path, c);
+ goto fail;
+ }
+
+ dbus_message_iter_get_basic(&i, &key);
+ dbus_message_iter_next(&i);
+
+ if ((c = dbus_message_iter_get_arg_type(&i)) != DBUS_TYPE_VARIANT) {
+ pa_log_error("Invalid properties for %s: expected \'v\', received \'%c\'", path, c);
+ goto fail;
+ }
+
+ dbus_message_iter_recurse(&i, &value_i);
+
+ if ((c = dbus_message_iter_get_arg_type(&value_i)) != DBUS_TYPE_STRING) {
+ pa_log_error("Invalid properties for %s: expected \'s\', received \'%c\'", path, c);
+ goto fail;
+ }
+
+ dbus_message_iter_get_basic(&value_i, &value);
+
+ if (pa_streq(key, "RemoteAddress"))
+ hf_card->remote = pa_xstrdup(value);
+ else if (pa_streq(key, "LocalAddress"))
+ hf_card->local = pa_xstrdup(value);
+
+ pa_log_debug("%s: %s", key, value);
+
+ dbus_message_iter_next(props_i);
+ }
+
+ pa_hashmap_put(y->hf_cards, hf_card->path, hf_card);
+ return;
+
+fail:
+ pa_xfree(hf_card);
+}
+
static void hfagent_get_cards_reply(DBusPendingCall *pending, void *userdata) {
DBusMessage *r;
pa_dbus_pending *p;
@@ -1177,7 +1254,7 @@ static void hfagent_get_cards_reply(DBusPendingCall *pending, void *userdata) {
dbus_message_iter_recurse(&struct_i, &props_i);
- pa_log("Found HF card %s", path);
+ hfagent_card_found(y, path, &props_i);
dbus_message_iter_next(&array_i);
}
--
1.7.11.7
More information about the pulseaudio-discuss
mailing list