diff --git a/client/dbus-proxy.c b/client/dbus-proxy.c index 29c7fe24..536ef000 100644 --- a/client/dbus-proxy.c +++ b/client/dbus-proxy.c @@ -43,10 +43,53 @@ static struct l_dbus *dbus; static struct l_queue *proxy_interfaces; static struct l_queue *proxy_interface_types; +static void proxy_interface_property_set(struct proxy_interface *proxy, + const char *name, + struct l_dbus_message_iter *variant) +{ + size_t i; + const void *value; + const struct proxy_interface_property *property_table = + proxy->type->properties; + + for (i = 0; property_table[i].name; i++) { + if (strcmp(property_table[i].name, name)) + continue; + + if (!property_table[i].set) + return; + + if (variant) + l_dbus_message_iter_get_variant(variant, + property_table[i].type, + &value); + else + value = NULL; + + property_table[i].set(proxy->data, value); + + return; + } + + l_debug("Unknown property name: %s for interface %s", name, + proxy->type->interface); +} + static void interface_update_properties(struct proxy_interface *proxy, struct l_dbus_message_iter *changed, struct l_dbus_message_iter *invalidated) { + const char *name; + struct l_dbus_message_iter variant; + + while (l_dbus_message_iter_next_entry(changed, &name, &variant)) + proxy_interface_property_set(proxy, name, &variant); + + if (!invalidated) + return; + + while (l_dbus_message_iter_next_entry(invalidated, &name)) + proxy_interface_property_set(proxy, name, NULL); } static bool dbus_message_has_error(struct l_dbus_message *message) diff --git a/client/dbus-proxy.h b/client/dbus-proxy.h index b5276439..cc9abf95 100644 --- a/client/dbus-proxy.h +++ b/client/dbus-proxy.h @@ -22,6 +22,12 @@ struct proxy_interface; +struct proxy_interface_property { + const char *name; + const char *type; + void (*set)(void *data, const void *value); +}; + struct proxy_interface_type_ops { void *(*create)(void); void (*destroy)(void *data); @@ -29,6 +35,7 @@ struct proxy_interface_type_ops { struct proxy_interface_type { const char *interface; + const struct proxy_interface_property *properties; const struct proxy_interface_type_ops *ops; };