[pulseaudio-discuss] [RFCv3 07/20] bluetooth: Parse HF cards properties

jprvita at gmail.com jprvita at gmail.com
Sun Apr 21 20:07:37 PDT 2013


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

---
 src/modules/bluetooth/bluetooth-util.c | 95 +++++++++++++++++++++++++++++++++-
 1 file changed, 93 insertions(+), 2 deletions(-)

diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index dd01b5a..6334c79 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -128,6 +128,15 @@ struct pa_bluetooth_discovery {
     pa_hashmap *hf_cards;
 };
 
+struct handsfree_card {
+    char *path;
+    char *remote;
+    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 +1138,88 @@ static void init_bluez(pa_bluetooth_discovery *y) {
     send_and_add_to_pending(y, m, get_managed_objects_reply, NULL);
 }
 
+static struct handsfree_card *hf_card_new(pa_bluetooth_discovery *y, const char *path) {
+    struct handsfree_card *hf_card = pa_xnew0(struct handsfree_card, 1);
+
+    hf_card->path = pa_xstrdup(path);
+    hf_card->fd = -1;
+
+    return hf_card;
+}
+
+static void hf_card_free(void *data) {
+    struct handsfree_card *hf_card;
+
+    pa_assert_se(hf_card = data);
+
+    pa_xfree(hf_card->path);
+    pa_xfree(hf_card->remote);
+    pa_xfree(hf_card->local);
+    pa_xfree(hf_card);
+};
+
+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 = hf_card_new(y, path);
+
+    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 +1268,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);
     }
@@ -1252,7 +1343,7 @@ static void ofono_done(pa_bluetooth_discovery *y) {
     y->ofono_bus_id = NULL;
 
     if (y->hf_cards)
-        pa_hashmap_free(y->hf_cards, NULL); /* TODO: free hash entries */
+        pa_hashmap_free(y->hf_cards, hf_card_free);
     y->hf_cards = NULL;
 }
 
-- 
1.7.11.7



More information about the pulseaudio-discuss mailing list