}
/**
+ * Gets the user data passed to dbus_connection_register_object_path()
+ * or dbus_connection_register_fallback(). If nothing was registered
+ * at this path, the data is filled in with #NULL.
+ *
+ * @param connection the connection
+ * @param path the path you registered with
+ * @param data_p location to store the user data, or #NULL
+ * @returns #FALSE if not enough memory
+ */
+dbus_bool_t
+dbus_connection_get_object_path_data (DBusConnection *connection,
+ const char *path,
+ void **data_p)
+{
+ char **decomposed_path;
+
+ _dbus_return_val_if_fail (connection != NULL, FALSE);
+ _dbus_return_val_if_fail (path != NULL, FALSE);
+ _dbus_return_val_if_fail (data_p != NULL, FALSE);
+
+ *data_p = NULL;
+
+ if (!_dbus_decompose_path (path, strlen (path), &decomposed_path, NULL))
+ return FALSE;
+
+ CONNECTION_LOCK (connection);
+
+ *data_p = _dbus_object_tree_get_user_data_unlocked (connection->objects, (const char**) decomposed_path);
+
+ CONNECTION_UNLOCK (connection);
+
+ dbus_free_string_array (decomposed_path);
+
+ return TRUE;
+}
+
+/**
* Lists the registered fallback handlers and object path handlers at
* the given parent_path. The returned array should be freed with
* dbus_free_string_array().
_dbus_verbose ("Looking for deepest handler\n");
#endif
_dbus_assert (exact_match != NULL);
+
+ *exact_match = FALSE; /* ensure always initialized */
+
return find_subtree_recurse (tree->root, path, FALSE, NULL, exact_match);
}
}
/**
+ * Looks up the data passed to _dbus_object_tree_register() for a
+ * handler at the given path.
+ *
+ * @param tree the global object tree
+ * @param path NULL-terminated array of path elements giving path to subtree
+ * @returns the object's user_data or #NULL if none found
+ */
+void*
+_dbus_object_tree_get_user_data_unlocked (DBusObjectTree *tree,
+ const char **path)
+{
+ dbus_bool_t exact_match;
+ DBusObjectSubtree *subtree;
+
+ _dbus_assert (tree != NULL);
+ _dbus_assert (path != NULL);
+
+ /* 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 ("%s: No object at specified path found\n",
+ _DBUS_FUNCTION_NAME);
+ return NULL;
+ }
+
+ return subtree->user_data;
+}
+
+/**
* Allocates a subtree object.
*
* @param name name to duplicate.
&tree_test_data[i]))
return FALSE;
+ _dbus_assert (_dbus_object_tree_get_user_data_unlocked (tree, path) ==
+ &tree_test_data[i]);
+
return TRUE;
}
goto out;
_dbus_object_tree_unregister_and_unlock (tree, path0);
+ _dbus_assert (_dbus_object_tree_get_user_data_unlocked (tree, path0) == NULL);
_dbus_assert (!find_subtree (tree, path0, NULL));
_dbus_assert (find_subtree (tree, path1, NULL));
_dbus_assert (find_subtree (tree, path8, NULL));
_dbus_object_tree_unregister_and_unlock (tree, path1);
+ _dbus_assert (_dbus_object_tree_get_user_data_unlocked (tree, path1) == NULL);
_dbus_assert (!find_subtree (tree, path0, NULL));
_dbus_assert (!find_subtree (tree, path1, NULL));
_dbus_assert (find_subtree (tree, path8, NULL));
_dbus_object_tree_unregister_and_unlock (tree, path2);
+ _dbus_assert (_dbus_object_tree_get_user_data_unlocked (tree, path2) == NULL);
_dbus_assert (!find_subtree (tree, path0, NULL));
_dbus_assert (!find_subtree (tree, path1, NULL));
_dbus_assert (find_subtree (tree, path8, NULL));
_dbus_object_tree_unregister_and_unlock (tree, path3);
+ _dbus_assert (_dbus_object_tree_get_user_data_unlocked (tree, path3) == NULL);
_dbus_assert (!find_subtree (tree, path0, NULL));
_dbus_assert (!find_subtree (tree, path1, NULL));
_dbus_assert (find_subtree (tree, path8, NULL));
_dbus_object_tree_unregister_and_unlock (tree, path4);
+ _dbus_assert (_dbus_object_tree_get_user_data_unlocked (tree, path4) == NULL);
_dbus_assert (!find_subtree (tree, path0, NULL));
_dbus_assert (!find_subtree (tree, path1, NULL));
_dbus_assert (find_subtree (tree, path8, NULL));
_dbus_object_tree_unregister_and_unlock (tree, path5);
+ _dbus_assert (_dbus_object_tree_get_user_data_unlocked (tree, path5) == NULL);
_dbus_assert (!find_subtree (tree, path0, NULL));
_dbus_assert (!find_subtree (tree, path1, NULL));
_dbus_assert (find_subtree (tree, path8, NULL));
_dbus_object_tree_unregister_and_unlock (tree, path6);
+ _dbus_assert (_dbus_object_tree_get_user_data_unlocked (tree, path6) == NULL);
_dbus_assert (!find_subtree (tree, path0, NULL));
_dbus_assert (!find_subtree (tree, path1, NULL));
_dbus_assert (find_subtree (tree, path8, NULL));
_dbus_object_tree_unregister_and_unlock (tree, path7);
+ _dbus_assert (_dbus_object_tree_get_user_data_unlocked (tree, path7) == NULL);
_dbus_assert (!find_subtree (tree, path0, NULL));
_dbus_assert (!find_subtree (tree, path1, NULL));
_dbus_assert (find_subtree (tree, path8, NULL));
_dbus_object_tree_unregister_and_unlock (tree, path8);
+ _dbus_assert (_dbus_object_tree_get_user_data_unlocked (tree, path8) == NULL);
_dbus_assert (!find_subtree (tree, path0, NULL));
_dbus_assert (!find_subtree (tree, path1, NULL));
DBusObjectTree* _dbus_object_tree_ref (DBusObjectTree *tree);
void _dbus_object_tree_unref (DBusObjectTree *tree);
-dbus_bool_t _dbus_object_tree_register (DBusObjectTree *tree,
- dbus_bool_t fallback,
- const char **path,
- const DBusObjectPathVTable *vtable,
- void *user_data);
-void _dbus_object_tree_unregister_and_unlock (DBusObjectTree *tree,
- const char **path);
-DBusHandlerResult _dbus_object_tree_dispatch_and_unlock (DBusObjectTree *tree,
- DBusMessage *message);
-void _dbus_object_tree_free_all_unlocked (DBusObjectTree *tree);
+dbus_bool_t _dbus_object_tree_register (DBusObjectTree *tree,
+ dbus_bool_t fallback,
+ const char **path,
+ const DBusObjectPathVTable *vtable,
+ void *user_data);
+void _dbus_object_tree_unregister_and_unlock (DBusObjectTree *tree,
+ const char **path);
+DBusHandlerResult _dbus_object_tree_dispatch_and_unlock (DBusObjectTree *tree,
+ DBusMessage *message);
+void* _dbus_object_tree_get_user_data_unlocked (DBusObjectTree *tree,
+ const char **path);
+void _dbus_object_tree_free_all_unlocked (DBusObjectTree *tree);
+
dbus_bool_t _dbus_object_tree_list_registered_and_unlock (DBusObjectTree *tree,
const char **parent_path,