From: Jo?o Paulo Rechi Vita <jprvita@xxxxxxxxxxxxx> --- src/modules/bluetooth/bluez5-util.c | 18 +++++++++++++++++- src/modules/bluetooth/bluez5-util.h | 5 +++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c index 485471f..8f682c6 100644 --- a/src/modules/bluetooth/bluez5-util.c +++ b/src/modules/bluetooth/bluez5-util.c @@ -471,6 +471,12 @@ static int parse_device_property(pa_bluetooth_device *d, DBusMessageIter *i, boo } d->adapter = pa_hashmap_get(d->discovery->adapters, value); + if (!d->adapter) { + pa_log_warn("Device %s: 'Adapter' property references an unknown adapter %s.", d->path, value); + d->_adapter_path = pa_xstrdup(value); + break; + } + pa_log_debug("%s: %s", key, value); } @@ -663,6 +669,8 @@ static void register_endpoint(pa_bluetooth_discovery *y, const char *path, const static void parse_interfaces_and_properties(pa_bluetooth_discovery *y, DBusMessageIter *dict_i) { DBusMessageIter element_i; const char *path; + void *state = NULL; + pa_bluetooth_device *d; pa_assert(dbus_message_iter_get_arg_type(dict_i) == DBUS_TYPE_OBJECT_PATH); dbus_message_iter_get_basic(dict_i, &path); @@ -701,7 +709,6 @@ static void parse_interfaces_and_properties(pa_bluetooth_discovery *y, DBusMessa register_endpoint(y, path, A2DP_SINK_ENDPOINT, PA_BLUETOOTH_UUID_A2DP_SINK); } else if (pa_streq(interface, BLUEZ_DEVICE_INTERFACE)) { - pa_bluetooth_device *d; if ((d = pa_hashmap_get(y->devices, path))) { if (d->device_info_valid != 0) { @@ -721,6 +728,15 @@ static void parse_interfaces_and_properties(pa_bluetooth_discovery *y, DBusMessa dbus_message_iter_next(&element_i); } + while ((d = pa_hashmap_iterate(y->devices, &state, NULL))) + if (!d->adapter && d->_adapter_path) { + d->adapter = pa_hashmap_get(d->discovery->adapters, d->_adapter_path); + pa_xfree(d->_adapter_path); + d->_adapter_path = NULL; + if (d->adapter && d->address && d->alias) + d->device_info_valid = 1; + } + return; } diff --git a/src/modules/bluetooth/bluez5-util.h b/src/modules/bluetooth/bluez5-util.h index 41673e3..c0adfb3 100644 --- a/src/modules/bluetooth/bluez5-util.h +++ b/src/modules/bluetooth/bluez5-util.h @@ -76,6 +76,11 @@ struct pa_bluetooth_device { pa_bluetooth_discovery *discovery; pa_bluetooth_adapter *adapter; + /* Do no use this field: _adapter_path is only used temporarily when the + * device information arrives before the adapter information so it's + * possible to update adapter pointer at a later moment */ + char *_adapter_path; + int device_info_valid; /* 0: no results yet; 1: good results; -1: bad results ... */ /* Device information */ -- 1.8.3.1