[pulseaudio-discuss] [PATCH v4 03/41] bluetooth: Create pa_bluetooth_adapter for BlueZ 5 support

jprvita at gmail.com jprvita at gmail.com
Wed Sep 18 14:16:57 PDT 2013


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

---
 src/modules/bluetooth/bluez5-util.c | 34 ++++++++++++++++++++++++++++++++++
 src/modules/bluetooth/bluez5-util.h |  7 +++++++
 2 files changed, 41 insertions(+)

diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c
index bfb3359..2f08f59 100644
--- a/src/modules/bluetooth/bluez5-util.c
+++ b/src/modules/bluetooth/bluez5-util.c
@@ -45,8 +45,36 @@ struct pa_bluetooth_discovery {
     bool filter_added;
     bool matches_added;
     pa_hook hooks[PA_BLUETOOTH_HOOK_MAX];
+    pa_hashmap *adapters;
 };
 
+static pa_bluetooth_adapter* adapter_create(pa_bluetooth_discovery *y, const char *path) {
+    pa_bluetooth_adapter *a;
+
+    pa_assert(y);
+    pa_assert(path);
+
+    a = pa_xnew0(pa_bluetooth_adapter, 1);
+    a->discovery = y;
+    a->path = pa_xstrdup(path);
+
+    pa_hashmap_put(y->adapters, a->path, a);
+
+    return a;
+}
+
+static void adapter_remove_all(pa_bluetooth_discovery *y) {
+    pa_bluetooth_adapter *a;
+
+    pa_assert(y);
+
+    while ((a = pa_hashmap_steal_first(y->adapters))) {
+        pa_xfree(a->path);
+        pa_xfree(a->address);
+        pa_xfree(a);
+    }
+}
+
 pa_hook* pa_bluetooth_discovery_hook(pa_bluetooth_discovery *y, pa_bluetooth_hook_t hook) {
     pa_assert(y);
     pa_assert(PA_REFCNT_VALUE(y) > 0);
@@ -109,6 +137,7 @@ pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *c) {
     y = pa_xnew0(pa_bluetooth_discovery, 1);
     PA_REFCNT_INIT(y);
     y->core = c;
+    y->adapters = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
 
     for (i = 0; i < PA_BLUETOOTH_HOOK_MAX; i++)
         pa_hook_init(&y->hooks[i], y);
@@ -165,6 +194,11 @@ void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y) {
     if (PA_REFCNT_DEC(y) > 0)
         return;
 
+    if (y->adapters) {
+        adapter_remove_all(y);
+        pa_hashmap_free(y->adapters, NULL);
+    }
+
     if (y->connection) {
 
         if (y->matches_added)
diff --git a/src/modules/bluetooth/bluez5-util.h b/src/modules/bluetooth/bluez5-util.h
index afbd8e9..1f2f702 100644
--- a/src/modules/bluetooth/bluez5-util.h
+++ b/src/modules/bluetooth/bluez5-util.h
@@ -24,12 +24,19 @@
 
 #include <pulsecore/core.h>
 
+typedef struct pa_bluetooth_adapter pa_bluetooth_adapter;
 typedef struct pa_bluetooth_discovery pa_bluetooth_discovery;
 
 typedef enum pa_bluetooth_hook {
     PA_BLUETOOTH_HOOK_MAX
 } pa_bluetooth_hook_t;
 
+struct pa_bluetooth_adapter {
+    pa_bluetooth_discovery *discovery;
+    char *path;
+    char *address;
+};
+
 pa_hook* pa_bluetooth_discovery_hook(pa_bluetooth_discovery *y, pa_bluetooth_hook_t hook);
 
 pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *core);
-- 
1.8.3.1



More information about the pulseaudio-discuss mailing list