[pulseaudio-discuss] [PATCH v3 3/3] bluetooth: Rename *bluez5 modules to bluetooth

Luiz Augusto von Dentz luiz.dentz at gmail.com
Thu May 25 08:36:37 UTC 2017


From: Luiz Augusto von Dentz <luiz.von.dentz at intel.com>

Since there is no longer support for BlueZ 4 it makes no sense to keep
BlueZ 5 modules separated.
---
 configure.ac                                       |  68 ++++----
 src/Makefile.am                                    |  59 +++----
 src/modules/bluetooth/backend-native.c             |   2 +-
 src/modules/bluetooth/backend-ofono.c              |   2 +-
 .../bluetooth/{bluez5-util.c => bluez-util.c}      |  10 +-
 .../bluetooth/{bluez5-util.h => bluez-util.h}      |   8 +-
 ...e-bluez5-device.c => module-bluetooth-device.c} |   6 +-
 src/modules/bluetooth/module-bluetooth-discover.c  | 136 +++++++++++++---
 src/modules/bluetooth/module-bluez5-discover.c     | 174 ---------------------
 9 files changed, 186 insertions(+), 279 deletions(-)
 rename src/modules/bluetooth/{bluez5-util.c => bluez-util.c} (99%)
 rename src/modules/bluetooth/{bluez5-util.h => bluez-util.h} (98%)
 rename src/modules/bluetooth/{module-bluez5-device.c => module-bluetooth-device.c} (99%)
 delete mode 100644 src/modules/bluetooth/module-bluez5-discover.c

