2 This file is part of PulseAudio.
4 Copyright 2008-2013 João Paulo Rechi Vita
5 Copyright 2011-2013 BMW Car IT GmbH.
7 PulseAudio is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as
9 published by the Free Software Foundation; either version 2.1 of the
10 License, or (at your option) any later version.
12 PulseAudio is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with PulseAudio; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27 #include <pulsecore/module.h>
28 #include <pulsecore/modargs.h>
30 #include "bluez5-util.h"
32 #include "module-bluez5-device-symdef.h"
34 PA_MODULE_AUTHOR("João Paulo Rechi Vita");
35 PA_MODULE_DESCRIPTION("BlueZ 5 Bluetooth audio sink and source");
36 PA_MODULE_VERSION(PACKAGE_VERSION
);
37 PA_MODULE_LOAD_ONCE(false);
38 PA_MODULE_USAGE("path=<device object path>");
40 static const char* const valid_modargs
[] = {
49 pa_hook_slot
*device_connection_changed_slot
;
51 pa_bluetooth_discovery
*discovery
;
52 pa_bluetooth_device
*device
;
55 /* Run from main thread */
56 static pa_hook_result_t
device_connection_changed_cb(pa_bluetooth_discovery
*y
, const pa_bluetooth_device
*d
, struct userdata
*u
) {
60 if (d
!= u
->device
|| pa_bluetooth_device_any_transport_connected(d
))
63 pa_log_debug("Unloading module for device %s", d
->path
);
64 pa_module_unload(u
->core
, u
->module
, true);
69 int pa__init(pa_module
* m
) {
76 m
->userdata
= u
= pa_xnew0(struct userdata
, 1);
80 if (!(ma
= pa_modargs_new(m
->argument
, valid_modargs
))) {
81 pa_log_error("Failed to parse module arguments");
85 if (!(path
= pa_modargs_get_value(ma
, "path", NULL
))) {
86 pa_log_error("Failed to get device path from module arguments");
90 if (!(u
->discovery
= pa_bluetooth_discovery_get(m
->core
)))
93 if (!(u
->device
= pa_bluetooth_discovery_get_device_by_path(u
->discovery
, path
))) {
94 pa_log_error("%s is unknown", path
);
100 u
->device_connection_changed_slot
=
101 pa_hook_connect(pa_bluetooth_discovery_hook(u
->discovery
, PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED
),
102 PA_HOOK_NORMAL
, (pa_hook_cb_t
) device_connection_changed_cb
, u
);
116 void pa__done(pa_module
*m
) {
121 if (!(u
= m
->userdata
))
124 if (u
->device_connection_changed_slot
)
125 pa_hook_slot_free(u
->device_connection_changed_slot
);
128 pa_bluetooth_discovery_unref(u
->discovery
);