[RFC next v0 04/11] bluetooth: Add embedded BlueZ backend inside bluetooth-util

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Mikel Astiz <mikel.astiz@xxxxxxxxxxxx>

BlueZ 5 supports external profiles, meaning that certain Bluetooth
profiles (e.g. HFP/HSP) are completely handled outside BlueZ.

However, some other profiles (i.e. A2DP) are still implemented inside
BlueZ, so let's keep a BlueZ-specific backend inside bluetooth-util.

Furthermore, in the case of BlueZ 4, this embedded backend also supports
HSP/HFP.
---
 src/modules/bluetooth/bluetooth-util.c | 36 ++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index 56156a9..9f7cf77 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -96,6 +96,9 @@ struct profile_data {
     void *backend_private;
 };
 
+typedef struct bluez_backend_private {
+} bluez_backend_private;
+
 struct pa_bluetooth_discovery {
     PA_REFCNT_DECLARE;
 
@@ -109,6 +112,8 @@ struct pa_bluetooth_discovery {
     struct profile_data profiles[PA_BLUETOOTH_PROFILE_COUNT];
     pa_hook hooks[PA_BLUETOOTH_HOOK_MAX];
     bool filter_added;
+
+    bluez_backend_private backend_private;
 };
 
 static void get_properties_reply(DBusPendingCall *pending, void *userdata);
@@ -1975,6 +1980,33 @@ static DBusHandlerResult endpoint_handler(DBusConnection *c, DBusMessage *m, voi
     return DBUS_HANDLER_RESULT_HANDLED;
 }
 
+pa_bluetooth_backend bluez_backend = {
+};
+
+static void bluez_backend_init(pa_bluetooth_discovery *y) {
+    bluez_backend_private *bbp = &y->backend_private;
+
+    pa_bt_backend_register(y, &bluez_backend, PROFILE_A2DP, bbp);
+    pa_bt_backend_register(y, &bluez_backend, PROFILE_A2DP_SOURCE, bbp);
+
+    if (y->version >= BLUEZ_VERSION_5)
+        return;
+
+    pa_bt_backend_register(y, &bluez_backend, PROFILE_HSP, bbp);
+    pa_bt_backend_register(y, &bluez_backend, PROFILE_HFGW, bbp);
+}
+
+static void bluez_backend_done(pa_bluetooth_discovery *y) {
+    pa_bt_backend_unregister(y, &bluez_backend, PROFILE_A2DP);
+    pa_bt_backend_unregister(y, &bluez_backend, PROFILE_A2DP_SOURCE);
+
+    if (y->version >= BLUEZ_VERSION_5)
+        return;
+
+    pa_bt_backend_unregister(y, &bluez_backend, PROFILE_HSP);
+    pa_bt_backend_unregister(y, &bluez_backend, PROFILE_HFGW);
+}
+
 pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *c) {
     DBusError err;
     pa_bluetooth_discovery *y;
@@ -2003,6 +2035,8 @@ pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *c) {
 
     pa_shared_set(c, "bluetooth-discovery", y);
 
+    bluez_backend_init(y);
+
     if (setup_dbus(y) < 0)
         goto fail;
 
@@ -2079,6 +2113,8 @@ void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y) {
 
     pa_dbus_free_pending_list(&y->pending);
 
+    bluez_backend_done(y);
+
     if (y->devices) {
         remove_all_devices(y);
         pa_hashmap_free(y->devices, NULL);
-- 
1.8.1.4



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux