2 This file is part of PulseAudio.
4 Copyright 2008 Joao Paulo Rechi Vita
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.
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.
16 You should have received a copy of the GNU Lesser General Public
17 License along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 #include <pulsecore/core-util.h>
27 #include <pulsecore/shared.h>
28 #include <modules/dbus-util.h>
30 #include "bluetooth-util.h"
32 struct pa_bluetooth_discovery
{
36 pa_dbus_connection
*connection
;
37 PA_LLIST_HEAD(pa_dbus_pending
, pending
);
42 static void get_properties_reply(DBusPendingCall
*pending
, void *userdata
);
43 static pa_dbus_pending
* send_and_add_to_pending(pa_bluetooth_discovery
*y
, pa_bluetooth_device
*d
, DBusMessage
*m
, DBusPendingCallNotifyFunction func
);
45 static enum pa_bt_audio_state
pa_bt_audio_state_from_string(const char* value
) {
48 if (pa_streq(value
, "disconnected")) {
49 return PA_BT_AUDIO_STATE_DISCONNECTED
;
50 } else if (pa_streq(value
, "connecting")) {
51 return PA_BT_AUDIO_STATE_CONNECTING
;
52 } else if (pa_streq(value
, "connected")) {
53 return PA_BT_AUDIO_STATE_CONNECTED
;
54 } else if (pa_streq(value
, "playing")) {
55 return PA_BT_AUDIO_STATE_PLAYING
;
58 return PA_BT_AUDIO_STATE_INVALID
;
61 static pa_bluetooth_uuid
*uuid_new(const char *uuid
) {
64 u
= pa_xnew(pa_bluetooth_uuid
, 1);
65 u
->uuid
= pa_xstrdup(uuid
);
66 PA_LLIST_INIT(pa_bluetooth_uuid
, u
);
71 static void uuid_free(pa_bluetooth_uuid
*u
) {
78 static pa_bluetooth_device
* device_new(const char *path
) {
79 pa_bluetooth_device
*d
;
81 d
= pa_xnew(pa_bluetooth_device
, 1);
85 d
->device_info_valid
= 0;
88 d
->path
= pa_xstrdup(path
);
91 d
->device_connected
= -1;
92 PA_LLIST_HEAD_INIT(pa_bluetooth_uuid
, d
->uuids
);
97 d
->audio_state
= PA_BT_AUDIO_STATE_INVALID
;
98 d
->audio_sink_state
= PA_BT_AUDIO_STATE_INVALID
;
99 d
->headset_state
= PA_BT_AUDIO_STATE_INVALID
;
104 static void device_free(pa_bluetooth_device
*d
) {
105 pa_bluetooth_uuid
*u
;
109 while ((u
= d
->uuids
)) {
110 PA_LLIST_REMOVE(pa_bluetooth_uuid
, d
->uuids
, u
);
117 pa_xfree(d
->address
);
121 static pa_bool_t
device_is_audio(pa_bluetooth_device
*d
) {
125 d
->device_info_valid
&&
126 (d
->audio_state
!= PA_BT_AUDIO_STATE_INVALID
||
127 d
->audio_sink_state
!= PA_BT_AUDIO_STATE_INVALID
||
128 d
->headset_state
!= PA_BT_AUDIO_STATE_INVALID
);
131 static int parse_device_property(pa_bluetooth_discovery
*y
, pa_bluetooth_device
*d
, DBusMessageIter
*i
) {
133 DBusMessageIter variant_i
;
139 if (dbus_message_iter_get_arg_type(i
) != DBUS_TYPE_STRING
) {
140 pa_log("Property name not a string.");
144 dbus_message_iter_get_basic(i
, &key
);
146 if (!dbus_message_iter_next(i
)) {
147 pa_log("Property value missing");
151 if (dbus_message_iter_get_arg_type(i
) != DBUS_TYPE_VARIANT
) {
152 pa_log("Property value not a variant.");
156 dbus_message_iter_recurse(i
, &variant_i
);
158 /* pa_log_debug("Parsing property org.bluez.Device.%s", key); */
160 switch (dbus_message_iter_get_arg_type(&variant_i
)) {
162 case DBUS_TYPE_STRING
: {
165 dbus_message_iter_get_basic(&variant_i
, &value
);
167 if (pa_streq(key
, "Name")) {
169 d
->name
= pa_xstrdup(value
);
170 } else if (pa_streq(key
, "Alias")) {
172 d
->alias
= pa_xstrdup(value
);
173 } else if (pa_streq(key
, "Address")) {
174 pa_xfree(d
->address
);
175 d
->address
= pa_xstrdup(value
);
178 /* pa_log_debug("Value %s", value); */
183 case DBUS_TYPE_BOOLEAN
: {
186 dbus_message_iter_get_basic(&variant_i
, &value
);
188 if (pa_streq(key
, "Paired"))
190 else if (pa_streq(key
, "Connected"))
191 d
->device_connected
= !!value
;
192 else if (pa_streq(key
, "Trusted"))
193 d
->trusted
= !!value
;
195 /* pa_log_debug("Value %s", pa_yes_no(value)); */
200 case DBUS_TYPE_UINT32
: {
203 dbus_message_iter_get_basic(&variant_i
, &value
);
205 if (pa_streq(key
, "Class"))
206 d
->class = (int) value
;
208 /* pa_log_debug("Value %u", (unsigned) value); */
213 case DBUS_TYPE_ARRAY
: {
216 dbus_message_iter_recurse(&variant_i
, &ai
);
218 if (dbus_message_iter_get_arg_type(&ai
) == DBUS_TYPE_STRING
&&
219 pa_streq(key
, "UUIDs")) {
221 while (dbus_message_iter_get_arg_type(&ai
) != DBUS_TYPE_INVALID
) {
222 pa_bluetooth_uuid
*node
;
226 dbus_message_iter_get_basic(&ai
, &value
);
227 node
= uuid_new(value
);
228 PA_LLIST_PREPEND(pa_bluetooth_uuid
, d
->uuids
, node
);
230 /* this might eventually be racy if .Audio is not there yet, but the State change will come anyway later, so this call is for cold-detection mostly */
231 pa_assert_se(m
= dbus_message_new_method_call("org.bluez", d
->path
, "org.bluez.Audio", "GetProperties"));
232 send_and_add_to_pending(y
, d
, m
, get_properties_reply
);
234 /* Vudentz said the interfaces are here when the UUIDs are announced */
235 if (strcasecmp(HSP_HS_UUID
, value
) == 0 || strcasecmp(HFP_HS_UUID
, value
) == 0) {
236 pa_assert_se(m
= dbus_message_new_method_call("org.bluez", d
->path
, "org.bluez.Headset", "GetProperties"));
237 send_and_add_to_pending(y
, d
, m
, get_properties_reply
);
238 } else if (strcasecmp(A2DP_SINK_UUID
, value
) == 0) {
239 pa_assert_se(m
= dbus_message_new_method_call("org.bluez", d
->path
, "org.bluez.AudioSink", "GetProperties"));
240 send_and_add_to_pending(y
, d
, m
, get_properties_reply
);
243 if (!dbus_message_iter_next(&ai
))
255 static int parse_audio_property(pa_bluetooth_discovery
*u
, int *state
, DBusMessageIter
*i
) {
257 DBusMessageIter variant_i
;
263 if (dbus_message_iter_get_arg_type(i
) != DBUS_TYPE_STRING
) {
264 pa_log("Property name not a string.");
268 dbus_message_iter_get_basic(i
, &key
);
270 if (!dbus_message_iter_next(i
)) {
271 pa_log("Property value missing");
275 if (dbus_message_iter_get_arg_type(i
) != DBUS_TYPE_VARIANT
) {
276 pa_log("Property value not a variant.");
280 dbus_message_iter_recurse(i
, &variant_i
);
282 /* pa_log_debug("Parsing property org.bluez.{Audio|AudioSink|Headset}.%s", key); */
284 switch (dbus_message_iter_get_arg_type(&variant_i
)) {
286 case DBUS_TYPE_STRING
: {
289 dbus_message_iter_get_basic(&variant_i
, &value
);
291 if (pa_streq(key
, "State"))
292 *state
= pa_bt_audio_state_from_string(value
);
293 /* pa_log_debug("Value %s", value); */
296 case DBUS_TYPE_BOOLEAN
: {
299 dbus_message_iter_get_basic(&variant_i
, &value
);
301 /* if (pa_streq(key, "Connected")) */
302 /* *connected = !!value; */
304 /* pa_log_debug("Value %s", pa_yes_no(value)); */
313 static void run_callback(pa_bluetooth_discovery
*y
, pa_bluetooth_device
*d
, pa_bool_t dead
) {
317 if (!device_is_audio(d
))
321 pa_hook_fire(&y
->hook
, d
);
324 static void get_properties_reply(DBusPendingCall
*pending
, void *userdata
) {
326 DBusMessageIter arg_i
, element_i
;
328 pa_bluetooth_device
*d
;
329 pa_bluetooth_discovery
*y
;
332 pa_assert_se(p
= userdata
);
333 pa_assert_se(y
= p
->context_data
);
334 pa_assert_se(r
= dbus_pending_call_steal_reply(pending
));
336 /* pa_log_debug("Got %s.GetProperties response for %s", */
337 /* dbus_message_get_interface(p->message), */
338 /* dbus_message_get_path(p->message)); */
342 valid
= dbus_message_get_type(r
) == DBUS_MESSAGE_TYPE_ERROR
? -1 : 1;
344 if (dbus_message_is_method_call(p
->message
, "org.bluez.Device", "GetProperties"))
345 d
->device_info_valid
= valid
;
347 if (dbus_message_get_type(r
) == DBUS_MESSAGE_TYPE_ERROR
) {
349 if (!dbus_message_is_error(r
, DBUS_ERROR_UNKNOWN_METHOD
))
350 pa_log("Error from GetProperties reply: %s", dbus_message_get_error_name(r
));
355 if (!dbus_message_iter_init(r
, &arg_i
)) {
356 pa_log("GetProperties reply has no arguments.");
360 if (dbus_message_iter_get_arg_type(&arg_i
) != DBUS_TYPE_ARRAY
) {
361 pa_log("GetProperties argument is not an array.");
365 dbus_message_iter_recurse(&arg_i
, &element_i
);
366 while (dbus_message_iter_get_arg_type(&element_i
) != DBUS_TYPE_INVALID
) {
368 if (dbus_message_iter_get_arg_type(&element_i
) == DBUS_TYPE_DICT_ENTRY
) {
369 DBusMessageIter dict_i
;
371 dbus_message_iter_recurse(&element_i
, &dict_i
);
373 if (dbus_message_has_interface(p
->message
, "org.bluez.Device")) {
374 if (parse_device_property(y
, d
, &dict_i
) < 0)
377 } else if (dbus_message_has_interface(p
->message
, "org.bluez.Audio")) {
378 if (parse_audio_property(y
, &d
->audio_state
, &dict_i
) < 0)
381 } else if (dbus_message_has_interface(p
->message
, "org.bluez.Headset")) {
382 if (parse_audio_property(y
, &d
->headset_state
, &dict_i
) < 0)
385 } else if (dbus_message_has_interface(p
->message
, "org.bluez.AudioSink")) {
386 if (parse_audio_property(y
, &d
->audio_sink_state
, &dict_i
) < 0)
391 if (!dbus_message_iter_next(&element_i
))
396 run_callback(y
, d
, FALSE
);
398 dbus_message_unref(r
);
400 PA_LLIST_REMOVE(pa_dbus_pending
, y
->pending
, p
);
401 pa_dbus_pending_free(p
);
404 static pa_dbus_pending
* send_and_add_to_pending(pa_bluetooth_discovery
*y
, pa_bluetooth_device
*d
, DBusMessage
*m
, DBusPendingCallNotifyFunction func
) {
406 DBusPendingCall
*call
;
411 pa_assert_se(dbus_connection_send_with_reply(pa_dbus_connection_get(y
->connection
), m
, &call
, -1));
413 p
= pa_dbus_pending_new(pa_dbus_connection_get(y
->connection
), m
, call
, y
, d
);
414 PA_LLIST_PREPEND(pa_dbus_pending
, y
->pending
, p
);
415 dbus_pending_call_set_notify(call
, func
, p
, NULL
);
420 static void found_device(pa_bluetooth_discovery
*y
, const char* path
) {
422 pa_bluetooth_device
*d
;
427 d
= device_new(path
);
429 pa_hashmap_put(y
->devices
, d
->path
, d
);
431 pa_assert_se(m
= dbus_message_new_method_call("org.bluez", path
, "org.bluez.Device", "GetProperties"));
432 send_and_add_to_pending(y
, d
, m
, get_properties_reply
);
435 static void list_devices_reply(DBusPendingCall
*pending
, void *userdata
) {
441 pa_bluetooth_discovery
*y
;
447 pa_assert_se(p
= userdata
);
448 pa_assert_se(y
= p
->context_data
);
449 pa_assert_se(r
= dbus_pending_call_steal_reply(pending
));
451 if (dbus_message_get_type(r
) == DBUS_MESSAGE_TYPE_ERROR
) {
452 pa_log("Error from ListDevices reply: %s", dbus_message_get_error_name(r
));
456 if (!dbus_message_get_args(r
, &e
, DBUS_TYPE_ARRAY
, DBUS_TYPE_OBJECT_PATH
, &paths
, &num
, DBUS_TYPE_INVALID
)) {
457 pa_log("org.bluez.Adapter.ListDevices returned an error: '%s'\n", e
.message
);
462 for (i
= 0; i
< num
; ++i
)
463 found_device(y
, paths
[i
]);
468 dbus_free_string_array (paths
);
470 dbus_message_unref(r
);
472 PA_LLIST_REMOVE(pa_dbus_pending
, y
->pending
, p
);
473 pa_dbus_pending_free(p
);
476 static void found_adapter(pa_bluetooth_discovery
*y
, const char *path
) {
479 pa_assert_se(m
= dbus_message_new_method_call("org.bluez", path
, "org.bluez.Adapter", "ListDevices"));
480 send_and_add_to_pending(y
, NULL
, m
, list_devices_reply
);
483 static void list_adapters_reply(DBusPendingCall
*pending
, void *userdata
) {
489 pa_bluetooth_discovery
*y
;
495 pa_assert_se(p
= userdata
);
496 pa_assert_se(y
= p
->context_data
);
497 pa_assert_se(r
= dbus_pending_call_steal_reply(pending
));
499 if (dbus_message_get_type(r
) == DBUS_MESSAGE_TYPE_ERROR
) {
500 pa_log("Error from ListAdapters reply: %s", dbus_message_get_error_name(r
));
504 if (!dbus_message_get_args(r
, &e
, DBUS_TYPE_ARRAY
, DBUS_TYPE_OBJECT_PATH
, &paths
, &num
, DBUS_TYPE_INVALID
)) {
505 pa_log("org.bluez.Manager.ListAdapters returned an error: %s", e
.message
);
510 for (i
= 0; i
< num
; ++i
)
511 found_adapter(y
, paths
[i
]);
516 dbus_free_string_array (paths
);
518 dbus_message_unref(r
);
520 PA_LLIST_REMOVE(pa_dbus_pending
, y
->pending
, p
);
521 pa_dbus_pending_free(p
);
524 static void list_adapters(pa_bluetooth_discovery
*y
) {
528 pa_assert_se(m
= dbus_message_new_method_call("org.bluez", "/", "org.bluez.Manager", "ListAdapters"));
529 send_and_add_to_pending(y
, NULL
, m
, list_adapters_reply
);
532 static DBusHandlerResult
filter_cb(DBusConnection
*bus
, DBusMessage
*m
, void *userdata
) {
534 pa_bluetooth_discovery
*y
;
539 pa_assert_se(y
= userdata
);
541 dbus_error_init(&err
);
543 pa_log_debug("dbus: interface=%s, path=%s, member=%s\n",
544 dbus_message_get_interface(m
),
545 dbus_message_get_path(m
),
546 dbus_message_get_member(m
));
548 if (dbus_message_is_signal(m
, "org.bluez.Adapter", "DeviceRemoved")) {
550 pa_bluetooth_device
*d
;
552 if (!dbus_message_get_args(m
, &err
, DBUS_TYPE_OBJECT_PATH
, &path
, DBUS_TYPE_INVALID
)) {
553 pa_log("Failed to parse org.bluez.Adapter.DeviceRemoved: %s", err
.message
);
557 pa_log_debug("Device %s removed", path
);
559 if ((d
= pa_hashmap_remove(y
->devices
, path
))) {
560 run_callback(y
, d
, TRUE
);
564 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
566 } else if (dbus_message_is_signal(m
, "org.bluez.Adapter", "DeviceCreated")) {
569 if (!dbus_message_get_args(m
, &err
, DBUS_TYPE_OBJECT_PATH
, &path
, DBUS_TYPE_INVALID
)) {
570 pa_log("Failed to parse org.bluez.Adapter.DeviceCreated: %s", err
.message
);
574 pa_log_debug("Device %s created", path
);
576 found_device(y
, path
);
577 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
579 } else if (dbus_message_is_signal(m
, "org.bluez.Manager", "AdapterAdded")) {
582 if (!dbus_message_get_args(m
, &err
, DBUS_TYPE_OBJECT_PATH
, &path
, DBUS_TYPE_INVALID
)) {
583 pa_log("Failed to parse org.bluez.Manager.AdapterAdded: %s", err
.message
);
587 pa_log_debug("Adapter %s created", path
);
589 found_adapter(y
, path
);
590 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
592 } else if (dbus_message_is_signal(m
, "org.bluez.Audio", "PropertyChanged") ||
593 dbus_message_is_signal(m
, "org.bluez.Headset", "PropertyChanged") ||
594 dbus_message_is_signal(m
, "org.bluez.AudioSink", "PropertyChanged") ||
595 dbus_message_is_signal(m
, "org.bluez.Device", "PropertyChanged")) {
597 pa_bluetooth_device
*d
;
599 if ((d
= pa_hashmap_get(y
->devices
, dbus_message_get_path(m
)))) {
600 DBusMessageIter arg_i
;
602 if (!dbus_message_iter_init(m
, &arg_i
)) {
603 pa_log("Failed to parse PropertyChanged: %s", err
.message
);
607 if (dbus_message_has_interface(m
, "org.bluez.Device")) {
608 if (parse_device_property(y
, d
, &arg_i
) < 0)
611 } else if (dbus_message_has_interface(m
, "org.bluez.Audio")) {
612 if (parse_audio_property(y
, &d
->audio_state
, &arg_i
) < 0)
615 } else if (dbus_message_has_interface(m
, "org.bluez.Headset")) {
616 if (parse_audio_property(y
, &d
->headset_state
, &arg_i
) < 0)
619 } else if (dbus_message_has_interface(m
, "org.bluez.AudioSink")) {
620 if (parse_audio_property(y
, &d
->audio_sink_state
, &arg_i
) < 0)
624 run_callback(y
, d
, FALSE
);
627 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
631 dbus_error_free(&err
);
633 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
636 const pa_bluetooth_device
* pa_bluetooth_discovery_get_by_address(pa_bluetooth_discovery
*y
, const char* address
) {
637 pa_bluetooth_device
*d
;
641 pa_assert(PA_REFCNT_VALUE(y
) > 0);
644 if (!pa_hook_is_firing(&y
->hook
))
645 pa_bluetooth_discovery_sync(y
);
647 while ((d
= pa_hashmap_iterate(y
->devices
, &state
, NULL
)))
648 if (pa_streq(d
->address
, address
))
654 const pa_bluetooth_device
* pa_bluetooth_discovery_get_by_path(pa_bluetooth_discovery
*y
, const char* path
) {
656 pa_assert(PA_REFCNT_VALUE(y
) > 0);
659 if (!pa_hook_is_firing(&y
->hook
))
660 pa_bluetooth_discovery_sync(y
);
662 return pa_hashmap_get(y
->devices
, path
);
665 static int setup_dbus(pa_bluetooth_discovery
*y
) {
668 dbus_error_init(&err
);
670 y
->connection
= pa_dbus_bus_get(y
->core
, DBUS_BUS_SYSTEM
, &err
);
672 if (dbus_error_is_set(&err
) || !y
->connection
) {
673 pa_log("Failed to get D-Bus connection: %s", err
.message
);
674 dbus_error_free(&err
);
681 pa_bluetooth_discovery
* pa_bluetooth_discovery_get(pa_core
*c
) {
683 pa_bluetooth_discovery
*y
;
687 dbus_error_init(&err
);
689 if ((y
= pa_shared_get(c
, "bluetooth-discovery")))
690 return pa_bluetooth_discovery_ref(y
);
692 y
= pa_xnew0(pa_bluetooth_discovery
, 1);
695 y
->devices
= pa_hashmap_new(pa_idxset_string_hash_func
, pa_idxset_string_compare_func
);
696 PA_LLIST_HEAD_INIT(pa_dbus_pending
, y
->pending
);
697 pa_hook_init(&y
->hook
, y
);
698 pa_shared_set(c
, "bluetooth-discovery", y
);
700 if (setup_dbus(y
) < 0)
703 /* dynamic detection of bluetooth audio devices */
704 if (!dbus_connection_add_filter(pa_dbus_connection_get(y
->connection
), filter_cb
, y
, NULL
)) {
705 pa_log_error("Failed to add filter function");
709 if (pa_dbus_add_matches(
710 pa_dbus_connection_get(y
->connection
), &err
,
711 "type='signal',sender='org.bluez',interface='org.bluez.Manager',member='AdapterAdded'",
712 "type='signal',sender='org.bluez',interface='org.bluez.Adapter',member='DeviceRemoved'",
713 "type='signal',sender='org.bluez',interface='org.bluez.Adapter',member='DeviceCreated'",
714 "type='signal',sender='org.bluez',interface='org.bluez.Device',member='PropertyChanged'",
715 "type='signal',sender='org.bluez',interface='org.bluez.Audio',member='PropertyChanged'",
716 "type='signal',sender='org.bluez',interface='org.bluez.Headset',member='PropertyChanged'",
717 "type='signal',sender='org.bluez',interface='org.bluez.AudioSink',member='PropertyChanged'", NULL
) < 0) {
718 pa_log("Failed to add D-Bus matches: %s", err
.message
);
729 pa_bluetooth_discovery_unref(y
);
731 dbus_error_free(&err
);
736 pa_bluetooth_discovery
* pa_bluetooth_discovery_ref(pa_bluetooth_discovery
*y
) {
738 pa_assert(PA_REFCNT_VALUE(y
) > 0);
745 void pa_bluetooth_discovery_unref(pa_bluetooth_discovery
*y
) {
746 pa_bluetooth_device
*d
;
749 pa_assert(PA_REFCNT_VALUE(y
) > 0);
751 if (PA_REFCNT_DEC(y
) > 0)
754 pa_dbus_free_pending_list(&y
->pending
);
757 while ((d
= pa_hashmap_steal_first(y
->devices
))) {
758 run_callback(y
, d
, TRUE
);
762 pa_hashmap_free(y
->devices
, NULL
, NULL
);
766 pa_dbus_remove_matches(pa_dbus_connection_get(y
->connection
),
767 "type='signal',sender='org.bluez',interface='org.bluez.Manager',member='AdapterAdded'",
768 "type='signal',sender='org.bluez',interface='org.bluez.Manager',member='AdapterRemoved'",
769 "type='signal',sender='org.bluez',interface='org.bluez.Adapter',member='DeviceRemoved'",
770 "type='signal',sender='org.bluez',interface='org.bluez.Adapter',member='DeviceCreated'",
771 "type='signal',sender='org.bluez',interface='org.bluez.Device',member='PropertyChanged'",
772 "type='signal',sender='org.bluez',interface='org.bluez.Audio',member='PropertyChanged'",
773 "type='signal',sender='org.bluez',interface='org.bluez.Headset',member='PropertyChanged'",
774 "type='signal',sender='org.bluez',interface='org.bluez.AudioSink',member='PropertyChanged'", NULL
);
776 dbus_connection_remove_filter(pa_dbus_connection_get(y
->connection
), filter_cb
, y
);
778 pa_dbus_connection_unref(y
->connection
);
781 pa_hook_done(&y
->hook
);
784 pa_shared_remove(y
->core
, "bluetooth-discovery");
787 void pa_bluetooth_discovery_sync(pa_bluetooth_discovery
*y
) {
789 pa_assert(PA_REFCNT_VALUE(y
) > 0);
791 pa_dbus_sync_pending_list(&y
->pending
);
794 pa_hook
* pa_bluetooth_discovery_hook(pa_bluetooth_discovery
*y
) {
796 pa_assert(PA_REFCNT_VALUE(y
) > 0);
801 const char*pa_bluetooth_get_form_factor(uint32_t class) {
805 static const char * const table
[] = {
816 if (((class >> 8) & 31) != 4)
819 if ((i
= (class >> 2) & 63) > PA_ELEMENTSOF(table
))
825 pa_log_debug("Unknown Bluetooth minor device class %u", i
);
830 char *pa_bluetooth_cleanup_name(const char *name
) {
832 pa_bool_t space
= FALSE
;
836 while ((*name
>= 1 && *name
<= 32) || *name
>= 127)
839 t
= pa_xstrdup(name
);
841 for (s
= d
= t
; *s
; s
++) {
843 if (*s
<= 32 || *s
>= 127 || *s
== '_') {
861 pa_bool_t
pa_bluetooth_uuid_has(pa_bluetooth_uuid
*uuids
, const char *uuid
) {
865 if (strcasecmp(uuids
->uuid
, uuid
) == 0)