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 <pulsecore/dbus-shared.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 pa_bt_audio_state_t
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
;
57 return PA_BT_AUDIO_STATE_INVALID
;
60 static pa_bluetooth_uuid
*uuid_new(const char *uuid
) {
63 u
= pa_xnew(pa_bluetooth_uuid
, 1);
64 u
->uuid
= pa_xstrdup(uuid
);
65 PA_LLIST_INIT(pa_bluetooth_uuid
, u
);
70 static void uuid_free(pa_bluetooth_uuid
*u
) {
77 static pa_bluetooth_device
* device_new(const char *path
) {
78 pa_bluetooth_device
*d
;
80 d
= pa_xnew(pa_bluetooth_device
, 1);
84 d
->device_info_valid
= 0;
87 d
->path
= pa_xstrdup(path
);
90 d
->device_connected
= -1;
91 PA_LLIST_HEAD_INIT(pa_bluetooth_uuid
, d
->uuids
);
96 d
->audio_state
= PA_BT_AUDIO_STATE_INVALID
;
97 d
->audio_sink_state
= PA_BT_AUDIO_STATE_INVALID
;
98 d
->headset_state
= PA_BT_AUDIO_STATE_INVALID
;
103 static void device_free(pa_bluetooth_device
*d
) {
104 pa_bluetooth_uuid
*u
;
108 while ((u
= d
->uuids
)) {
109 PA_LLIST_REMOVE(pa_bluetooth_uuid
, d
->uuids
, u
);
116 pa_xfree(d
->address
);
120 static pa_bool_t
device_is_audio(pa_bluetooth_device
*d
) {
124 d
->device_info_valid
&&
125 (d
->audio_state
!= PA_BT_AUDIO_STATE_INVALID
||
126 d
->audio_sink_state
!= PA_BT_AUDIO_STATE_INVALID
||
127 d
->headset_state
!= PA_BT_AUDIO_STATE_INVALID
);
130 static int parse_device_property(pa_bluetooth_discovery
*y
, pa_bluetooth_device
*d
, DBusMessageIter
*i
) {
132 DBusMessageIter variant_i
;
138 if (dbus_message_iter_get_arg_type(i
) != DBUS_TYPE_STRING
) {
139 pa_log("Property name not a string.");
143 dbus_message_iter_get_basic(i
, &key
);
145 if (!dbus_message_iter_next(i
)) {
146 pa_log("Property value missing");
150 if (dbus_message_iter_get_arg_type(i
) != DBUS_TYPE_VARIANT
) {
151 pa_log("Property value not a variant.");
155 dbus_message_iter_recurse(i
, &variant_i
);
157 /* pa_log_debug("Parsing property org.bluez.Device.%s", key); */
159 switch (dbus_message_iter_get_arg_type(&variant_i
)) {
161 case DBUS_TYPE_STRING
: {
164 dbus_message_iter_get_basic(&variant_i
, &value
);
166 if (pa_streq(key
, "Name")) {
168 d
->name
= pa_xstrdup(value
);
169 } else if (pa_streq(key
, "Alias")) {
171 d
->alias
= pa_xstrdup(value
);
172 } else if (pa_streq(key
, "Address")) {
173 pa_xfree(d
->address
);
174 d
->address
= pa_xstrdup(value
);
177 /* pa_log_debug("Value %s", value); */
182 case DBUS_TYPE_BOOLEAN
: {
185 dbus_message_iter_get_basic(&variant_i
, &value
);
187 if (pa_streq(key
, "Paired"))
189 else if (pa_streq(key
, "Connected"))
190 d
->device_connected
= !!value
;
191 else if (pa_streq(key
, "Trusted"))
192 d
->trusted
= !!value
;
194 /* pa_log_debug("Value %s", pa_yes_no(value)); */
199 case DBUS_TYPE_UINT32
: {
202 dbus_message_iter_get_basic(&variant_i
, &value
);
204 if (pa_streq(key
, "Class"))
205 d
->class = (int) value
;
207 /* pa_log_debug("Value %u", (unsigned) value); */
212 case DBUS_TYPE_ARRAY
: {
215 dbus_message_iter_recurse(&variant_i
, &ai
);
217 if (dbus_message_iter_get_arg_type(&ai
) == DBUS_TYPE_STRING
&&
218 pa_streq(key
, "UUIDs")) {
220 while (dbus_message_iter_get_arg_type(&ai
) != DBUS_TYPE_INVALID
) {
221 pa_bluetooth_uuid
*node
;
225 dbus_message_iter_get_basic(&ai
, &value
);
226 node
= uuid_new(value
);
227 PA_LLIST_PREPEND(pa_bluetooth_uuid
, d
->uuids
, node
);
229 /* 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 */
230 pa_assert_se(m
= dbus_message_new_method_call("org.bluez", d
->path
, "org.bluez.Audio", "GetProperties"));
231 send_and_add_to_pending(y
, d
, m
, get_properties_reply
);
233 /* Vudentz said the interfaces are here when the UUIDs are announced */
234 if (strcasecmp(HSP_HS_UUID
, value
) == 0 || strcasecmp(HFP_HS_UUID
, value
) == 0) {
235 pa_assert_se(m
= dbus_message_new_method_call("org.bluez", d
->path
, "org.bluez.Headset", "GetProperties"));
236 send_and_add_to_pending(y
, d
, m
, get_properties_reply
);
237 } else if (strcasecmp(A2DP_SINK_UUID
, value
) == 0) {
238 pa_assert_se(m
= dbus_message_new_method_call("org.bluez", d
->path
, "org.bluez.AudioSink", "GetProperties"));
239 send_and_add_to_pending(y
, d
, m
, get_properties_reply
);
242 if (!dbus_message_iter_next(&ai
))
254 static int parse_audio_property(pa_bluetooth_discovery
*u
, int *state
, DBusMessageIter
*i
) {
256 DBusMessageIter variant_i
;
262 if (dbus_message_iter_get_arg_type(i
) != DBUS_TYPE_STRING
) {
263 pa_log("Property name not a string.");
267 dbus_message_iter_get_basic(i
, &key
);
269 if (!dbus_message_iter_next(i
)) {
270 pa_log("Property value missing");
274 if (dbus_message_iter_get_arg_type(i
) != DBUS_TYPE_VARIANT
) {
275 pa_log("Property value not a variant.");
279 dbus_message_iter_recurse(i
, &variant_i
);
281 /* pa_log_debug("Parsing property org.bluez.{Audio|AudioSink|Headset}.%s", key); */
283 switch (dbus_message_iter_get_arg_type(&variant_i
)) {
285 case DBUS_TYPE_STRING
: {
288 dbus_message_iter_get_basic(&variant_i
, &value
);
290 if (pa_streq(key
, "State"))
291 *state
= pa_bt_audio_state_from_string(value
);
292 /* pa_log_debug("Value %s", value); */
295 case DBUS_TYPE_BOOLEAN
: {
298 dbus_message_iter_get_basic(&variant_i
, &value
);
300 /* if (pa_streq(key, "Connected")) */
301 /* *connected = !!value; */
303 /* pa_log_debug("Value %s", pa_yes_no(value)); */
312 static void run_callback(pa_bluetooth_discovery
*y
, pa_bluetooth_device
*d
, pa_bool_t dead
) {
316 if (!device_is_audio(d
))
320 pa_hook_fire(&y
->hook
, d
);
323 static void get_properties_reply(DBusPendingCall
*pending
, void *userdata
) {
325 DBusMessageIter arg_i
, element_i
;
327 pa_bluetooth_device
*d
;
328 pa_bluetooth_discovery
*y
;
331 pa_assert_se(p
= userdata
);
332 pa_assert_se(y
= p
->context_data
);
333 pa_assert_se(r
= dbus_pending_call_steal_reply(pending
));
335 /* pa_log_debug("Got %s.GetProperties response for %s", */
336 /* dbus_message_get_interface(p->message), */
337 /* dbus_message_get_path(p->message)); */
341 valid
= dbus_message_get_type(r
) == DBUS_MESSAGE_TYPE_ERROR
? -1 : 1;
343 if (dbus_message_is_method_call(p
->message
, "org.bluez.Device", "GetProperties"))
344 d
->device_info_valid
= valid
;
346 if (dbus_message_get_type(r
) == DBUS_MESSAGE_TYPE_ERROR
) {
348 if (!dbus_message_is_error(r
, DBUS_ERROR_UNKNOWN_METHOD
))
349 pa_log("Error from GetProperties reply: %s", dbus_message_get_error_name(r
));
354 if (!dbus_message_iter_init(r
, &arg_i
)) {
355 pa_log("GetProperties reply has no arguments.");
359 if (dbus_message_iter_get_arg_type(&arg_i
) != DBUS_TYPE_ARRAY
) {
360 pa_log("GetProperties argument is not an array.");
364 dbus_message_iter_recurse(&arg_i
, &element_i
);
365 while (dbus_message_iter_get_arg_type(&element_i
) != DBUS_TYPE_INVALID
) {
367 if (dbus_message_iter_get_arg_type(&element_i
) == DBUS_TYPE_DICT_ENTRY
) {
368 DBusMessageIter dict_i
;
370 dbus_message_iter_recurse(&element_i
, &dict_i
);
372 if (dbus_message_has_interface(p
->message
, "org.bluez.Device")) {
373 if (parse_device_property(y
, d
, &dict_i
) < 0)
376 } else if (dbus_message_has_interface(p
->message
, "org.bluez.Audio")) {
377 if (parse_audio_property(y
, &d
->audio_state
, &dict_i
) < 0)
380 } else if (dbus_message_has_interface(p
->message
, "org.bluez.Headset")) {
381 if (parse_audio_property(y
, &d
->headset_state
, &dict_i
) < 0)
384 } else if (dbus_message_has_interface(p
->message
, "org.bluez.AudioSink")) {
385 if (parse_audio_property(y
, &d
->audio_sink_state
, &dict_i
) < 0)
390 if (!dbus_message_iter_next(&element_i
))
395 run_callback(y
, d
, FALSE
);
397 dbus_message_unref(r
);
399 PA_LLIST_REMOVE(pa_dbus_pending
, y
->pending
, p
);
400 pa_dbus_pending_free(p
);
403 static pa_dbus_pending
* send_and_add_to_pending(pa_bluetooth_discovery
*y
, pa_bluetooth_device
*d
, DBusMessage
*m
, DBusPendingCallNotifyFunction func
) {
405 DBusPendingCall
*call
;
410 pa_assert_se(dbus_connection_send_with_reply(pa_dbus_connection_get(y
->connection
), m
, &call
, -1));
412 p
= pa_dbus_pending_new(pa_dbus_connection_get(y
->connection
), m
, call
, y
, d
);
413 PA_LLIST_PREPEND(pa_dbus_pending
, y
->pending
, p
);
414 dbus_pending_call_set_notify(call
, func
, p
, NULL
);
419 static void found_device(pa_bluetooth_discovery
*y
, const char* path
) {
421 pa_bluetooth_device
*d
;
426 d
= device_new(path
);
428 pa_hashmap_put(y
->devices
, d
->path
, d
);
430 pa_assert_se(m
= dbus_message_new_method_call("org.bluez", path
, "org.bluez.Device", "GetProperties"));
431 send_and_add_to_pending(y
, d
, m
, get_properties_reply
);
434 static void list_devices_reply(DBusPendingCall
*pending
, void *userdata
) {
440 pa_bluetooth_discovery
*y
;
446 pa_assert_se(p
= userdata
);
447 pa_assert_se(y
= p
->context_data
);
448 pa_assert_se(r
= dbus_pending_call_steal_reply(pending
));
450 if (dbus_message_get_type(r
) == DBUS_MESSAGE_TYPE_ERROR
) {
451 pa_log("Error from ListDevices reply: %s", dbus_message_get_error_name(r
));
455 if (!dbus_message_get_args(r
, &e
, DBUS_TYPE_ARRAY
, DBUS_TYPE_OBJECT_PATH
, &paths
, &num
, DBUS_TYPE_INVALID
)) {
456 pa_log("org.bluez.Adapter.ListDevices returned an error: '%s'\n", e
.message
);
461 for (i
= 0; i
< num
; ++i
)
462 found_device(y
, paths
[i
]);
467 dbus_free_string_array (paths
);
469 dbus_message_unref(r
);
471 PA_LLIST_REMOVE(pa_dbus_pending
, y
->pending
, p
);
472 pa_dbus_pending_free(p
);
475 static void found_adapter(pa_bluetooth_discovery
*y
, const char *path
) {
478 pa_assert_se(m
= dbus_message_new_method_call("org.bluez", path
, "org.bluez.Adapter", "ListDevices"));
479 send_and_add_to_pending(y
, NULL
, m
, list_devices_reply
);
482 static void list_adapters_reply(DBusPendingCall
*pending
, void *userdata
) {
488 pa_bluetooth_discovery
*y
;
494 pa_assert_se(p
= userdata
);
495 pa_assert_se(y
= p
->context_data
);
496 pa_assert_se(r
= dbus_pending_call_steal_reply(pending
));
498 if (dbus_message_get_type(r
) == DBUS_MESSAGE_TYPE_ERROR
) {
499 pa_log("Error from ListAdapters reply: %s", dbus_message_get_error_name(r
));
503 if (!dbus_message_get_args(r
, &e
, DBUS_TYPE_ARRAY
, DBUS_TYPE_OBJECT_PATH
, &paths
, &num
, DBUS_TYPE_INVALID
)) {
504 pa_log("org.bluez.Manager.ListAdapters returned an error: %s", e
.message
);
509 for (i
= 0; i
< num
; ++i
)
510 found_adapter(y
, paths
[i
]);
515 dbus_free_string_array (paths
);
517 dbus_message_unref(r
);
519 PA_LLIST_REMOVE(pa_dbus_pending
, y
->pending
, p
);
520 pa_dbus_pending_free(p
);
523 static void list_adapters(pa_bluetooth_discovery
*y
) {
527 pa_assert_se(m
= dbus_message_new_method_call("org.bluez", "/", "org.bluez.Manager", "ListAdapters"));
528 send_and_add_to_pending(y
, NULL
, m
, list_adapters_reply
);
531 static DBusHandlerResult
filter_cb(DBusConnection
*bus
, DBusMessage
*m
, void *userdata
) {
533 pa_bluetooth_discovery
*y
;
538 pa_assert_se(y
= userdata
);
540 dbus_error_init(&err
);
542 pa_log_debug("dbus: interface=%s, path=%s, member=%s\n",
543 dbus_message_get_interface(m
),
544 dbus_message_get_path(m
),
545 dbus_message_get_member(m
));
547 if (dbus_message_is_signal(m
, "org.bluez.Adapter", "DeviceRemoved")) {
549 pa_bluetooth_device
*d
;
551 if (!dbus_message_get_args(m
, &err
, DBUS_TYPE_OBJECT_PATH
, &path
, DBUS_TYPE_INVALID
)) {
552 pa_log("Failed to parse org.bluez.Adapter.DeviceRemoved: %s", err
.message
);
556 pa_log_debug("Device %s removed", path
);
558 if ((d
= pa_hashmap_remove(y
->devices
, path
))) {
559 run_callback(y
, d
, TRUE
);
563 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
565 } else if (dbus_message_is_signal(m
, "org.bluez.Adapter", "DeviceCreated")) {
568 if (!dbus_message_get_args(m
, &err
, DBUS_TYPE_OBJECT_PATH
, &path
, DBUS_TYPE_INVALID
)) {
569 pa_log("Failed to parse org.bluez.Adapter.DeviceCreated: %s", err
.message
);
573 pa_log_debug("Device %s created", path
);
575 found_device(y
, path
);
576 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
578 } else if (dbus_message_is_signal(m
, "org.bluez.Manager", "AdapterAdded")) {
581 if (!dbus_message_get_args(m
, &err
, DBUS_TYPE_OBJECT_PATH
, &path
, DBUS_TYPE_INVALID
)) {
582 pa_log("Failed to parse org.bluez.Manager.AdapterAdded: %s", err
.message
);
586 pa_log_debug("Adapter %s created", path
);
588 found_adapter(y
, path
);
589 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
591 } else if (dbus_message_is_signal(m
, "org.bluez.Audio", "PropertyChanged") ||
592 dbus_message_is_signal(m
, "org.bluez.Headset", "PropertyChanged") ||
593 dbus_message_is_signal(m
, "org.bluez.AudioSink", "PropertyChanged") ||
594 dbus_message_is_signal(m
, "org.bluez.Device", "PropertyChanged")) {
596 pa_bluetooth_device
*d
;
598 if ((d
= pa_hashmap_get(y
->devices
, dbus_message_get_path(m
)))) {
599 DBusMessageIter arg_i
;
601 if (!dbus_message_iter_init(m
, &arg_i
)) {
602 pa_log("Failed to parse PropertyChanged: %s", err
.message
);
606 if (dbus_message_has_interface(m
, "org.bluez.Device")) {
607 if (parse_device_property(y
, d
, &arg_i
) < 0)
610 } else if (dbus_message_has_interface(m
, "org.bluez.Audio")) {
611 if (parse_audio_property(y
, &d
->audio_state
, &arg_i
) < 0)
614 } else if (dbus_message_has_interface(m
, "org.bluez.Headset")) {
615 if (parse_audio_property(y
, &d
->headset_state
, &arg_i
) < 0)
618 } else if (dbus_message_has_interface(m
, "org.bluez.AudioSink")) {
619 if (parse_audio_property(y
, &d
->audio_sink_state
, &arg_i
) < 0)
623 run_callback(y
, d
, FALSE
);
626 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
630 dbus_error_free(&err
);
632 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
635 const pa_bluetooth_device
* pa_bluetooth_discovery_get_by_address(pa_bluetooth_discovery
*y
, const char* address
) {
636 pa_bluetooth_device
*d
;
640 pa_assert(PA_REFCNT_VALUE(y
) > 0);
643 if (!pa_hook_is_firing(&y
->hook
))
644 pa_bluetooth_discovery_sync(y
);
646 while ((d
= pa_hashmap_iterate(y
->devices
, &state
, NULL
)))
647 if (pa_streq(d
->address
, address
))
653 const pa_bluetooth_device
* pa_bluetooth_discovery_get_by_path(pa_bluetooth_discovery
*y
, const char* path
) {
655 pa_assert(PA_REFCNT_VALUE(y
) > 0);
658 if (!pa_hook_is_firing(&y
->hook
))
659 pa_bluetooth_discovery_sync(y
);
661 return pa_hashmap_get(y
->devices
, path
);
664 static int setup_dbus(pa_bluetooth_discovery
*y
) {
667 dbus_error_init(&err
);
669 y
->connection
= pa_dbus_bus_get(y
->core
, DBUS_BUS_SYSTEM
, &err
);
671 if (dbus_error_is_set(&err
) || !y
->connection
) {
672 pa_log("Failed to get D-Bus connection: %s", err
.message
);
673 dbus_error_free(&err
);
680 pa_bluetooth_discovery
* pa_bluetooth_discovery_get(pa_core
*c
) {
682 pa_bluetooth_discovery
*y
;
686 dbus_error_init(&err
);
688 if ((y
= pa_shared_get(c
, "bluetooth-discovery")))
689 return pa_bluetooth_discovery_ref(y
);
691 y
= pa_xnew0(pa_bluetooth_discovery
, 1);
694 y
->devices
= pa_hashmap_new(pa_idxset_string_hash_func
, pa_idxset_string_compare_func
);
695 PA_LLIST_HEAD_INIT(pa_dbus_pending
, y
->pending
);
696 pa_hook_init(&y
->hook
, y
);
697 pa_shared_set(c
, "bluetooth-discovery", y
);
699 if (setup_dbus(y
) < 0)
702 /* dynamic detection of bluetooth audio devices */
703 if (!dbus_connection_add_filter(pa_dbus_connection_get(y
->connection
), filter_cb
, y
, NULL
)) {
704 pa_log_error("Failed to add filter function");
708 if (pa_dbus_add_matches(
709 pa_dbus_connection_get(y
->connection
), &err
,
710 "type='signal',sender='org.bluez',interface='org.bluez.Manager',member='AdapterAdded'",
711 "type='signal',sender='org.bluez',interface='org.bluez.Adapter',member='DeviceRemoved'",
712 "type='signal',sender='org.bluez',interface='org.bluez.Adapter',member='DeviceCreated'",
713 "type='signal',sender='org.bluez',interface='org.bluez.Device',member='PropertyChanged'",
714 "type='signal',sender='org.bluez',interface='org.bluez.Audio',member='PropertyChanged'",
715 "type='signal',sender='org.bluez',interface='org.bluez.Headset',member='PropertyChanged'",
716 "type='signal',sender='org.bluez',interface='org.bluez.AudioSink',member='PropertyChanged'", NULL
) < 0) {
717 pa_log("Failed to add D-Bus matches: %s", err
.message
);
728 pa_bluetooth_discovery_unref(y
);
730 dbus_error_free(&err
);
735 pa_bluetooth_discovery
* pa_bluetooth_discovery_ref(pa_bluetooth_discovery
*y
) {
737 pa_assert(PA_REFCNT_VALUE(y
) > 0);
744 void pa_bluetooth_discovery_unref(pa_bluetooth_discovery
*y
) {
745 pa_bluetooth_device
*d
;
748 pa_assert(PA_REFCNT_VALUE(y
) > 0);
750 if (PA_REFCNT_DEC(y
) > 0)
753 pa_dbus_free_pending_list(&y
->pending
);
756 while ((d
= pa_hashmap_steal_first(y
->devices
))) {
757 run_callback(y
, d
, TRUE
);
761 pa_hashmap_free(y
->devices
, NULL
, NULL
);
765 pa_dbus_remove_matches(pa_dbus_connection_get(y
->connection
),
766 "type='signal',sender='org.bluez',interface='org.bluez.Manager',member='AdapterAdded'",
767 "type='signal',sender='org.bluez',interface='org.bluez.Manager',member='AdapterRemoved'",
768 "type='signal',sender='org.bluez',interface='org.bluez.Adapter',member='DeviceRemoved'",
769 "type='signal',sender='org.bluez',interface='org.bluez.Adapter',member='DeviceCreated'",
770 "type='signal',sender='org.bluez',interface='org.bluez.Device',member='PropertyChanged'",
771 "type='signal',sender='org.bluez',interface='org.bluez.Audio',member='PropertyChanged'",
772 "type='signal',sender='org.bluez',interface='org.bluez.Headset',member='PropertyChanged'",
773 "type='signal',sender='org.bluez',interface='org.bluez.AudioSink',member='PropertyChanged'", NULL
);
775 dbus_connection_remove_filter(pa_dbus_connection_get(y
->connection
), filter_cb
, y
);
777 pa_dbus_connection_unref(y
->connection
);
780 pa_hook_done(&y
->hook
);
783 pa_shared_remove(y
->core
, "bluetooth-discovery");
786 void pa_bluetooth_discovery_sync(pa_bluetooth_discovery
*y
) {
788 pa_assert(PA_REFCNT_VALUE(y
) > 0);
790 pa_dbus_sync_pending_list(&y
->pending
);
793 pa_hook
* pa_bluetooth_discovery_hook(pa_bluetooth_discovery
*y
) {
795 pa_assert(PA_REFCNT_VALUE(y
) > 0);
800 const char*pa_bluetooth_get_form_factor(uint32_t class) {
804 static const char * const table
[] = {
815 if (((class >> 8) & 31) != 4)
818 if ((i
= (class >> 2) & 63) > PA_ELEMENTSOF(table
))
824 pa_log_debug("Unknown Bluetooth minor device class %u", i
);
829 char *pa_bluetooth_cleanup_name(const char *name
) {
831 pa_bool_t space
= FALSE
;
835 while ((*name
>= 1 && *name
<= 32) || *name
>= 127)
838 t
= pa_xstrdup(name
);
840 for (s
= d
= t
; *s
; s
++) {
842 if (*s
<= 32 || *s
>= 127 || *s
== '_') {
860 pa_bool_t
pa_bluetooth_uuid_has(pa_bluetooth_uuid
*uuids
, const char *uuid
) {
864 if (strcasecmp(uuids
->uuid
, uuid
) == 0)