bluetooth: Keep a list of local adapters' UUIDs

This commit stores the UUID list when an adapter is discovered and
updates it whenever a PropertiesChanged signal notifies it has changed.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/593>
This commit is contained in:
João Paulo Rechi Vita 2018-09-11 12:10:12 -07:00 committed by Igor Kovalenko
parent a246bb77c7
commit 4b55b8a9d0
2 changed files with 26 additions and 0 deletions

View file

@ -1441,6 +1441,7 @@ static pa_bluetooth_adapter* adapter_create(pa_bluetooth_discovery *y, const cha
a = pa_xnew0(pa_bluetooth_adapter, 1);
a->discovery = y;
a->path = pa_xstrdup(path);
a->uuids = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, pa_xfree);
pa_hashmap_put(y->adapters, a->path, a);
@ -1643,6 +1644,30 @@ static void parse_adapter_properties(pa_bluetooth_adapter *a, DBusMessageIter *i
dbus_message_iter_get_basic(&variant_i, &value);
a->address = pa_xstrdup(value);
a->valid = true;
} else if (dbus_message_iter_get_arg_type(&variant_i) == DBUS_TYPE_ARRAY) {
DBusMessageIter ai;
dbus_message_iter_recurse(&variant_i, &ai);
if (dbus_message_iter_get_arg_type(&ai) == DBUS_TYPE_STRING && pa_streq(key, "UUIDs")) {
pa_hashmap_remove_all(a->uuids);
while (dbus_message_iter_get_arg_type(&ai) != DBUS_TYPE_INVALID) {
const char *value;
char *uuid;
dbus_message_iter_get_basic(&ai, &value);
if (pa_hashmap_get(a->uuids, value)) {
dbus_message_iter_next(&ai);
continue;
}
uuid = pa_xstrdup(value);
pa_hashmap_put(a->uuids, uuid, uuid);
pa_log_debug("%s: %s", key, value);
dbus_message_iter_next(&ai);
}
}
}
dbus_message_iter_next(&element_i);

View file

@ -163,6 +163,7 @@ struct pa_bluetooth_adapter {
pa_bluetooth_discovery *discovery;
char *path;
char *address;
pa_hashmap *uuids; /* char* -> char* (hashmap-as-a-set) */
bool valid;
bool application_registered;