]> code.delx.au - pulseaudio/blob - src/modules/bluetooth/module-bluez5-device.c
bluetooth: Get BlueZ 5 device object
[pulseaudio] / src / modules / bluetooth / module-bluez5-device.c
1 /***
2 This file is part of PulseAudio.
3
4 Copyright 2008-2013 João Paulo Rechi Vita
5 Copyright 2011-2013 BMW Car IT GmbH.
6
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.
11
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.
16
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
20 USA.
21 ***/
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <pulsecore/module.h>
28 #include <pulsecore/modargs.h>
29
30 #include "bluez5-util.h"
31
32 #include "module-bluez5-device-symdef.h"
33
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>");
39
40 static const char* const valid_modargs[] = {
41 "path",
42 NULL
43 };
44
45 struct userdata {
46 pa_module *module;
47 pa_core *core;
48
49 pa_bluetooth_discovery *discovery;
50 pa_bluetooth_device *device;
51 };
52
53 int pa__init(pa_module* m) {
54 struct userdata *u;
55 const char *path;
56 pa_modargs *ma;
57
58 pa_assert(m);
59
60 m->userdata = u = pa_xnew0(struct userdata, 1);
61 u->module = m;
62 u->core = m->core;
63
64 if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
65 pa_log_error("Failed to parse module arguments");
66 goto fail;
67 }
68
69 if (!(path = pa_modargs_get_value(ma, "path", NULL))) {
70 pa_log_error("Failed to get device path from module arguments");
71 goto fail;
72 }
73
74 if (!(u->discovery = pa_bluetooth_discovery_get(m->core)))
75 goto fail;
76
77 if (!(u->device = pa_bluetooth_discovery_get_device_by_path(u->discovery, path))) {
78 pa_log_error("%s is unknown", path);
79 goto fail;
80 }
81
82 pa_modargs_free(ma);
83
84 return 0;
85
86 fail:
87
88 if (ma)
89 pa_modargs_free(ma);
90
91 pa__done(m);
92
93 return -1;
94 }
95
96 void pa__done(pa_module *m) {
97 struct userdata *u;
98
99 pa_assert(m);
100
101 if (!(u = m->userdata))
102 return;
103
104 if (u->discovery)
105 pa_bluetooth_discovery_unref(u->discovery);
106
107 pa_xfree(u);
108 }