[pulseaudio-discuss] [RFC next v4 03/16] bluetooth: Support ObjectManager interface add/remove

Tanu Kaskinen tanu.kaskinen at intel.com
Thu May 9 01:18:22 PDT 2013


On Mon, 2013-04-29 at 18:28 +0200, 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 | 58 ++++++++++++++++++++++++++++++++++
>  1 file changed, 58 insertions(+)
> 
> diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
> index cee283e..c60f3ff 100644
> --- a/src/modules/bluetooth/bluetooth-util.c
> +++ b/src/modules/bluetooth/bluetooth-util.c
> @@ -1209,6 +1209,60 @@ 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) || !pa_streq(dbus_message_get_signature(m), "oa{sa{sv}}")) {
> +            pa_log("Invalid signature found in InterfacesAdded");
> +            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) || !pa_streq(dbus_message_get_signature(m), "oas")) {
> +            pa_log("Invalid signature found in InterfacesRemoved");
> +            goto fail;
> +        }
> +
> +        dbus_message_iter_get_basic(&arg_i, &path);
> +
> +        pa_assert_se(dbus_message_iter_next(&arg_i));
> +        pa_assert(dbus_message_iter_get_arg_type(&arg_i) == DBUS_TYPE_ARRAY);
> +
> +        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);
> +                    device_free(d);
> +                }

We should know about every device, so it should never happen that
pa_hashmap_remove() fails here. If it happens anyway, I think a warning
would be appropriate.

-- 
Tanu

---------------------------------------------------------------------
Intel Finland Oy
Registered Address: PL 281, 00181 Helsinki 
Business Identity Code: 0357606 - 4 
Domiciled in Helsinki 

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.


More information about the pulseaudio-discuss mailing list