[PATCH 21/56] bluetooth: Create pa_bluetooth_discovery for BlueZ 5

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

 



From: Jo?o Paulo Rechi Vita <jprvita@xxxxxxxxxxxxx>

pa_bluetooth_discovery is the struct that holds information about known
Bluetooth audio devices and other information about the Bluetooth stack.

This commit also creates bluez5-util.[ch], which will hold a lot of
utility functions to help with the BlueZ 5 support.
---
 src/Makefile.am                                | 10 +++-
 src/modules/bluetooth/bluez5-util.c            | 74 ++++++++++++++++++++++++++
 src/modules/bluetooth/bluez5-util.h            | 32 +++++++++++
 src/modules/bluetooth/module-bluez5-discover.c | 33 ++++++++++++
 4 files changed, 148 insertions(+), 1 deletion(-)
 create mode 100644 src/modules/bluetooth/bluez5-util.c
 create mode 100644 src/modules/bluetooth/bluez5-util.h

diff --git a/src/Makefile.am b/src/Makefile.am
index 733c338..52cd63f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1333,6 +1333,7 @@ endif
 if HAVE_BLUEZ_5
 modlibexec_LTLIBRARIES += \
 		module-bluetooth-policy.la \
+		libbluez5-util.la \
 		module-bluez5-discover.la
 endif
 
@@ -2049,9 +2050,16 @@ module_bluez4_device_la_LIBADD = $(MODULE_LIBADD) $(DBUS_LIBS) $(SBC_LIBS) libbl
 module_bluez4_device_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS) $(SBC_CFLAGS)
 
 # Bluetooth BlueZ 5 sink / source
+libbluez5_util_la_SOURCES = \
+		modules/bluetooth/bluez5-util.c \
+		modules/bluetooth/bluez5-util.h
+libbluez5_util_la_LDFLAGS = -avoid-version
+libbluez5_util_la_LIBADD = $(MODULE_LIBADD) $(DBUS_LIBS)
+libbluez5_util_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS)
+
 module_bluez5_discover_la_SOURCES = modules/bluetooth/module-bluez5-discover.c
 module_bluez5_discover_la_LDFLAGS = $(MODULE_LDFLAGS)
-module_bluez5_discover_la_LIBADD = $(MODULE_LIBADD) $(DBUS_LIBS)
+module_bluez5_discover_la_LIBADD = $(MODULE_LIBADD) $(DBUS_LIBS) libbluez5-util.la
 module_bluez5_discover_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS)
 
 # Apple Airtunes/RAOP
diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c
new file mode 100644
index 0000000..0f23bff
--- /dev/null
+++ b/src/modules/bluetooth/bluez5-util.c
@@ -0,0 +1,74 @@
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2008-2013 Jo?o Paulo Rechi Vita
+
+  PulseAudio is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License as
+  published by the Free Software Foundation; either version 2.1 of the
+  License, or (at your option) any later version.
+
+  PulseAudio is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <pulse/xmalloc.h>
+
+#include <pulsecore/core.h>
+#include <pulsecore/macro.h>
+#include <pulsecore/refcnt.h>
+#include <pulsecore/shared.h>
+
+#include "bluez5-util.h"
+
+struct pa_bluetooth_discovery {
+    PA_REFCNT_DECLARE;
+
+    pa_core *core;
+};
+
+pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *c) {
+    pa_bluetooth_discovery *y;
+
+    if ((y = pa_shared_get(c, "bluetooth-discovery")))
+        return pa_bluetooth_discovery_ref(y);
+
+    y = pa_xnew0(pa_bluetooth_discovery, 1);
+    PA_REFCNT_INIT(y);
+    y->core = c;
+
+    pa_shared_set(c, "bluetooth-discovery", y);
+
+    return y;
+}
+
+pa_bluetooth_discovery* pa_bluetooth_discovery_ref(pa_bluetooth_discovery *y) {
+    pa_assert(y);
+    pa_assert(PA_REFCNT_VALUE(y) > 0);
+
+    PA_REFCNT_INC(y);
+
+    return y;
+}
+
+void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y) {
+    pa_assert(y);
+    pa_assert(PA_REFCNT_VALUE(y) > 0);
+
+    if (PA_REFCNT_DEC(y) > 0)
+        return;
+
+    pa_shared_remove(y->core, "bluetooth-discovery");
+    pa_xfree(y);
+}
diff --git a/src/modules/bluetooth/bluez5-util.h b/src/modules/bluetooth/bluez5-util.h
new file mode 100644
index 0000000..56602bf
--- /dev/null
+++ b/src/modules/bluetooth/bluez5-util.h
@@ -0,0 +1,32 @@
+#ifndef foobluez5utilhfoo
+#define foobluez5utilhfoo
+
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2008-2013 Jo?o Paulo Rechi Vita
+
+  PulseAudio is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License as
+  published by the Free Software Foundation; either version 2.1 of the
+  License, or (at your option) any later version.
+
+  PulseAudio is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#include <pulsecore/core.h>
+
+typedef struct pa_bluetooth_discovery pa_bluetooth_discovery;
+
+pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *core);
+pa_bluetooth_discovery* pa_bluetooth_discovery_ref(pa_bluetooth_discovery *y);
+void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y);
+#endif
diff --git a/src/modules/bluetooth/module-bluez5-discover.c b/src/modules/bluetooth/module-bluez5-discover.c
index ef76048..8409bd3 100644
--- a/src/modules/bluetooth/module-bluez5-discover.c
+++ b/src/modules/bluetooth/module-bluez5-discover.c
@@ -23,9 +23,12 @@
 #include <config.h>
 #endif
 
+#include <pulsecore/core.h>
 #include <pulsecore/macro.h>
 #include <pulsecore/module.h>
 
+#include "bluez5-util.h"
+
 #include "module-bluez5-discover-symdef.h"
 
 PA_MODULE_AUTHOR("Jo?o Paulo Rechi Vita");
@@ -33,11 +36,41 @@ PA_MODULE_DESCRIPTION("Detect available BlueZ 5 Bluetooth audio devices and load
 PA_MODULE_VERSION(PACKAGE_VERSION);
 PA_MODULE_LOAD_ONCE(true);
 
+struct userdata {
+    pa_module *module;
+    pa_core *core;
+    pa_bluetooth_discovery *discovery;
+};
+
 int pa__init(pa_module* m) {
+    struct userdata *u;
+
     pa_assert(m);
+
+    m->userdata = u = pa_xnew0(struct userdata, 1);
+    u->module = m;
+    u->core = m->core;
+
+    if (!(u->discovery = pa_bluetooth_discovery_get(u->core)))
+        goto fail;
+
     return 0;
+
+fail:
+    pa__done(m);
+    return -1;
 }
 
 void pa__done(pa_module* m) {
+    struct userdata *u;
+
     pa_assert(m);
+
+    if (!(u = m->userdata))
+        return;
+
+    if (u->discovery)
+        pa_bluetooth_discovery_unref(u->discovery);
+
+    pa_xfree(u);
 }
-- 
1.7.11.7



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

  Powered by Linux