diff mbox series

[1/2] dbus: add _dbus_object_tree_set_interface_data

Message ID 20240807175943.170002-1-prestwoj@gmail.com (mailing list archive)
State Accepted, archived
Headers show
Series [1/2] dbus: add _dbus_object_tree_set_interface_data | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
prestwoj/iwd-ci-setupell success Prep - Setup ELL
prestwoj/iwd-ci-makedistcheck success Make Distcheck
prestwoj/iwd-ci-build success Build - Configure
prestwoj/iwd-ci-makecheckvalgrind success Make Check w/Valgrind
prestwoj/iwd-ci-makecheck success Make Check
prestwoj/iwd-ci-clang success clang PASS
prestwoj/iwd-ci-testrunner success test-runner PASS

Commit Message

James Prestwood Aug. 7, 2024, 5:59 p.m. UTC
This is to prep for l_dbus_object_set_data(), i.e. modifying the
user_data of an existing dbus object.
---
 ell/dbus-private.h |  4 ++++
 ell/dbus-service.c | 33 +++++++++++++++++++++++++++++----
 2 files changed, 33 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/ell/dbus-private.h b/ell/dbus-private.h
index fd5d099..0c06410 100644
--- a/ell/dbus-private.h
+++ b/ell/dbus-private.h
@@ -207,6 +207,10 @@  bool _dbus_object_tree_remove_interface(struct _dbus_object_tree *tree,
 void *_dbus_object_tree_get_interface_data(struct _dbus_object_tree *tree,
 						const char *path,
 						const char *interface);
+bool _dbus_object_tree_set_interface_data(struct _dbus_object_tree *tree,
+						const char *path,
+						const char *interface,
+						void *user_data);
 
 void _dbus_object_tree_introspect(struct _dbus_object_tree *tree,
 					const char *path, struct l_string *buf);
diff --git a/ell/dbus-service.c b/ell/dbus-service.c
index d4466de..0300bfe 100644
--- a/ell/dbus-service.c
+++ b/ell/dbus-service.c
@@ -1568,25 +1568,50 @@  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,
+static struct interface_instance *_dbus_object_tree_find_interface(
+						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);
+	return l_queue_find(object->instances, match_interface_instance,
+				interface);
+}
+
+void *_dbus_object_tree_get_interface_data(struct _dbus_object_tree *tree,
+						const char *path,
+						const char *interface)
+{
+	struct interface_instance *instance;
+
+	instance = _dbus_object_tree_find_interface(tree, path, interface);
 	if (!instance)
 		return NULL;
 
 	return instance->user_data;
 }
 
+bool _dbus_object_tree_set_interface_data(struct _dbus_object_tree *tree,
+						const char *path,
+						const char *interface,
+						void *user_data)
+{
+	struct interface_instance *instance;
+
+	instance = _dbus_object_tree_find_interface(tree, path, interface);
+	if (!instance)
+		return false;
+
+	instance->user_data = user_data;
+
+	return true;
+}
+
 static bool match_object_manager_path(const void *a, const void *b)
 {
 	const struct object_manager *manager = a;