1/***
2  This file is part of PulseAudio.
3
4  Copyright 2013 João Paulo Rechi Vita
5
6  PulseAudio is free software; you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as
8  published by the Free Software Foundation; either version 2.1 of the
9  License, or (at your option) any later version.
10
11  PulseAudio is distributed in the hope that it will be useful, but
12  WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  General Public License for more details.
15
16  You should have received a copy of the GNU Lesser General Public
17  License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
18***/
19
20#ifdef HAVE_CONFIG_H
21#include <config.h>
22#endif
23
24#include <pulsecore/core-util.h>
25#include <pulsecore/macro.h>
26#include <pulsecore/module.h>
27
28PA_MODULE_AUTHOR("João Paulo Rechi Vita");
29PA_MODULE_DESCRIPTION("Detect available Bluetooth daemon and load the corresponding discovery module");
30PA_MODULE_VERSION(PACKAGE_VERSION);
31PA_MODULE_LOAD_ONCE(true);
32PA_MODULE_USAGE(
33    "headset=ofono|native|auto"
34    "autodetect_mtu=<boolean>"
35);
36
37struct userdata {
38    uint32_t bluez5_module_idx;
39};
40
41int pa__init(pa_module* m) {
42    struct userdata *u;
43    pa_module *mm;
44
45    pa_assert(m);
46
47    m->userdata = u = pa_xnew0(struct userdata, 1);
48    u->bluez5_module_idx = PA_INVALID_INDEX;
49
50    if (pa_module_exists("module-bluez5-discover")) {
51        pa_module_load(&mm, m->core, "module-bluez5-discover", m->argument);
52        if (mm)
53            u->bluez5_module_idx = mm->index;
54    }
55
56    if (u->bluez5_module_idx == PA_INVALID_INDEX) {
57        pa_xfree(u);
58        return -1;
59    }
60
61    return 0;
62}
63
64void pa__done(pa_module* m) {
65    struct userdata *u;
66
67    pa_assert(m);
68
69    if (!(u = m->userdata))
70        return;
71
72    if (u->bluez5_module_idx != PA_INVALID_INDEX)
73        pa_module_unload_by_index(m->core, u->bluez5_module_idx, true);
74
75    pa_xfree(u);
76}
77