getting the user_data associated with an object path

Daniel Reed n at ml.org
Wed Mar 23 14:00:18 PST 2005


On 2005-03-23T16:43-0500, Havoc Pennington wrote:
) On Wed, 2005-03-23 at 15:13 -0500, Daniel Reed wrote:
) > Are there any better methods, or can this patch be reviewed?
) Can you explain the use-case?

DBUS maintains a hierarchy of objects for its client. The exact means of
conflict/duplicate resolution, handling having multiple sources (threads,
modules, etc.) populating or depopulating the tree, etc. are not necessarily
defined, so mimicking the hierarchy outside of DBUS can be error prone.
Additionally, mimicking it outside of DBUS wastes memory.

I just want a mechanism for retrieving an object once I have put it in the
tree.


) > The original patch is archived at:
) >   http://lists.freedesktop.org/archives/dbus/2005-March/002279.html
) The object_tree_get_user_data() function should be called
) get_user_data_unlocked() if it assumes the lock is held and does not
) change the lock, or get_user_data_and_unlock() if it assumes the lock is

Alrighty; making it _unlocked sounds the most reasonable of the two.

-- 
Daniel Reed <n at ml.org>	http://naim-users.org/nmlorg/	http://naim.n.ml.org/
I'd say some people have no lives, but I'm the one who's going to
wallpaper his room in naim source in a few days. -- FalseName, EFnet #naim
-------------- next part --------------
Index: dbus/dbus-connection.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-connection.c,v
retrieving revision 1.103
diff -u -r1.103 dbus-connection.c
--- dbus/dbus-connection.c	11 Mar 2005 17:43:22 -0000	1.103
+++ dbus/dbus-connection.c	23 Mar 2005 21:54:58 -0000
@@ -4208,6 +4208,27 @@
   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_unlocked (connection->objects, decomposed_path);
+
+  CONNECTION_UNLOCK (connection);
+
+  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	23 Mar 2005 21:54:59 -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.16
diff -u -r1.16 dbus-object-tree.c
--- dbus/dbus-object-tree.c	9 Mar 2005 17:30:38 -0000	1.16
+++ dbus/dbus-object-tree.c	23 Mar 2005 21:55:01 -0000
@@ -903,6 +903,32 @@
 }
 
 /**
+ * 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_unlocked (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);
+
+  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	23 Mar 2005 21:55:01 -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_unlocked(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