diff --git a/configure.ac b/configure.ac
index 30e776a..e387b7d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1037,46 +1037,42 @@ AX_DEFINE_DIR(PA_MACHINE_ID_FALLBACK, PA_MACHINE_ID_FALLBACK,
 
 #### BlueZ support (optional, dependent on D-Bus and SBC) ####
 
-AC_ARG_ENABLE([bluez5],
-    AS_HELP_STRING([--disable-bluez5],[Disable optional BlueZ 5 support]))
+AC_ARG_ENABLE([bluez],
+    AS_HELP_STRING([--disable-bluez],[Disable optional BlueZ support]))
 
 ## SBC ##
-AS_IF([test "x$enable_bluez5" != "xno"],
+AS_IF([test "x$enable_bluez" != "xno"],
     [PKG_CHECK_MODULES(SBC, [ sbc >= 1.0 ], HAVE_SBC=1, HAVE_SBC=0)],
     HAVE_SBC=0)
 
-## BlueZ 5 ##
-AS_IF([test "x$enable_bluez5" != "xno" && test "x$HAVE_DBUS" = "x1" && test "x$HAVE_SBC" = "x1"], HAVE_BLUEZ_5=1,
-      HAVE_BLUEZ_5=0)
-AS_IF([test "x$enable_bluez5" = "xyes" && test "x$HAVE_BLUEZ_5" != "x1"],
-    [AC_MSG_ERROR([*** BLUEZ 5 support not found (requires sbc and D-Bus)])])
-AC_SUBST(HAVE_BLUEZ_5)
-AM_CONDITIONAL([HAVE_BLUEZ_5], [test "x$HAVE_BLUEZ_5" = x1])
-
-AS_IF([test "x$HAVE_BLUEZ_5" = "x1"], HAVE_BLUEZ=1, HAVE_BLUEZ=0)
+## BlueZ ##
+AS_IF([test "x$enable_bluez" != "xno" && test "x$HAVE_DBUS" = "x1" && test "x$HAVE_SBC" = "x1"], HAVE_BLUEZ=1,
+      HAVE_BLUEZ=0)
+AS_IF([test "x$enable_bluez" = "xyes" && test "x$HAVE_BLUEZ" != "x1"],
+    [AC_MSG_ERROR([*** BLUEZ support not found (requires sbc and D-Bus)])])
 AC_SUBST(HAVE_BLUEZ)
 AM_CONDITIONAL([HAVE_BLUEZ], [test "x$HAVE_BLUEZ" = x1])
 
 ## Bluetooth Headset profiles backend ##
 
-AC_ARG_ENABLE([bluez5-ofono-headset],
-    AS_HELP_STRING([--disable-bluez5-ofono-headset],[Disable optional ofono headset backend support (Bluez 5)]))
-AS_IF([test "x$HAVE_BLUEZ_5" = "x1" && test "x$enable_bluez5_ofono_headset" != "xno"], HAVE_BLUEZ_5_OFONO_HEADSET=1,
-      HAVE_BLUEZ_5_OFONO_HEADSET=0)
-AC_SUBST(HAVE_BLUEZ_5_OFONO_HEADSET)
-AM_CONDITIONAL([HAVE_BLUEZ_5_OFONO_HEADSET], [test "x$HAVE_BLUEZ_5_OFONO_HEADSET" = x1])
-AS_IF([test "x$HAVE_BLUEZ_5_OFONO_HEADSET" = "x1"], AC_DEFINE([HAVE_BLUEZ_5_OFONO_HEADSET], 1, [Bluez 5 ofono headset backend enabled]))
-
-AC_ARG_ENABLE([bluez5-native-headset],
-    AS_HELP_STRING([--disable-bluez5-native-headset],[Disable optional native headset backend support (Bluez 5)]))
-AS_IF([test "x$HAVE_BLUEZ_5" = "x1" && test "x$enable_bluez5_native_headset" != "xno"],
-      [PKG_CHECK_MODULES(BLUEZ, [ bluez >= 4.101 ], HAVE_BLUEZ_5_NATIVE_HEADSET=1, HAVE_BLUEZ_5_NATIVE_HEADSET=0)],
-      HAVE_BLUEZ_5_NATIVE_HEADSET=0)
-AS_IF([test "x$enable_bluez5_native_headset" = "xyes" && test "x$HAVE_BLUEZ_5_NATIVE_HEADSET" = "x0"],
-      [AC_MSG_ERROR([*** BlueZ 5 native headset backend support not available (requires the libbluetooth headers)])])
-AC_SUBST(HAVE_BLUEZ_5_NATIVE_HEADSET)
-AM_CONDITIONAL([HAVE_BLUEZ_5_NATIVE_HEADSET], [test "x$HAVE_BLUEZ_5_NATIVE_HEADSET" = x1])
-AS_IF([test "x$HAVE_BLUEZ_5_NATIVE_HEADSET" = "x1"], AC_DEFINE([HAVE_BLUEZ_5_NATIVE_HEADSET], 1, [Bluez 5 native headset backend enabled]))
+AC_ARG_ENABLE([bluez-ofono-headset],
+    AS_HELP_STRING([--disable-bluez-ofono-headset],[Disable optional ofono headset backend support (Bluez 5)]))
+AS_IF([test "x$HAVE_BLUEZ" = "x1" && test "x$enable_bluez_ofono_headset" != "xno"], HAVE_BLUEZ_OFONO_HEADSET=1,
+      HAVE_BLUEZ_OFONO_HEADSET=0)
+AC_SUBST(HAVE_BLUEZ_OFONO_HEADSET)
+AM_CONDITIONAL([HAVE_BLUEZ_OFONO_HEADSET], [test "x$HAVE_BLUEZ_OFONO_HEADSET" = x1])
+AS_IF([test "x$HAVE_BLUEZ_OFONO_HEADSET" = "x1"], AC_DEFINE([HAVE_BLUEZ_OFONO_HEADSET], 1, [Bluez 5 ofono headset backend enabled]))
+
+AC_ARG_ENABLE([bluez-native-headset],
+    AS_HELP_STRING([--disable-bluez-native-headset],[Disable optional native headset backend support (Bluez 5)]))
+AS_IF([test "x$HAVE_BLUEZ" = "x1" && test "x$enable_bluez_native_headset" != "xno"],
+      [PKG_CHECK_MODULES(BLUEZ, [ bluez >= 5.0 ], HAVE_BLUEZ_NATIVE_HEADSET=1, HAVE_BLUEZ_NATIVE_HEADSET=0)],
+      HAVE_BLUEZ_NATIVE_HEADSET=0)
+AS_IF([test "x$enable_bluez_native_headset" = "xyes" && test "x$HAVE_BLUEZ_NATIVE_HEADSET" = "x0"],
+      [AC_MSG_ERROR([*** BlueZ native headset backend support not available (requires the libbluetooth headers)])])
+AC_SUBST(HAVE_BLUEZ_NATIVE_HEADSET)
+AM_CONDITIONAL([HAVE_BLUEZ_NATIVE_HEADSET], [test "x$HAVE_BLUEZ_NATIVE_HEADSET" = x1])
+AS_IF([test "x$HAVE_BLUEZ_NATIVE_HEADSET" = "x1"], AC_DEFINE([HAVE_BLUEZ_NATIVE_HEADSET], 1, [Bluez 5 native headset backend enabled]))
 
 #### UDEV support (optional) ####
 
@@ -1555,9 +1551,9 @@ AS_IF([test "x$HAVE_UDEV" = "x1"], ENABLE_UDEV=yes, ENABLE_UDEV=no)
 AS_IF([test "x$HAVE_SYSTEMD_DAEMON" = "x1"], ENABLE_SYSTEMD_DAEMON=yes, ENABLE_SYSTEMD_DAEMON=no)
 AS_IF([test "x$HAVE_SYSTEMD_LOGIN" = "x1"], ENABLE_SYSTEMD_LOGIN=yes, ENABLE_SYSTEMD_LOGIN=no)
 AS_IF([test "x$HAVE_SYSTEMD_JOURNAL" = "x1"], ENABLE_SYSTEMD_JOURNAL=yes, ENABLE_SYSTEMD_JOURNAL=no)
-AS_IF([test "x$HAVE_BLUEZ_5" = "x1"], ENABLE_BLUEZ_5=yes, ENABLE_BLUEZ_5=no)
-AS_IF([test "x$HAVE_BLUEZ_5_OFONO_HEADSET" = "x1"], ENABLE_BLUEZ_5_OFONO_HEADSET=yes, ENABLE_BLUEZ_5_OFONO_HEADSET=no)
-AS_IF([test "x$HAVE_BLUEZ_5_NATIVE_HEADSET" = "x1"], ENABLE_BLUEZ_5_NATIVE_HEADSET=yes, ENABLE_BLUEZ_5_NATIVE_HEADSET=no)
+AS_IF([test "x$HAVE_BLUEZ" = "x1"], ENABLE_BLUEZ=yes, ENABLE_BLUEZ=no)
+AS_IF([test "x$HAVE_BLUEZ_OFONO_HEADSET" = "x1"], ENABLE_BLUEZ_OFONO_HEADSET=yes, ENABLE_BLUEZ_OFONO_HEADSET=no)
+AS_IF([test "x$HAVE_BLUEZ_NATIVE_HEADSET" = "x1"], ENABLE_BLUEZ_NATIVE_HEADSET=yes, ENABLE_BLUEZ_NATIVE_HEADSET=no)
 AS_IF([test "x$HAVE_HAL_COMPAT" = "x1"], ENABLE_HAL_COMPAT=yes, ENABLE_HAL_COMPAT=no)
 AS_IF([test "x$HAVE_TCPWRAP" = "x1"], ENABLE_TCPWRAP=yes, ENABLE_TCPWRAP=no)
 AS_IF([test "x$HAVE_LIBSAMPLERATE" = "x1"], ENABLE_LIBSAMPLERATE="yes (DEPRECATED)", ENABLE_LIBSAMPLERATE=no)
@@ -1612,9 +1608,9 @@ echo "
     Enable Async DNS:              ${ENABLE_LIBASYNCNS}
     Enable LIRC:                   ${ENABLE_LIRC}
     Enable D-Bus:                  ${ENABLE_DBUS}
-      Enable BlueZ 5:              ${ENABLE_BLUEZ_5}
-        Enable ofono headsets:     ${ENABLE_BLUEZ_5_OFONO_HEADSET}
-        Enable native headsets:    ${ENABLE_BLUEZ_5_NATIVE_HEADSET}
+      Enable BlueZ:                ${ENABLE_BLUEZ}
+        Enable ofono headsets:     ${ENABLE_BLUEZ_OFONO_HEADSET}
+        Enable native headsets:    ${ENABLE_BLUEZ_NATIVE_HEADSET}
     Enable udev:                   ${ENABLE_UDEV}
       Enable HAL->udev compat:     ${ENABLE_HAL_COMPAT}
     Enable systemd
diff --git a/src/Makefile.am b/src/Makefile.am
index 96caed2..eae1d2e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1430,14 +1430,9 @@ endif
 if HAVE_BLUEZ
 modlibexec_LTLIBRARIES += \
 		module-bluetooth-discover.la \
-		module-bluetooth-policy.la
-endif
-
-if HAVE_BLUEZ_5
-modlibexec_LTLIBRARIES += \
-		libbluez5-util.la \
-		module-bluez5-discover.la \
-		module-bluez5-device.la
+		module-bluetooth-policy.la \
+		libbluez-util.la \
+		module-bluetooth-device.la
 endif
 
 # RAOP depends on RTP, and we don't support RTP on Windows, see comment at
@@ -1531,8 +1526,8 @@ SYMDEF_FILES = \
 		module-systemd-login-symdef.h \
 		module-bluetooth-policy-symdef.h \
 		module-bluetooth-discover-symdef.h \
-		module-bluez5-discover-symdef.h \
-		module-bluez5-device-symdef.h \
+		module-bluetooth-discover-symdef.h \
+		module-bluetooth-device-symdef.h \
 		module-raop-sink-symdef.h \
 		module-raop-discover-symdef.h \
 		module-gconf-symdef.h \
@@ -2131,39 +2126,33 @@ module_bluetooth_policy_la_LDFLAGS = $(MODULE_LDFLAGS)
 module_bluetooth_policy_la_LIBADD = $(MODULE_LIBADD)
 module_bluetooth_policy_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS)
 
-# Bluetooth discover
-module_bluetooth_discover_la_SOURCES = modules/bluetooth/module-bluetooth-discover.c
-module_bluetooth_discover_la_LDFLAGS = $(MODULE_LDFLAGS)
-module_bluetooth_discover_la_LIBADD = $(MODULE_LIBADD)
-module_bluetooth_discover_la_CFLAGS = $(AM_CFLAGS)
-
-# Bluetooth BlueZ 5 sink / source
-libbluez5_util_la_SOURCES = \
-		modules/bluetooth/bluez5-util.c \
-		modules/bluetooth/bluez5-util.h \
+# Bluetooth BlueZ sink / source
+libbluez_util_la_SOURCES = \
+		modules/bluetooth/bluez-util.c \
+		modules/bluetooth/bluez-util.h \
 		modules/bluetooth/a2dp-codecs.h
-if HAVE_BLUEZ_5_OFONO_HEADSET
-libbluez5_util_la_SOURCES += \
+if HAVE_BLUEZ_OFONO_HEADSET
+libbluez_util_la_SOURCES += \
 		modules/bluetooth/backend-ofono.c
 endif
-if HAVE_BLUEZ_5_NATIVE_HEADSET
-libbluez5_util_la_SOURCES += \
+if HAVE_BLUEZ_NATIVE_HEADSET
+libbluez_util_la_SOURCES += \
 		modules/bluetooth/backend-native.c
 endif
 
-libbluez5_util_la_LDFLAGS = -avoid-version
-libbluez5_util_la_LIBADD = $(MODULE_LIBADD) $(DBUS_LIBS)
-libbluez5_util_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS)
+libbluez_util_la_LDFLAGS = -avoid-version
+libbluez_util_la_LIBADD = $(MODULE_LIBADD) $(DBUS_LIBS)
+libbluez_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) libbluez5-util.la
-module_bluez5_discover_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS)
+module_bluetooth_discover_la_SOURCES = modules/bluetooth/module-bluetooth-discover.c
+module_bluetooth_discover_la_LDFLAGS = $(MODULE_LDFLAGS)
+module_bluetooth_discover_la_LIBADD = $(MODULE_LIBADD) $(DBUS_LIBS) libbluez-util.la
+module_bluetooth_discover_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS)
 
-module_bluez5_device_la_SOURCES = modules/bluetooth/module-bluez5-device.c
-module_bluez5_device_la_LDFLAGS = $(MODULE_LDFLAGS)
-module_bluez5_device_la_LIBADD = $(MODULE_LIBADD) $(SBC_LIBS) libbluez5-util.la
-module_bluez5_device_la_CFLAGS = $(AM_CFLAGS) $(SBC_CFLAGS)
+module_bluetooth_device_la_SOURCES = modules/bluetooth/module-bluetooth-device.c
+module_bluetooth_device_la_LDFLAGS = $(MODULE_LDFLAGS)
+module_bluetooth_device_la_LIBADD = $(MODULE_LIBADD) $(SBC_LIBS) libbluez-util.la
+module_bluetooth_device_la_CFLAGS = $(AM_CFLAGS) $(SBC_CFLAGS)
 
 # Apple Airtunes/RAOP
 module_raop_sink_la_SOURCES = modules/raop/module-raop-sink.c
diff --git a/src/modules/bluetooth/backend-native.c b/src/modules/bluetooth/backend-native.c
index 6eb4e16..ea46240 100644
--- a/src/modules/bluetooth/backend-native.c
+++ b/src/modules/bluetooth/backend-native.c
@@ -34,7 +34,7 @@
 #include <bluetooth/bluetooth.h>
 #include <bluetooth/sco.h>
 
