getting the user_data associated with an object path

Daniel Reed n at ml.org
Fri Mar 4 09:32:54 PST 2005


Assuming I make a call:
	dbus_connection_register_object_path(connection, obj->path, &obj_vtable, (void *)obj))

What is the most effective means of getting the user_data obj back given
obj->path?

dbus_connection_list_registered() only gives me path components for
children; no user_data values. There doesn't appear to be any other exported
API for dealing with registered paths.

If there is no great way of doing it now, would it be possible for an API
call to be added in the next API revision? I have attached a simple patch to
add an external call dbus_connection_get_object_user_data() to retrieve the
user_data associated with a given object path.

-- 
Daniel Reed <n at ml.org>	http://naim-users.org/nmlorg/	http://naim.n.ml.org/
Mourn the losses because they are many; but celebrate the victories
because they are few.
-------------- next part --------------
Index: dbus/dbus-connection.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-connection.c,v
retrieving revision 1.101
diff -u -r1.101 dbus-connection.c
--- dbus/dbus-connection.c	26 Feb 2005 06:37:46 -0000	1.101
+++ dbus/dbus-connection.c	4 Mar 2005 07:10:59 -0000
@@ -4204,6 +4204,25 @@
   return TRUE;
 }
 
+void *
+dbus_connection_get_object_user_data (DBusConnection              *connection,
+                                      const char                  *path)
+{
+  char **decomposed_path;
+  void *result;
+
+  if (!_dbus_decompose_path (path, strlen (path), &decomposed_path, NULL))
+      return FALSE;
+
+  CONNECTION_LOCK (connection);
+
+  result = _dbus_object_tree_get_user_data (connection->objects, decomposed_path);
+
+  dbus_free_string_array (decomposed_path);
+
+  return result;
+}
+
 /**
  * Lists the registered fallback handlers and object path handlers at
  * the given parent_path. The returned array should be freed with
Index: dbus/dbus-connection.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-connection.h,v
retrieving revision 1.35
diff -u -r1.35 dbus-connection.h
--- dbus/dbus-connection.h	26 Feb 2005 06:37:46 -0000	1.35
+++ dbus/dbus-connection.h	4 Mar 2005 07:11:00 -0000
@@ -241,6 +241,9 @@
 dbus_bool_t dbus_connection_unregister_object_path (DBusConnection              *connection,
                                                     const char                  *path);
 
+void*       dbus_connection_get_object_user_data   (DBusConnection              *connection,
+                                                    const char                  *path);
+
 dbus_bool_t dbus_connection_list_registered        (DBusConnection              *connection,
                                                     const char                  *parent_path,
                                                     char                      ***child_entries);
Index: dbus/dbus-object-tree.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-object-tree.c,v
retrieving revision 1.15
diff -u -r1.15 dbus-object-tree.c
--- dbus/dbus-object-tree.c	17 Feb 2005 21:19:49 -0000	1.15
+++ dbus/dbus-object-tree.c	4 Mar 2005 07:11:02 -0000
@@ -899,6 +899,40 @@
 }
 
 /**
+ * Tries to find a specific object's user_data field.
+ *
+ * @param tree the global object tree
+ * @param path NULL-terminated array of path elements giving path to subtree
+ * @returns the object's user_data
+ */
+void*
+_dbus_object_tree_get_user_data (DBusObjectTree          *tree,
+                                 char                   **path)
+{
+  dbus_bool_t exact_match;
+  DBusObjectSubtree *subtree;
+
+  /* Find the deepest path that covers the path in the message */
+  subtree = find_handler (tree, (const char**) path, &exact_match);
+
+#ifdef DBUS_BUILD_TESTS
+  if (tree->connection)
+#endif
+    {
+      _dbus_verbose ("unlock %s\n", _DBUS_FUNCTION_NAME);
+      _dbus_connection_unlock (tree->connection);
+    }
+
+  if ((subtree == NULL) || !exact_match)
+    {
+      _dbus_verbose ("No object at specified path found\n");
+      return NULL;
+    }
+
+  return subtree->user_data;
+}
+
+/**
  * Allocates a subtree object.
  *
  * @param name name to duplicate.
Index: dbus/dbus-object-tree.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-object-tree.h,v
retrieving revision 1.7
diff -u -r1.7 dbus-object-tree.h
--- dbus/dbus-object-tree.h	15 Jan 2005 07:15:38 -0000	1.7
+++ dbus/dbus-object-tree.h	4 Mar 2005 07:11:02 -0000
@@ -42,6 +42,8 @@
                                                            const char                 **path);
 DBusHandlerResult _dbus_object_tree_dispatch_and_unlock   (DBusObjectTree              *tree,
                                                            DBusMessage                 *message);
+void*             _dbus_object_tree_get_user_data         (DBusObjectTree              *tree,
+                                                           char                       **path);
 void              _dbus_object_tree_free_all_unlocked     (DBusObjectTree              *tree);
 
 dbus_bool_t _dbus_object_tree_list_registered_and_unlock (DBusObjectTree *tree,


More information about the dbus mailing list