mirror of git://git.sysmocom.de/ofono
Add parse properties stuff to bluetooth.c
This commit is contained in:
parent
5bf4bec526
commit
4ccb481f4d
|
@ -93,6 +93,90 @@ fail:
|
|||
return err;
|
||||
}
|
||||
|
||||
typedef void (*PropertyHandler)(DBusMessageIter *iter, gpointer user_data);
|
||||
|
||||
struct property_handler {
|
||||
const char *property;
|
||||
PropertyHandler callback;
|
||||
gpointer user_data;
|
||||
};
|
||||
|
||||
static gint property_handler_compare(gconstpointer a, gconstpointer b)
|
||||
{
|
||||
const struct property_handler *handler = a;
|
||||
const char *property = b;
|
||||
|
||||
return strcmp(handler->property, property);
|
||||
}
|
||||
|
||||
static void parse_properties_reply(DBusMessage *reply,
|
||||
const char *property, ...)
|
||||
{
|
||||
va_list args;
|
||||
GSList *prop_handlers = NULL;
|
||||
DBusMessageIter array, dict;
|
||||
|
||||
va_start(args, property);
|
||||
|
||||
while (property != NULL) {
|
||||
struct property_handler *handler =
|
||||
g_new0(struct property_handler, 1);
|
||||
|
||||
handler->property = property;
|
||||
handler->callback = va_arg(args, PropertyHandler);
|
||||
handler->user_data = va_arg(args, gpointer);
|
||||
|
||||
property = va_arg(args, const char *);
|
||||
|
||||
prop_handlers = g_slist_prepend(prop_handlers, handler);
|
||||
}
|
||||
|
||||
va_end(args);
|
||||
|
||||
if (dbus_message_iter_init(reply, &array) == FALSE)
|
||||
goto done;
|
||||
|
||||
if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
|
||||
goto done;
|
||||
|
||||
dbus_message_iter_recurse(&array, &dict);
|
||||
|
||||
while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
|
||||
DBusMessageIter entry, value;
|
||||
const char *key;
|
||||
GSList *l;
|
||||
|
||||
dbus_message_iter_recurse(&dict, &entry);
|
||||
|
||||
if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
|
||||
goto done;
|
||||
|
||||
dbus_message_iter_get_basic(&entry, &key);
|
||||
|
||||
dbus_message_iter_next(&entry);
|
||||
|
||||
if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
|
||||
goto done;
|
||||
|
||||
dbus_message_iter_recurse(&entry, &value);
|
||||
|
||||
l = g_slist_find_custom(prop_handlers, key,
|
||||
property_handler_compare);
|
||||
|
||||
if (l) {
|
||||
struct property_handler *handler = l->data;
|
||||
|
||||
handler->callback(&value, handler->user_data);
|
||||
}
|
||||
|
||||
dbus_message_iter_next(&dict);
|
||||
}
|
||||
|
||||
done:
|
||||
g_slist_foreach(prop_handlers, (GFunc)g_free, NULL);
|
||||
g_slist_free(prop_handlers);
|
||||
}
|
||||
|
||||
int bluetooth_register_uuid(const char *uuid, struct bluetooth_profile *profile)
|
||||
{
|
||||
if (uuid_hash)
|
||||
|
|
Loading…
Reference in New Issue