-#include "bluez5-util.h"
+#include "bluez-util.h"
 
 struct pa_bluetooth_backend {
   pa_core *core;
diff --git a/src/modules/bluetooth/backend-ofono.c b/src/modules/bluetooth/backend-ofono.c
index d098402..7dda39c 100644
--- a/src/modules/bluetooth/backend-ofono.c
+++ b/src/modules/bluetooth/backend-ofono.c
@@ -29,7 +29,7 @@
 #include <pulsecore/shared.h>
 #include <pulsecore/core-error.h>
 
-#include "bluez5-util.h"
+#include "bluez-util.h"
 
 #define HFP_AUDIO_CODEC_CVSD    0x01
 #define HFP_AUDIO_CODEC_MSBC    0x02
diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez-util.c
similarity index 99%
rename from src/modules/bluetooth/bluez5-util.c
rename to src/modules/bluetooth/bluez-util.c
index 8956fb1..cb9b778 100644
--- a/src/modules/bluetooth/bluez5-util.c
+++ b/src/modules/bluetooth/bluez-util.c
@@ -35,7 +35,7 @@
 
 #include "a2dp-codecs.h"
 
-#include "bluez5-util.h"
+#include "bluez-util.h"
 
 #define WAIT_FOR_PROFILES_TIMEOUT_USEC (3 * PA_USEC_PER_SEC)
 
@@ -347,7 +347,7 @@ void pa_bluetooth_transport_free(pa_bluetooth_transport *t) {
     pa_xfree(t);
 }
 
-static int bluez5_transport_acquire_cb(pa_bluetooth_transport *t, bool optional, size_t *imtu, size_t *omtu) {
+static int bluez_transport_acquire_cb(pa_bluetooth_transport *t, bool optional, size_t *imtu, size_t *omtu) {
     DBusMessage *m, *r;
     DBusError err;
     int ret;
@@ -392,7 +392,7 @@ finish:
     return ret;
 }
 
-static void bluez5_transport_release_cb(pa_bluetooth_transport *t) {
+static void bluez_transport_release_cb(pa_bluetooth_transport *t) {
     DBusMessage *m;
     DBusError err;
 
@@ -1457,8 +1457,8 @@ static DBusMessage *endpoint_set_configuration(DBusConnection *conn, DBusMessage
     dbus_message_unref(r);
 
     t = pa_bluetooth_transport_new(d, sender, path, p, config, size);
-    t->acquire = bluez5_transport_acquire_cb;
-    t->release = bluez5_transport_release_cb;
+    t->acquire = bluez_transport_acquire_cb;
+    t->release = bluez_transport_release_cb;
     pa_bluetooth_transport_put(t);
 
     pa_log_debug("Transport %s available for profile %s", t->path, pa_bluetooth_profile_to_string(t->profile));
diff --git a/src/modules/bluetooth/bluez5-util.h b/src/modules/bluetooth/bluez-util.h
similarity index 98%
rename from src/modules/bluetooth/bluez5-util.h
rename to src/modules/bluetooth/bluez-util.h
index a3e7bf3..42d084a 100644
--- a/src/modules/bluetooth/bluez5-util.h
+++ b/src/modules/bluetooth/bluez-util.h
@@ -1,5 +1,5 @@
-#ifndef foobluez5utilhfoo
-#define foobluez5utilhfoo
+#ifndef foobluezutilhfoo
+#define foobluezutilhfoo
 
 /***
   This file is part of PulseAudio.
@@ -118,7 +118,7 @@ struct pa_bluetooth_adapter {
     bool valid;
 };
 
-#ifdef HAVE_BLUEZ_5_OFONO_HEADSET
+#ifdef HAVE_BLUEZ_OFONO_HEADSET
 pa_bluetooth_backend *pa_bluetooth_ofono_backend_new(pa_core *c, pa_bluetooth_discovery *y);
 void pa_bluetooth_ofono_backend_free(pa_bluetooth_backend *b);
 #else
@@ -128,7 +128,7 @@ static inline pa_bluetooth_backend *pa_bluetooth_ofono_backend_new(pa_core *c, p
 static inline void pa_bluetooth_ofono_backend_free(pa_bluetooth_backend *b) {}
 #endif
 
-#ifdef HAVE_BLUEZ_5_NATIVE_HEADSET
+#ifdef HAVE_BLUEZ_NATIVE_HEADSET
 pa_bluetooth_backend *pa_bluetooth_native_backend_new(pa_core *c, pa_bluetooth_discovery *y, bool enable_hs_role);
 void pa_bluetooth_native_backend_free(pa_bluetooth_backend *b);
 void pa_bluetooth_native_backend_enable_hs_role(pa_bluetooth_backend *b, bool enable_hs_role);
diff --git a/src/modules/bluetooth/module-bluez5-device.c b/src/modules/bluetooth/module-bluetooth-device.c
similarity index 99%
rename from src/modules/bluetooth/module-bluez5-device.c
rename to src/modules/bluetooth/module-bluetooth-device.c
index 867def7..3168285 100644
--- a/src/modules/bluetooth/module-bluez5-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -46,10 +46,10 @@
 #include <pulsecore/time-smoother.h>
 
 #include "a2dp-codecs.h"
-#include "bluez5-util.h"
+#include "bluez-util.h"
 #include "rtp.h"
 
-#include "module-bluez5-device-symdef.h"
+#include "module-bluez-device-symdef.h"
 
 PA_MODULE_AUTHOR("João Paulo Rechi Vita");
 PA_MODULE_DESCRIPTION("BlueZ 5 Bluetooth audio sink and source");
@@ -2240,7 +2240,7 @@ int pa__init(pa_module* m) {
     if ((u->discovery = pa_shared_get(u->core, "bluetooth-discovery")))
         pa_bluetooth_discovery_ref(u->discovery);
     else {
-        pa_log_error("module-bluez5-discover doesn't seem to be loaded, refusing to load module-bluez5-device");
+        pa_log_error("module-bluetooth-discover doesn't seem to be loaded, refusing to load module-bluez-device");
         goto fail_free_modargs;
     }
 
diff --git a/src/modules/bluetooth/module-bluetooth-discover.c b/src/modules/bluetooth/module-bluetooth-discover.c
index b88ab8b..39f5bf0 100644
--- a/src/modules/bluetooth/module-bluetooth-discover.c
+++ b/src/modules/bluetooth/module-bluetooth-discover.c
@@ -1,7 +1,7 @@
 /***
   This file is part of PulseAudio.
 
-  Copyright 2013 João Paulo Rechi Vita
+  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
@@ -21,49 +21,139 @@
 #include <config.h>
 #endif
 
+#include <pulsecore/core.h>
 #include <pulsecore/core-util.h>
 #include <pulsecore/macro.h>
 #include <pulsecore/module.h>
+#include <pulsecore/modargs.h>
+#include <pulsecore/shared.h>
 
-#include "module-bluetooth-discover-symdef.h"
+#include "bluez-util.h"
+
+#include "module-bluez-discover-symdef.h"
 
 PA_MODULE_AUTHOR("João Paulo Rechi Vita");
-PA_MODULE_DESCRIPTION("Detect available Bluetooth daemon and load the corresponding discovery module");
+PA_MODULE_DESCRIPTION("Detect available BlueZ 5 Bluetooth audio devices and load BlueZ 5 Bluetooth audio drivers");
 PA_MODULE_VERSION(PACKAGE_VERSION);
 PA_MODULE_LOAD_ONCE(true);
 PA_MODULE_USAGE(
-    "headset=ofono|native|auto (bluez 5 only)"
-    "autodetect_mtu=<boolean> (bluez 5 only)"
+    "headset=ofono|native|auto"
 );
 
+static const char* const valid_modargs[] = {
+    "headset",
+    "autodetect_mtu",
+    NULL
+};
+
 struct userdata {
-    uint32_t bluez5_module_idx;
+    pa_module *module;
+    pa_core *core;
+    pa_hashmap *loaded_device_paths;
+    pa_hook_slot *device_connection_changed_slot;
+    pa_bluetooth_discovery *discovery;
+    bool autodetect_mtu;
 };
 
-int pa__init(pa_module* m) {
+static pa_hook_result_t device_connection_changed_cb(pa_bluetooth_discovery *y, const pa_bluetooth_device *d, struct userdata *u) {
+    bool module_loaded;
+
+    pa_assert(d);
+    pa_assert(u);
+
+    module_loaded = pa_hashmap_get(u->loaded_device_paths, d->path) ? true : false;
+
+    if (module_loaded && !pa_bluetooth_device_any_transport_connected(d)) {
+        /* disconnection, the module unloads itself */
+        pa_log_debug("Unregistering module for %s", d->path);
+        pa_hashmap_remove(u->loaded_device_paths, d->path);
+        return PA_HOOK_OK;
+    }
+
+    if (!module_loaded && pa_bluetooth_device_any_transport_connected(d)) {
+        /* a new device has been connected */
+        pa_module *m;
+        char *args = pa_sprintf_malloc("path=%s autodetect_mtu=%i", d->path, (int)u->autodetect_mtu);
+
+        pa_log_debug("Loading module-bluetooth-device %s", args);
+        m = pa_module_load(u->module->core, "module-bluetooth-device", args);
+        pa_xfree(args);
+
+        if (m)
+            /* No need to duplicate the path here since the device object will
+             * exist for the whole hashmap entry lifespan */
+            pa_hashmap_put(u->loaded_device_paths, d->path, d->path);
+        else
+            pa_log_warn("Failed to load module for device %s", d->path);
+
+        return PA_HOOK_OK;
+    }
+
+    return PA_HOOK_OK;
+}
+
+#ifdef HAVE_BLUEZ_NATIVE_HEADSET
+const char *default_headset_backend = "auto";
+#else
+const char *default_headset_backend = "ofono";
+#endif
+
+int pa__init(pa_module *m) {
     struct userdata *u;
-    pa_module *mm;
+    pa_modargs *ma;
+    const char *headset_str;
+    int headset_backend;
+    bool autodetect_mtu;
 
     pa_assert(m);
 
-    m->userdata = u = pa_xnew0(struct userdata, 1);
-    u->bluez5_module_idx = PA_INVALID_INDEX;
+    if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
+        pa_log("failed to parse module arguments.");
+        goto fail;
+    }
 
-    if (pa_module_exists("module-bluez5-discover")) {
-        mm = pa_module_load(m->core, "module-bluez5-discover", m->argument);
-        if (mm)
-            u->bluez5_module_idx = mm->index;
+    pa_assert_se(headset_str = pa_modargs_get_value(ma, "headset", default_headset_backend));
+    if (pa_streq(headset_str, "ofono"))
+        headset_backend = HEADSET_BACKEND_OFONO;
+    else if (pa_streq(headset_str, "native"))
+        headset_backend = HEADSET_BACKEND_NATIVE;
+    else if (pa_streq(headset_str, "auto"))
+        headset_backend = HEADSET_BACKEND_AUTO;
+    else {
+        pa_log("headset parameter must be either ofono, native or auto (found %s)", headset_str);
+        goto fail;
     }
 
-    if (u->bluez5_module_idx == PA_INVALID_INDEX) {
-        pa_xfree(u);
-        return -1;
+    autodetect_mtu = true;
+    if (pa_modargs_get_value_boolean(ma, "autodetect_mtu", &autodetect_mtu) < 0) {
+        pa_log("Invalid boolean value for autodetect_mtu parameter");
+        goto fail;
     }
 
+    m->userdata = u = pa_xnew0(struct userdata, 1);
+    u->module = m;
+    u->core = m->core;
+    u->autodetect_mtu = autodetect_mtu;
+    u->loaded_device_paths = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+
+    if (!(u->discovery = pa_bluetooth_discovery_get(u->core, headset_backend)))
+        goto fail;
+
+    u->device_connection_changed_slot =
+        pa_hook_connect(pa_bluetooth_discovery_hook(u->discovery, PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED),
+                        PA_HOOK_NORMAL, (pa_hook_cb_t) device_connection_changed_cb, u);
+
+    pa_modargs_free(ma);
     return 0;
+
+fail:
+    if (ma)
+        pa_modargs_free(ma);
+    pa__done(m);
+    return -1;
 }
 
-void pa__done(pa_module* m) {
+void pa__done(pa_module *m) {
     struct userdata *u;
 
     pa_assert(m);
@@ -71,8 +161,14 @@ void pa__done(pa_module* m) {
     if (!(u = m->userdata))
         return;
 
-    if (u->bluez5_module_idx != PA_INVALID_INDEX)
-        pa_module_unload_by_index(m->core, u->bluez5_module_idx, true);
+    if (u->device_connection_changed_slot)
+        pa_hook_slot_free(u->device_connection_changed_slot);
+
+    if (u->discovery)
+        pa_bluetooth_discovery_unref(u->discovery);
+
+    if (u->loaded_device_paths)
+        pa_hashmap_free(u->loaded_device_paths);
 
     pa_xfree(u);
 }
diff --git a/src/modules/bluetooth/module-bluez5-discover.c b/src/modules/bluetooth/module-bluez5-discover.c
deleted file mode 100644
index 97ff943..0000000
--- a/src/modules/bluetooth/module-bluez5-discover.c
+++ /dev/null
@@ -1,174 +0,0 @@
-/***
-  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, see <http://www.gnu.org/licenses/>.
-***/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <pulsecore/core.h>
-#include <pulsecore/core-util.h>
-#include <pulsecore/macro.h>
-#include <pulsecore/module.h>
-#include <pulsecore/modargs.h>
-#include <pulsecore/shared.h>
-
-#include "bluez5-util.h"
-
-#include "module-bluez5-discover-symdef.h"
-
-PA_MODULE_AUTHOR("João Paulo Rechi Vita");
-PA_MODULE_DESCRIPTION("Detect available BlueZ 5 Bluetooth audio devices and load BlueZ 5 Bluetooth audio drivers");
-PA_MODULE_VERSION(PACKAGE_VERSION);
-PA_MODULE_LOAD_ONCE(true);
-PA_MODULE_USAGE(
-    "headset=ofono|native|auto"
-);
-
-static const char* const valid_modargs[] = {
-    "headset",
-    "autodetect_mtu",
-    NULL
-};
-
-struct userdata {
-    pa_module *module;
-    pa_core *core;
-    pa_hashmap *loaded_device_paths;
-    pa_hook_slot *device_connection_changed_slot;
-    pa_bluetooth_discovery *discovery;
-    bool autodetect_mtu;
-};
-
-static pa_hook_result_t device_connection_changed_cb(pa_bluetooth_discovery *y, const pa_bluetooth_device *d, struct userdata *u) {
-    bool module_loaded;
-
-    pa_assert(d);
-    pa_assert(u);
-
-    module_loaded = pa_hashmap_get(u->loaded_device_paths, d->path) ? true : false;
-
-    if (module_loaded && !pa_bluetooth_device_any_transport_connected(d)) {
-        /* disconnection, the module unloads itself */
-        pa_log_debug("Unregistering module for %s", d->path);
-        pa_hashmap_remove(u->loaded_device_paths, d->path);
-        return PA_HOOK_OK;
-    }
-
-    if (!module_loaded && pa_bluetooth_device_any_transport_connected(d)) {
-        /* a new device has been connected */
-        pa_module *m;
-        char *args = pa_sprintf_malloc("path=%s autodetect_mtu=%i", d->path, (int)u->autodetect_mtu);
-
-        pa_log_debug("Loading module-bluez5-device %s", args);
-        m = pa_module_load(u->module->core, "module-bluez5-device", args);
-        pa_xfree(args);
-
-        if (m)
-            /* No need to duplicate the path here since the device object will
-             * exist for the whole hashmap entry lifespan */
-            pa_hashmap_put(u->loaded_device_paths, d->path, d->path);
-        else
-            pa_log_warn("Failed to load module for device %s", d->path);
-
-        return PA_HOOK_OK;
-    }
-
-    return PA_HOOK_OK;
-}
-
-#ifdef HAVE_BLUEZ_5_NATIVE_HEADSET
-const char *default_headset_backend = "auto";
-#else
-const char *default_headset_backend = "ofono";
-#endif
-
-int pa__init(pa_module *m) {
-    struct userdata *u;
-    pa_modargs *ma;
-    const char *headset_str;
-    int headset_backend;
-    bool autodetect_mtu;
-
-    pa_assert(m);
-
-    if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
-        pa_log("failed to parse module arguments.");
-        goto fail;
-    }
-
-    pa_assert_se(headset_str = pa_modargs_get_value(ma, "headset", default_headset_backend));
-    if (pa_streq(headset_str, "ofono"))
-        headset_backend = HEADSET_BACKEND_OFONO;
-    else if (pa_streq(headset_str, "native"))
-        headset_backend = HEADSET_BACKEND_NATIVE;
-    else if (pa_streq(headset_str, "auto"))
-        headset_backend = HEADSET_BACKEND_AUTO;
-    else {
-        pa_log("headset parameter must be either ofono, native or auto (found %s)", headset_str);
-        goto fail;
-    }
-
-    autodetect_mtu = true;
-    if (pa_modargs_get_value_boolean(ma, "autodetect_mtu", &autodetect_mtu) < 0) {
-        pa_log("Invalid boolean value for autodetect_mtu parameter");
-        goto fail;
-    }
-
-    m->userdata = u = pa_xnew0(struct userdata, 1);
-    u->module = m;
-    u->core = m->core;
-    u->autodetect_mtu = autodetect_mtu;
-    u->loaded_device_paths = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
-
-    if (!(u->discovery = pa_bluetooth_discovery_get(u->core, headset_backend)))
-        goto fail;
-
-    u->device_connection_changed_slot =
-        pa_hook_connect(pa_bluetooth_discovery_hook(u->discovery, PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED),
-                        PA_HOOK_NORMAL, (pa_hook_cb_t) device_connection_changed_cb, u);
-
-    pa_modargs_free(ma);
-    return 0;
-
-fail:
-    if (ma)
-        pa_modargs_free(ma);
-    pa__done(m);
-    return -1;
-}
-
-void pa__done(pa_module *m) {
-    struct userdata *u;
-
-    pa_assert(m);
-
-    if (!(u = m->userdata))
-        return;
-
-    if (u->device_connection_changed_slot)
-        pa_hook_slot_free(u->device_connection_changed_slot);
-
-    if (u->discovery)
-        pa_bluetooth_discovery_unref(u->discovery);
-
-    if (u->loaded_device_paths)
-        pa_hashmap_free(u->loaded_device_paths);
-
-    pa_xfree(u);
-}
-- 
2.9.4



More information about the pulseaudio-discuss mailing list