summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2005-04-24 14:04:16 +0000
committerHavoc Pennington <hp@redhat.com>2005-04-24 14:04:16 +0000
commit64f3d8f67db09e0c84ed3ff009b86d0127fe82b4 (patch)
tree1d090b30b2cdbf6dda54e6a9f961718db6b51552
parent52fce19fabf2e529c9bd332bcf8c5a4b56e42725 (diff)
2005-04-23 Havoc Pennington <hp@redhat.com>
* dbus/dbus-message.c (dbus_message_append_args): fix doc comment, reported by Tony Houghton * test/test-service.c (main): test dbus_connection_get_object_path_data() * dbus/dbus-object-tree.c (find_handler): be sure we always init the exact_match (_dbus_object_tree_get_user_data_unlocked): new function used by dbus_connection_get_object_path_data() (do_register): add assertion test for get_user_data_unlocked (object_tree_test_iteration): more tests * dbus/dbus-connection.c (dbus_connection_get_object_path_data): new function from Dan Reed to let you get the user data from dbus_connection_register_object_path()
-rw-r--r--ChangeLog19
-rw-r--r--dbus/dbus-connection.c37
-rw-r--r--dbus/dbus-connection.h4
-rw-r--r--dbus/dbus-message.c20
-rw-r--r--dbus/dbus-object-tree.c46
-rw-r--r--dbus/dbus-object-tree.h23
-rw-r--r--test/test-service.c10
7 files changed, 133 insertions, 26 deletions
diff --git a/ChangeLog b/ChangeLog
index 56301ee7..0368b119 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2005-04-23 Havoc Pennington <hp@redhat.com>
+
+ * dbus/dbus-message.c (dbus_message_append_args): fix doc comment,
+ reported by Tony Houghton
+
+ * test/test-service.c (main): test
+ dbus_connection_get_object_path_data()
+
+ * dbus/dbus-object-tree.c (find_handler): be sure we always init
+ the exact_match
+ (_dbus_object_tree_get_user_data_unlocked): new function used by
+ dbus_connection_get_object_path_data()
+ (do_register): add assertion test for get_user_data_unlocked
+ (object_tree_test_iteration): more tests
+
+ * dbus/dbus-connection.c (dbus_connection_get_object_path_data):
+ new function from Dan Reed to let you get the user data from
+ dbus_connection_register_object_path()
+
2005-04-23 John (J5) Palmieri <johnp@redhat.com>
* dbus/dbus-marshal-recursive-util.c: Fixed buffer overflow
diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c
index df8de937..edc57b84 100644
--- a/dbus/dbus-connection.c
+++ b/dbus/dbus-connection.c
@@ -4301,6 +4301,43 @@ dbus_connection_unregister_object_path (DBusConnection *connection,
}
/**
+ * 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().
diff --git a/dbus/dbus-connection.h b/dbus/dbus-connection.h
index 2c0b7f2c..25a5b0ea 100644
--- a/dbus/dbus-connection.h
+++ b/dbus/dbus-connection.h
@@ -243,6 +243,10 @@ dbus_bool_t dbus_connection_register_fallback (DBusConnection
dbus_bool_t dbus_connection_unregister_object_path (DBusConnection *connection,
const char *path);
+dbus_bool_t dbus_connection_get_object_path_data (DBusConnection *connection,
+ const char *path,
+ void **data_p);
+
dbus_bool_t dbus_connection_list_registered (DBusConnection *connection,
const char *parent_path,
char ***child_entries);
diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c
index b090fab0..8a9014ca 100644
--- a/dbus/dbus-message.c
+++ b/dbus/dbus-message.c
@@ -1142,25 +1142,15 @@ dbus_message_get_type (DBusMessage *message)
* rather than this function.
*
* To append a basic type, specify its type code followed by the
- * value. For example:
+ * address of the value. For example:
*
* @code
- * DBUS_TYPE_INT32, 42,
- * DBUS_TYPE_STRING, "Hello World"
- * @endcode
- * or
- * @code
- * dbus_int32_t val = 42;
- * DBUS_TYPE_INT32, val
- * @endcode
*
- * Be sure that your provided value is the right size. For example, this
- * won't work:
- * @code
- * DBUS_TYPE_INT64, 42
+ * dbus_int32_t v_INT32 = 42;
+ * const char *v_STRING = "Hello World";
+ * DBUS_TYPE_INT32, &v_INT32,
+ * DBUS_TYPE_STRING, &v_STRING,
* @endcode
- * Because the "42" will be a 32-bit integer. You need to cast to
- * 64-bit.
*
* To append an array of fixed-length basic types, pass in the
* DBUS_TYPE_ARRAY typecode, the element typecode, the address of
diff --git a/dbus/dbus-object-tree.c b/dbus/dbus-object-tree.c
index 1d6029af..73d4befc 100644
--- a/dbus/dbus-object-tree.c
+++ b/dbus/dbus-object-tree.c
@@ -373,6 +373,9 @@ find_handler (DBusObjectTree *tree,
_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);
}
@@ -903,6 +906,37 @@ _dbus_object_tree_dispatch_and_unlock (DBusObjectTree *tree,
}
/**
+ * 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.
@@ -1311,6 +1345,9 @@ do_register (DBusObjectTree *tree,
&tree_test_data[i]))
return FALSE;
+ _dbus_assert (_dbus_object_tree_get_user_data_unlocked (tree, path) ==
+ &tree_test_data[i]);
+
return TRUE;
}
@@ -1717,6 +1754,7 @@ object_tree_test_iteration (void *data)
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));
@@ -1729,6 +1767,7 @@ object_tree_test_iteration (void *data)
_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));
@@ -1741,6 +1780,7 @@ object_tree_test_iteration (void *data)
_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));
@@ -1753,6 +1793,7 @@ object_tree_test_iteration (void *data)
_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));
@@ -1765,6 +1806,7 @@ object_tree_test_iteration (void *data)
_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));
@@ -1777,6 +1819,7 @@ object_tree_test_iteration (void *data)
_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));
@@ -1789,6 +1832,7 @@ object_tree_test_iteration (void *data)
_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));
@@ -1801,6 +1845,7 @@ object_tree_test_iteration (void *data)
_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));
@@ -1813,6 +1858,7 @@ object_tree_test_iteration (void *data)
_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));
diff --git a/dbus/dbus-object-tree.h b/dbus/dbus-object-tree.h
index 6d8484e0..d1c04b4b 100644
--- a/dbus/dbus-object-tree.h
+++ b/dbus/dbus-object-tree.h
@@ -33,16 +33,19 @@ DBusObjectTree* _dbus_object_tree_new (DBusConnection *connection);
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,
diff --git a/test/test-service.c b/test/test-service.c
index 9316b626..040a0300 100644
--- a/test/test-service.c
+++ b/test/test-service.c
@@ -188,9 +188,17 @@ main (int argc,
if (!dbus_connection_register_object_path (connection,
echo_path,
&echo_vtable,
- NULL))
+ (void*) 0xdeadbeef))
die ("No memory");
+ {
+ void *d;
+ if (!dbus_connection_get_object_path_data (connection, echo_path, &d))
+ die ("No memory");
+ if (d != (void*) 0xdeadbeef)
+ die ("dbus_connection_get_object_path_data() doesn't seem to work right\n");
+ }
+
result = dbus_bus_request_name (connection, "org.freedesktop.DBus.TestSuiteEchoService",
0, &error);
if (dbus_error_is_set (&error))