[pulseaudio-discuss] [RFC v0 04/15] bluetooth: Support ObjectManager interface add/remove

Tanu Kaskinen tanuk at iki.fi
Sun Dec 30 06:18:19 PST 2012


On Wed, 2012-12-19 at 13:58 +0100, Mikel Astiz wrote:
> From: Mikel Astiz <mikel.astiz at bmw-carit.de>
> 
> Install matches for signals ObjectManager.InterfacesAdded and
> ObjectManager.InterfacesRemoved, and process the devices that are
> registered and unregistered dynamically.
> ---
>  src/modules/bluetooth/bluetooth-util.c | 60 ++++++++++++++++++++++++++++++++++
>  1 file changed, 60 insertions(+)
> 
> diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
> index e8f8756..d0b06b0 100644
> --- a/src/modules/bluetooth/bluetooth-util.c
> +++ b/src/modules/bluetooth/bluetooth-util.c
> @@ -1189,6 +1189,62 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us
>              goto fail;
>  
>          return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
> +    } else if (dbus_message_is_signal(m, "org.freedesktop.DBus.ObjectManager", "InterfacesAdded")) {
> +        DBusMessageIter arg_i;
> +
> +        if (y->version != BLUEZ_VERSION_5)
> +            return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; /* No reply received yet from GetManagedObjects */
> +
> +        if (!dbus_message_iter_init(m, &arg_i)) {

Check the signature of the message first, then you can use
pa_assert_se(dbus_message_iter_init()).

> +            pa_log("Failed to parse InterfacesAdded: %s", err.message);

err.message won't contain anything useful. The same mistake seems to be
also with other dbus_message_iter_init() calls in this function (also in
the old code).

> +            goto fail;
> +        }
> +
> +        if (parse_interfaces_and_properties(y, &arg_i) < 0)
> +            goto fail;
> +
> +        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
> +    } else if (dbus_message_is_signal(m, "org.freedesktop.DBus.ObjectManager", "InterfacesRemoved")) {
> +        const char *path;
> +        DBusMessageIter arg_i;
> +        DBusMessageIter element_i;
> +
> +        if (y->version != BLUEZ_VERSION_5)
> +            return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; /* No reply received yet from GetManagedObjects */
> +
> +        if (!dbus_message_iter_init(m, &arg_i) || dbus_message_iter_get_arg_type(&arg_i) != DBUS_TYPE_OBJECT_PATH) {
> +            pa_log("Failed to parse InterfacesRemoved: %s", err.message);
> +            goto fail;
> +        }

Check the message signature here too.

> +
> +        dbus_message_iter_get_basic(&arg_i, &path);
> +
> +        if (!dbus_message_iter_next(&arg_i) || dbus_message_iter_get_arg_type(&arg_i) != DBUS_TYPE_ARRAY) {
> +            pa_log("D-Bus interfaces missing in InterfacesRemoved for object %s", path);
> +            goto fail;
> +        }
> +
> +        dbus_message_iter_recurse(&arg_i, &element_i);
> +
> +        while (dbus_message_iter_get_arg_type(&element_i) == DBUS_TYPE_STRING) {
> +            const char *interface;
> +
> +            dbus_message_iter_get_basic(&element_i, &interface);
> +
> +            if (pa_streq(interface, "org.bluez.Device1")) {
> +                pa_bluetooth_device *d;
> +
> +                if ((d = pa_hashmap_remove(y->devices, path))) {
> +                    pa_log_debug("Device %s removed", d->path);
> +                    run_callback(d, TRUE);

s/TRUE/true/

-- 
Tanu



More information about the pulseaudio-discuss mailing list