[pulseaudio-discuss] [PATCH v4 14/41] bluetooth: Parse BlueZ 5 D-Bus interfaces

João Paulo Rechi Vita jprvita at gmail.com
Sat Sep 21 14:30:43 PDT 2013


On Sat, Sep 21, 2013 at 8:15 AM, Tanu Kaskinen
<tanu.kaskinen at linux.intel.com> wrote:
> On Sat, 2013-09-21 at 14:02 +0300, Tanu Kaskinen wrote:
>> On Wed, 2013-09-18 at 16:17 -0500, jprvita at gmail.com wrote:
>> > From: João Paulo Rechi Vita <jprvita at openbossa.org>
>> >
>> > Parse the arguments of the InterfacesAdded signal and the
>> > GetManagedObjects() reply.
>> >
>> > This code is based on previous work by Mikel Astiz.
>> > ---
>> >  src/modules/bluetooth/bluez5-util.c | 72 +++++++++++++++++++++++++++++++++++--
>> >  1 file changed, 70 insertions(+), 2 deletions(-)
>> >
>> > diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c
>> > index bf4a046..7f0a7ec 100644
>> > --- a/src/modules/bluetooth/bluez5-util.c
>> > +++ b/src/modules/bluetooth/bluez5-util.c
>> > @@ -38,6 +38,7 @@
>> >  #include "bluez5-util.h"
>> >
>> >  #define BLUEZ_SERVICE "org.bluez"
>> > +#define BLUEZ_ADAPTER_INTERFACE BLUEZ_SERVICE ".Adapter1"
>> >  #define BLUEZ_DEVICE_INTERFACE BLUEZ_SERVICE ".Device1"
>> >  #define BLUEZ_MEDIA_ENDPOINT_INTERFACE BLUEZ_SERVICE ".MediaEndpoint1"
>> >  #define BLUEZ_MEDIA_TRANSPORT_INTERFACE BLUEZ_SERVICE ".MediaTransport1"
>> > @@ -379,6 +380,73 @@ static void adapter_remove_all(pa_bluetooth_discovery *y) {
>> >      }
>> >  }
>> >
>> > +static void parse_interfaces_and_properties(pa_bluetooth_discovery *y, DBusMessageIter *dict_i) {
>> > +    DBusMessageIter element_i;
>> > +    const char *path;
>> > +
>> > +    pa_assert(dbus_message_iter_get_arg_type(dict_i) == DBUS_TYPE_OBJECT_PATH);
>> > +    dbus_message_iter_get_basic(dict_i, &path);
>> > +
>> > +    pa_assert_se(dbus_message_iter_next(dict_i));
>> > +    pa_assert(dbus_message_iter_get_arg_type(dict_i) == DBUS_TYPE_ARRAY);
>> > +
>> > +    dbus_message_iter_recurse(dict_i, &element_i);
>> > +
>> > +    while (dbus_message_iter_get_arg_type(&element_i) == DBUS_TYPE_DICT_ENTRY) {
>> > +        DBusMessageIter iface_i;
>> > +        const char *interface;
>> > +
>> > +        dbus_message_iter_recurse(&element_i, &iface_i);
>> > +
>> > +        pa_assert(dbus_message_iter_get_arg_type(&iface_i) == DBUS_TYPE_STRING);
>> > +        dbus_message_iter_get_basic(&iface_i, &interface);
>> > +
>> > +        pa_assert_se(dbus_message_iter_next(&iface_i));
>> > +        pa_assert(dbus_message_iter_get_arg_type(&iface_i) == DBUS_TYPE_ARRAY);
>> > +
>> > +        if (pa_streq(interface, BLUEZ_ADAPTER_INTERFACE)) {
>> > +            pa_bluetooth_adapter *a;
>> > +
>> > +            if ((a = pa_hashmap_get(y->adapters, path))) {
>> > +                pa_log_error("Found duplicated D-Bus path for device %s", path);
>> > +                return;
>> > +            } else
>> > +                a = adapter_create(y, path);
>> > +
>> > +            pa_log_debug("Adapter %s found", path);
>> > +
>> > +            /* TODO: parse adapter properties and register endpoints */
>> > +
>> > +        } 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 == 1) {
>> > +                    pa_log_error("Found duplicated D-Bus path for device %s", path);
>> > +                    return;
>> > +                }
>> > +
>> > +                if (d->device_info_valid == -1) {
>> > +                    pa_log_notice("Device %s was known before but had invalid information, reseting", path);
>> > +                    d->device_info_valid = 0;
>>
>> Didn't we agree that the device shouldn't be reset? If the device is
>> reset, the device properties should be reset too, otherwise the old
>> property values can leak to the new initialization. But as discussed
>> last round, resetting the property values is error prone, so if the
>> device initialization fails once, then the device should stay
>> uninitialized forever. We don't need to resurrect failed devices.
>
> Never mind, I see you fixed this in a later patch (it would have been
> good to fix it already in this patch, but no big deal).
>

I must have screwed something during a rebase, sorry. My idea was to
fix this on the same patch. I'll get this organized for v5.

-- 
João Paulo Rechi Vita
http://about.me/jprvita


More information about the pulseaudio-discuss mailing list