[PATCH v4 13/41] bluetooth: Handle InterfacesAdded and InterfacesRemoved

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2013-09-18 at 16:17 -0500, jprvita at gmail.com wrote:
> From: Jo?o Paulo Rechi Vita <jprvita at openbossa.org>
> 
> This code is based on previous work by Mikel Astiz.
> ---
>  src/modules/bluetooth/bluez5-util.c | 55 +++++++++++++++++++++++++++++++++++++
>  1 file changed, 55 insertions(+)
> 
> diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c
> index f5d4300..bf4a046 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_DEVICE_INTERFACE BLUEZ_SERVICE ".Device1"
>  #define BLUEZ_MEDIA_ENDPOINT_INTERFACE BLUEZ_SERVICE ".MediaEndpoint1"
>  #define BLUEZ_MEDIA_TRANSPORT_INTERFACE BLUEZ_SERVICE ".MediaTransport1"
>  
> @@ -476,6 +477,53 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us
>          }
>  
>          return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
> +    } else if (dbus_message_is_signal(m, "org.freedesktop.DBus.ObjectManager", "InterfacesAdded")) {
> +        DBusMessageIter arg_i;
> +
> +        if (!y->objects_listed)
> +            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_error("Invalid signature found in InterfacesAdded");
> +            goto fail;
> +        }
> +
> +        /* TODO: parse interfaces and properties */
> +
> +        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
> +    } else if (dbus_message_is_signal(m, "org.freedesktop.DBus.ObjectManager", "InterfacesRemoved")) {
> +        const char *p;
> +        DBusMessageIter arg_i;
> +        DBusMessageIter element_i;
> +
> +        if (!y->objects_listed)
> +            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_error("Invalid signature found in InterfacesRemoved");
> +            goto fail;
> +        }
> +
> +        dbus_message_iter_get_basic(&arg_i, &p);
> +
> +        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 *iface;
> +
> +            dbus_message_iter_get_basic(&element_i, &iface);
> +
> +            if (pa_streq(iface, BLUEZ_DEVICE_INTERFACE))
> +                device_remove(y, p);
> +
> +            dbus_message_iter_next(&element_i);
> +        }

This code handles only device removal, but I suppose adapter removal
should be handled too?

-- 
Tanu



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux