[PATCH v4 4/4] bluetooth: Rename *bluez5 modules to bluetooth

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

 



On Mon, 2018-03-26 at 17:15 +0300, Luiz Augusto von Dentz wrote:
> 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 +++++----
>  po/POTFILES.in                                     |   2 +-
>  po/be.po                                           |  42 +++---
>  po/de.po                                           |  42 +++---
>  po/el.po                                           |  38 ++---
>  po/fr.po                                           |  42 +++---
>  po/hr.po                                           |  42 +++---
>  po/hu.po                                           |  43 +++---
>  po/id.po                                           |  42 +++---
>  po/it.po                                           |  42 +++---
>  po/lt.po                                           |  42 +++---
>  po/nn.po                                           |  42 +++---
>  po/oc.po                                           |  42 +++---
>  po/pl.po                                           |  42 +++---
>  po/pt_BR.po                                        |  42 +++---
>  po/ru.po                                           |  38 ++---
>  po/sk.po                                           |  42 +++---
>  po/sv.po                                           |  42 +++---
>  po/tr.po                                           |  42 +++---
>  po/uk.po                                           |  42 +++---
>  po/zh_CN.po                                        |  42 +++---
>  po/zh_TW.po                                        |  42 +++---
>  src/Makefile.am                                    |  58 ++++----
>  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} |   8 +-
>  src/modules/bluetooth/module-bluetooth-discover.c  | 134 ++++++++++++++---
>  src/modules/bluetooth/module-bluez5-discover.c     | 158 ++++-----------------
>  30 files changed, 634 insertions(+), 649 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%)
> 
> diff --git a/configure.ac b/configure.ac
> index c2e883731..3dd6129c3 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -1043,46 +1043,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)]))

The "(Bluez 5)" part can be dropped.

> +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]))

"5" can be dropped.

> +
> +AC_ARG_ENABLE([bluez-native-headset],
> +    AS_HELP_STRING([--disable-bluez-native-headset],[Disable optional native headset backend support (Bluez 5)]))

"(Bluez 5)" can be dropped.

> +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]))

"5" can be dropped.

> -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) -DPA_MODULE_NAME=module_bluez5_device
> +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)

-DPA_MODULE_NAME=module_bluetooth_device is missing from CFLAGS.

> --- a/src/modules/bluetooth/module-bluez5-device.c
> +++ b/src/modules/bluetooth/module-bluetooth-device.c
> @@ -46,11 +46,13 @@
>  #include <pulsecore/time-smoother.h>
>  
>  #include "a2dp-codecs.h"
> -#include "bluez5-util.h"
> +#include "bluez-util.h"
>  #include "rtp.h"
>  
> +#include "module-bluetooth-device-symdef.h"

That file doesn't exist (this line isn't needed any more). You're
expected to do build testing before you submit patches, by the way...

> +
>  PA_MODULE_AUTHOR("João Paulo Rechi Vita");
> -PA_MODULE_DESCRIPTION("BlueZ 5 Bluetooth audio sink and source");
> +PA_MODULE_DESCRIPTION("Bluetooth audio sink and source");
>  PA_MODULE_VERSION(PACKAGE_VERSION);
>  PA_MODULE_LOAD_ONCE(false);
>  PA_MODULE_USAGE("path=<device object path>"
> @@ -2283,7 +2285,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 63195d3e1..0641467bc 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,47 +21,137 @@
>  #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 "bluez-util.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 Bluetooth audio devices and 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"

autodetect_mtu shouldn't be dropped from the usage string.

>  );
>  
> +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);
> +        pa_module_load(&m, 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")) {
> -        pa_module_load(&mm, 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;

This was set to false previously.

> +    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);
> @@ -69,8 +159,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
> index 44578214c..bc553a897 100644
> --- a/src/modules/bluetooth/module-bluez5-discover.c
> +++ b/src/modules/bluetooth/module-bluez5-discover.c
> @@ -4,169 +4,63 @@
>    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.
> +  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/>.
> +  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 <pulse/xmalloc.h>
>  
> -#include "bluez5-util.h"
> +#include <pulsecore/module.h>
> +#include <pulsecore/log.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_DESCRIPTION("Compatibility module (module-bluez5-discover rename)");
>  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
> -};
> +PA_MODULE_LOAD_ONCE(false);

This should be set to true.

> +PA_MODULE_DEPRECATED("Please use module-bluetooth-discover instead of module-bluez5-discover!");
>  
>  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;
> +    uint32_t module_index;
>  };
>  
> -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);
> -        pa_module_load(&m, 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) {
> +int pa__init(pa_module*m) {
>      struct userdata *u;
> -    pa_modargs *ma;
> -    const char *headset_str;
> -    int headset_backend;
> -    bool autodetect_mtu;
> +    pa_module *module;
>  
>      pa_assert(m);
> +    pa_assert_se(m->userdata = u = pa_xnew0(struct userdata, 1));
> +
> +    pa_log_warn("We will now load module-bluetooth-discover. Please make sure to remove module-bluez5-discover from your configuration.");
> +
> +    pa_module_load(&module, m->core, "module-bluetooth-discover", m->argument);
> +    u->module_index = module ? module->index : PA_INVALID_INDEX;
>  
> -    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 = false;
> -    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;
> +    return module ? 0 : -1;

If we return -1, then pa__done() won't be called, and u->userdata will
not get freed, so we have to free the userdata before returning -1.

>  }
>  
> -void pa__done(pa_module *m) {
> +void pa__done(pa_module*m) {
>      struct userdata *u;
>  
>      pa_assert(m);
> +    pa_assert(m->userdata);
>  
> -    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);
> +    u = m->userdata;
>  
> -    if (u->loaded_device_paths)
> -        pa_hashmap_free(u->loaded_device_paths);
> +    if (u && PA_INVALID_INDEX != u->module_index)
> +        pa_module_unload_by_index(m->core, u->module_index, true);

This if check is unnecessary. u is never null and the module index is
never invalid.

-- 
Tanu

https://liberapay.com/tanuk
https://www.patreon.com/tanuk


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

  Powered by Linux