dbus: Add l_dbus_object_get_data
PATCH 1/2 dbus: Add l_dbus_object_get_data
This function can be used by DBus method implementations that receive an object path as a parameter to directly look up the user_data by the path and interface name.
--- ell/dbus-private.h | 3 +++ ell/dbus-service.c | 19 +++++++++++++++++++ ell/dbus.c | 13 +++++++++++++ ell/dbus.h | 2 ++ ell/ell.sym | 1 + 5 files changed, 38 insertions(+)
ell/dbus-private.h +3 -0
@@ -219,6 +219,9 @@ bool _dbus_object_tree_add_interface(struct _dbus_object_tree *tree,bool _dbus_object_tree_remove_interface (struct _dbus_object_tree *tree,const char *path,const char *interface); +void *_dbus_object_tree_get_interface_data (struct _dbus_object_tree *tree, +const char *path, +const char *interface);void _dbus_object_tree_introspect (struct _dbus_object_tree *tree,const char *path,struct l_string *buf);
ell/dbus-service.c +19 -0
@@ -1556,6 +1556,25 @@ bool _dbus_object_tree_add_interface(struct _dbus_object_tree *tree,return true; } +void *_dbus_object_tree_get_interface_data (struct _dbus_object_tree *tree, +const char *path, +const char *interface) +{ +struct object_node *object; +struct interface_instance *instance; + + object =l_hashmap_lookup (tree->objects, path); +if (!object) +return NULL ; + + instance =l_queue_find (object->instances, match_interface_instance, + (char *) interface); +if (!instance) +return NULL ; + +return instance->user_data; +} +static bool match_object_manager_path (const void *a,const void *b) {const struct object_manager *manager = a;
ell/dbus.c +13 -0
@@ -1585,6 +1585,19 @@ LIB_EXPORT bool l_dbus_object_remove_interface(struct l_dbus *dbus, interface); } +LIB_EXPORT void *l_dbus_object_get_data(struct l_dbus *dbus, const char *object, +const char *interface) +{ +if (unlikely (!dbus)) +return false; + +if (unlikely (!dbus->tree)) +return false; + +return _dbus_object_tree_get_interface_data (dbus->tree, object, + interface); +} + LIB_EXPORT bool l_dbus_object_manager_enable(struct l_dbus *dbus) {if (unlikely (!dbus))
ell/dbus.h +2 -0
@@ -239,6 +239,8 @@ bool l_dbus_object_add_interface(struct l_dbus *dbus, const char *object, const char *interface, void *user_data);bool l_dbus_object_remove_interface (struct l_dbus *dbus,const char *object,const char *interface); +void *l_dbus_object_get_data (struct l_dbus *dbus,const char *object, +const char *interface);bool l_dbus_object_manager_enable (struct l_dbus *dbus);
ell/ell.sym +1 -0
@@ -210,6 +210,7 @@ global: l_dbus_unregister_object; l_dbus_object_add_interface; l_dbus_object_remove_interface; + l_dbus_object_get_data; l_dbus_object_manager_enable; l_dbus_add_disconnect_watch; l_dbus_add_service_watch;
Signature · 1 line
2.20.1
Hi Andrew,
Quoted 11 lines · Andrew Zaborowski
This function can be used by DBus method implementations that receive an object path as a parameter to directly look up the
user_databy the path and interface name.--- ell/dbus-private.h | 3 +++ ell/dbus-service.c | 19 +++++++++++++++++++ ell/dbus.c | 13 +++++++++++++ ell/dbus.h | 2 ++ ell/ell.sym | 1 + 5 files changed, 38 insertions(+)
Both applied, thanks.
Regards,
-Denis
PATCH 2/2 dbus: Use ptr match instead of string match where possible
In reply to Andrew ZaborowskiSlightly optimize the interface lookup where we already have the pointer to the interface struct to only look for that pointer instead of the interface name match.
--- ell/dbus-service.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
ell/dbus-service.c +9 -4
@@ -524,6 +524,13 @@ static bool match_interface_instance(const void *a, const void *b)return false; } +static bool match_interface_instance_ptr (const void *a,const void *b) +{ +const struct interface_instance *instance = a; + +return instance->interface == b; +} +static void interface_add_record_free (void *data) {struct interface_add_record *rec = data;
@@ -1499,8 +1506,7 @@ bool _dbus_object_tree_add_interface(struct _dbus_object_tree *tree,* Check to make sure we do not have this interface already * registered for this object */ -if (l_queue_find (object->instances, match_interface_instance, - (char *) interface)) +if (l_queue_find (object->instances, match_interface_instance_ptr, dbi))return false; instance = l_new(struct interface_instance, 1);
@@ -1892,8 +1898,7 @@ static struct l_dbus_message *properties_set(struct l_dbus *dbus,/* If we got here the object must exist */ instance =l_queue_find (object->instances, - match_interface_instance, - (char *) interface_name); + match_interface_instance_ptr, interface);if (!instance)return l_dbus_message_new_error (message, "org.freedesktop.DBus.Error."
Signature · 1 line
2.20.1