25#include "dbus-object-tree.h"
26#include "dbus-connection-internal.h"
27#include "dbus-internals.h"
29#include "dbus-protocol.h"
30#include "dbus-string.h"
31#include <dbus/dbus-test-tap.h>
108 tree->
root = _dbus_object_subtree_new (
"/",
NULL,
NULL);
161#define VERBOSE_FIND 0
167 int *index_in_parent,
173 return_deepest_match = exact_match !=
NULL;
175 _dbus_assert (!(return_deepest_match && create_if_not_found));
180 _dbus_verbose (
" path exhausted, returning %s\n",
183 if (exact_match !=
NULL)
189 _dbus_verbose (
" searching children of %s for %s\n",
190 subtree->
name, path[0]);
203 _dbus_verbose (
" %s cmp %s = %d\n",
213 _dbus_verbose (
" storing parent index %d\n", k);
215 *index_in_parent = k;
218 if (return_deepest_match)
222 next = find_subtree_recurse (subtree->
subtrees[k],
223 &path[1], create_if_not_found,
224 index_in_parent, exact_match);
229 _dbus_verbose (
" no deeper match found, returning %s\n",
232 if (exact_match !=
NULL)
233 *exact_match =
FALSE;
240 return find_subtree_recurse (subtree->
subtrees[k],
241 &path[1], create_if_not_found,
242 index_in_parent, exact_match);
255 _dbus_verbose (
" no match found, current tree %s, create_if_not_found = %d\n",
256 subtree->
name, create_if_not_found);
259 if (create_if_not_found)
262 int child_pos, new_n_subtrees;
265 _dbus_verbose (
" creating subtree %s\n",
269 child = _dbus_object_subtree_new (path[0],
277 int new_max_subtrees;
283 if (new_subtrees ==
NULL)
285 _dbus_object_subtree_unref (child);
296 new_n_subtrees <= subtree->max_subtrees);
297 if (child_pos + 1 < new_n_subtrees)
299 memmove (&subtree->
subtrees[child_pos+1],
301 (new_n_subtrees - child_pos - 1) *
304 subtree->
subtrees[child_pos] = child;
307 *index_in_parent = child_pos;
311 return find_subtree_recurse (child,
312 &path[1], create_if_not_found,
313 index_in_parent, exact_match);
317 if (exact_match !=
NULL)
318 *exact_match =
FALSE;
323#ifdef DBUS_ENABLE_EMBEDDED_TESTS
327 int *index_in_parent)
332 _dbus_verbose (
"Looking for exact registered subtree\n");
335 subtree = find_subtree_recurse (tree->
root, path,
FALSE, index_in_parent,
NULL);
349 _dbus_verbose (
"Looking for subtree\n");
360 _dbus_verbose (
"Looking for deepest handler\n");
364 *exact_match =
FALSE;
366 return find_subtree_recurse (tree->
root, path,
FALSE,
NULL, exact_match);
374 _dbus_verbose (
"Ensuring subtree\n");
379static char *flatten_path (
const char **path);
407 subtree = ensure_subtree (tree, path);
410 _DBUS_SET_OOM (error);
418 char *complete_path = flatten_path (path);
421 "A handler is already registered for %s",
422 complete_path ? complete_path
423 :
"(cannot represent path: out of memory!)");
453 void **user_data_out)
503 _dbus_assert (child_index >= 0 && child_index < parent->n_subtrees);
505 candidate = parent->
subtrees[child_index];
515 memmove (&parent->
subtrees[child_index],
523 _dbus_object_subtree_unref (candidate);
568unregister_and_free_path_recurse
573 void **user_data_out)
583 return unregister_subtree (subtree, unregister_function_out, user_data_out);
597 freed = unregister_and_free_path_recurse (subtree->
subtrees[k],
599 continue_removal_attempts,
600 unregister_function_out,
602 if (freed && *continue_removal_attempts)
603 *continue_removal_attempts = attempt_child_removal (subtree, k);
638 continue_removal_attempts =
TRUE;
639 unregister_function =
NULL;
642 found_subtree = unregister_and_free_path_recurse (tree->
root,
644 &continue_removal_attempts,
645 &unregister_function,
648#ifndef DBUS_DISABLE_CHECKS
649 if (found_subtree ==
FALSE)
651 _dbus_warn (
"Attempted to unregister path (path[0] = %s path[1] = %s) which isn't registered",
652 path[0] ? path[0] :
"null",
653 (path[0] && path[1]) ? path[1] :
"null");
664#ifdef DBUS_ENABLE_EMBEDDED_TESTS
669 _dbus_verbose (
"unlock\n");
673 if (unregister_function)
674 (* unregister_function) (connection, user_data);
676#ifdef DBUS_ENABLE_EMBEDDED_TESTS
698 free_subtree_recurse (connection, child);
711 _dbus_object_subtree_unref (subtree);
731 const char **parent_path,
732 char ***child_entries)
740 *child_entries =
NULL;
742 subtree = lookup_subtree (tree, parent_path);
754 while (i < subtree->n_subtrees)
757 if (retval[i] ==
NULL)
769 *child_entries = retval;
770 return retval !=
NULL;
784 const char *v_STRING;
789 already_unlocked =
FALSE;
791 _dbus_verbose (
" considering default Introspect() handler...\n");
799#ifdef DBUS_ENABLE_EMBEDDED_TESTS
803 _dbus_verbose (
"unlock\n");
810 _dbus_verbose (
" using default Introspect() handler!\n");
814#ifdef DBUS_ENABLE_EMBEDDED_TESTS
818 _dbus_verbose (
"unlock\n");
828 if (!_dbus_object_tree_list_registered_unlocked (tree, path, &children))
838 while (children[i] !=
NULL)
855 v_STRING = _dbus_string_get_const_data (&xml);
859#ifdef DBUS_ENABLE_EMBEDDED_TESTS
863 already_unlocked =
TRUE;
872#ifdef DBUS_ENABLE_EMBEDDED_TESTS
876 if (!already_unlocked)
878 _dbus_verbose (
"unlock\n");
918 _dbus_verbose (
"Dispatch of message by object path\n");
924#ifdef DBUS_ENABLE_EMBEDDED_TESTS
928 _dbus_verbose (
"unlock\n");
932 _dbus_verbose (
"No memory to get decomposed path\n");
939#ifdef DBUS_ENABLE_EMBEDDED_TESTS
943 _dbus_verbose (
"unlock\n");
947 _dbus_verbose (
"No path field in message\n");
952 subtree = find_handler (tree, (
const char**) path, &exact_match);
955 *found_object = !!subtree;
961 while (subtree !=
NULL)
965 _dbus_object_subtree_ref (subtree);
971 _dbus_object_subtree_unref (subtree);
972 goto free_and_return;
977 subtree = subtree->
parent;
980 _dbus_verbose (
"%d handlers in the path tree for this message\n",
991 subtree = link->
data;
1005 _dbus_verbose (
" (invoking a handler)\n");
1008#ifdef DBUS_ENABLE_EMBEDDED_TESTS
1012 _dbus_verbose (
"unlock\n");
1021 result = (* message_function) (tree->
connection,
1025#ifdef DBUS_ENABLE_EMBEDDED_TESTS
1031 goto free_and_return;
1043 result = handle_default_introspect_and_unlock (tree, message,
1044 (
const char**) path);
1048#ifdef DBUS_ENABLE_EMBEDDED_TESTS
1052 _dbus_verbose (
"unlock\n");
1057 while (list !=
NULL)
1060 _dbus_object_subtree_unref (link->
data);
1088 subtree = find_handler (tree, (
const char**) path, &exact_match);
1090 if ((subtree ==
NULL) || !exact_match)
1092 _dbus_verbose (
"No object at specified path found\n");
1106allocate_subtree_object (
const char *name)
1114 len = strlen (name);
1118 if (subtree ==
NULL)
1121 memcpy (subtree->
name, name, len + 1);
1127_dbus_object_subtree_new (
const char *name,
1133 subtree = allocate_subtree_object (name);
1134 if (subtree ==
NULL)
1168#ifdef DBUS_DISABLE_ASSERT
1171 dbus_int32_t old_value;
1183 dbus_int32_t old_value;
1210 const char **parent_path,
1211 char ***child_entries)
1215 result = _dbus_object_tree_list_registered_unlocked (tree,
1219#ifdef DBUS_ENABLE_EMBEDDED_TESTS
1223 _dbus_verbose (
"unlock\n");
1232#define VERBOSE_DECOMPOSE 0
1257#if VERBOSE_DECOMPOSE
1258 _dbus_verbose (
"Decomposing path \"%s\"\n",
1275 retval =
dbus_new0 (
char*, n_components + 1);
1281 if (n_components == 0)
1285 while (comp < n_components)
1293 while (j < len && data[j] !=
'/')
1301#if VERBOSE_DECOMPOSE
1302 _dbus_verbose (
" (component in [%d,%d))\n",
1307 if (retval[comp] ==
NULL)
1312 retval[comp][j-i] =
'\0';
1313#if VERBOSE_DECOMPOSE
1314 _dbus_verbose (
" (component %d = \"%s\")\n",
1315 comp, retval[comp]);
1325 *path_len = n_components;
1333flatten_path (
const char **path)
1341 if (path[0] ==
NULL)
1376#ifdef DBUS_ENABLE_EMBEDDED_TESTS
1378#ifndef DOXYGEN_SHOULD_SKIP_THIS
1380#include "dbus-test.h"
1393path_contains (
const char **container,
1399 while (child[i] !=
NULL)
1403 if (container[i] ==
NULL)
1412 v = strcmp (container[i], child[i]);
1415 return STR_DIFFERENT;
1425 if (container[i] ==
NULL)
1428 return STR_DIFFERENT;
1441 _dbus_verbose (
" ");
1445 _dbus_verbose (
"%s (%d children)\n",
1449 while (i < subtree->n_subtrees)
1451 spew_subtree_recurse (subtree->
subtrees[i], indent + 2);
1460 spew_subtree_recurse (tree->
root, 0);
1480 TreeTestData *ttd = user_data;
1482 ttd->handler_unregistered =
TRUE;
1490 TreeTestData *ttd = user_data;
1492 ttd->message_handled =
TRUE;
1502 TreeTestData *tree_test_data)
1505 test_message_function,
NULL };
1507 tree_test_data[i].message_handled =
FALSE;
1508 tree_test_data[i].handler_unregistered =
FALSE;
1509 tree_test_data[i].handler_fallback = fallback;
1510 tree_test_data[i].path = path;
1519 &tree_test_data[i]);
1528 TreeTestData *tree_test_data,
1538 flat = flatten_path (path);
1544 "org.freedesktop.TestInterface",
1547 if (message ==
NULL)
1551 while (j < n_test_data)
1553 tree_test_data[j].message_handled =
FALSE;
1564 while (j < n_test_data)
1566 if (tree_test_data[j].message_handled)
1568 if (tree_test_data[j].handler_fallback)
1570 path) != STR_DIFFERENT);
1572 _dbus_assert (path_contains (tree_test_data[j].path, path) == STR_EQUAL);
1576 if (tree_test_data[j].handler_fallback)
1578 path) == STR_DIFFERENT);
1580 _dbus_assert (path_contains (tree_test_data[j].path, path) != STR_EQUAL);
1599 const char *result[20];
1602static DecomposePathTest decompose_tests[] = {
1603 {
"/foo", {
"foo",
NULL } },
1604 {
"/foo/bar", {
"foo",
"bar",
NULL } },
1606 {
"/a/b", {
"a",
"b",
NULL } },
1607 {
"/a/b/c", {
"a",
"b",
"c",
NULL } },
1608 {
"/a/b/c/d", {
"a",
"b",
"c",
"d",
NULL } },
1609 {
"/foo/bar/q", {
"foo",
"bar",
"q",
NULL } },
1610 {
"/foo/bar/this/is/longer", {
"foo",
"bar",
"this",
"is",
"longer",
NULL } }
1616run_decompose_tests (
void)
1628 strlen (decompose_tests[i].path),
1629 &result, &result_len))
1635 expected_len != result_len ||
1636 path_contains (decompose_tests[i].result,
1637 (
const char**) result) != STR_EQUAL)
1640 _dbus_warn (
"Expected decompose of %s to have len %d, returned %d, appears to have %d",
1641 decompose_tests[i].path, expected_len, result_len,
1643 _dbus_warn (
"Decompose resulted in elements: { ");
1645 while (i < real_len)
1648 (i + 1) == real_len ?
"" :
", ");
1652 _dbus_test_fatal (
"path decompose failed");
1668 _dbus_verbose (
"Looking for exact subtree, registered or unregistered\n");
1677object_tree_test_iteration (
void *data,
1680 const char *path0[] = {
NULL };
1681 const char *path1[] = {
"foo",
NULL };
1682 const char *path2[] = {
"foo",
"bar",
NULL };
1683 const char *path3[] = {
"foo",
"bar",
"baz",
NULL };
1684 const char *path4[] = {
"foo",
"bar",
"boo",
NULL };
1685 const char *path5[] = {
"blah",
NULL };
1686 const char *path6[] = {
"blah",
"boof",
NULL };
1687 const char *path7[] = {
"blah",
"boof",
"this",
"is",
"really",
"long",
NULL };
1688 const char *path8[] = {
"childless",
NULL };
1689 const char *path9[] = {
"blah",
"a",
NULL };
1690 const char *path10[] = {
"blah",
"b",
NULL };
1691 const char *path11[] = {
"blah",
"c",
NULL };
1692 const char *path12[] = {
"blah",
"a",
"d",
NULL };
1693 const char *path13[] = {
"blah",
"b",
"d",
NULL };
1694 const char *path14[] = {
"blah",
"c",
"d",
NULL };
1697 TreeTestData tree_test_data[9];
1701 if (!run_decompose_tests ())
1710 if (!do_register (tree, path0,
TRUE, 0, tree_test_data))
1723 _dbus_assert (find_handler (tree, path0, &exact_match) && exact_match);
1724 _dbus_assert (find_handler (tree, path1, &exact_match) == tree->
root && !exact_match);
1725 _dbus_assert (find_handler (tree, path2, &exact_match) == tree->
root && !exact_match);
1726 _dbus_assert (find_handler (tree, path3, &exact_match) == tree->
root && !exact_match);
1727 _dbus_assert (find_handler (tree, path4, &exact_match) == tree->
root && !exact_match);
1728 _dbus_assert (find_handler (tree, path5, &exact_match) == tree->
root && !exact_match);
1729 _dbus_assert (find_handler (tree, path6, &exact_match) == tree->
root && !exact_match);
1730 _dbus_assert (find_handler (tree, path7, &exact_match) == tree->
root && !exact_match);
1731 _dbus_assert (find_handler (tree, path8, &exact_match) == tree->
root && !exact_match);
1733 if (!do_register (tree, path1,
TRUE, 1, tree_test_data))
1746 _dbus_assert (find_handler (tree, path0, &exact_match) && exact_match);
1747 _dbus_assert (find_handler (tree, path1, &exact_match) && exact_match);
1748 _dbus_assert (find_handler (tree, path2, &exact_match) && !exact_match);
1749 _dbus_assert (find_handler (tree, path3, &exact_match) && !exact_match);
1750 _dbus_assert (find_handler (tree, path4, &exact_match) && !exact_match);
1751 _dbus_assert (find_handler (tree, path5, &exact_match) == tree->
root && !exact_match);
1752 _dbus_assert (find_handler (tree, path6, &exact_match) == tree->
root && !exact_match);
1753 _dbus_assert (find_handler (tree, path7, &exact_match) == tree->
root && !exact_match);
1754 _dbus_assert (find_handler (tree, path8, &exact_match) == tree->
root && !exact_match);
1756 if (!do_register (tree, path2,
TRUE, 2, tree_test_data))
1768 if (!do_register (tree, path3,
TRUE, 3, tree_test_data))
1781 if (!do_register (tree, path4,
TRUE, 4, tree_test_data))
1794 if (!do_register (tree, path5,
TRUE, 5, tree_test_data))
1807 _dbus_assert (find_handler (tree, path0, &exact_match) == tree->
root && exact_match);
1808 _dbus_assert (find_handler (tree, path1, &exact_match) != tree->
root && exact_match);
1809 _dbus_assert (find_handler (tree, path2, &exact_match) != tree->
root && exact_match);
1810 _dbus_assert (find_handler (tree, path3, &exact_match) != tree->
root && exact_match);
1811 _dbus_assert (find_handler (tree, path4, &exact_match) != tree->
root && exact_match);
1812 _dbus_assert (find_handler (tree, path5, &exact_match) != tree->
root && exact_match);
1813 _dbus_assert (find_handler (tree, path6, &exact_match) != tree->
root && !exact_match);
1814 _dbus_assert (find_handler (tree, path7, &exact_match) != tree->
root && !exact_match);
1815 _dbus_assert (find_handler (tree, path8, &exact_match) == tree->
root && !exact_match);
1817 if (!do_register (tree, path6,
TRUE, 6, tree_test_data))
1830 if (!do_register (tree, path7,
TRUE, 7, tree_test_data))
1843 if (!do_register (tree, path8,
TRUE, 8, tree_test_data))
1856 _dbus_assert (find_handler (tree, path0, &exact_match) == tree->
root && exact_match);
1857 _dbus_assert (find_handler (tree, path1, &exact_match) != tree->
root && exact_match);
1858 _dbus_assert (find_handler (tree, path2, &exact_match) != tree->
root && exact_match);
1859 _dbus_assert (find_handler (tree, path3, &exact_match) != tree->
root && exact_match);
1860 _dbus_assert (find_handler (tree, path4, &exact_match) != tree->
root && exact_match);
1861 _dbus_assert (find_handler (tree, path5, &exact_match) != tree->
root && exact_match);
1862 _dbus_assert (find_handler (tree, path6, &exact_match) != tree->
root && exact_match);
1863 _dbus_assert (find_handler (tree, path7, &exact_match) != tree->
root && exact_match);
1864 _dbus_assert (find_handler (tree, path8, &exact_match) != tree->
root && exact_match);
1869 const char *root[] = {
NULL };
1870 char **child_entries;
1873 _dbus_object_tree_list_registered_unlocked (tree, path1, &child_entries);
1874 if (child_entries !=
NULL)
1881 _dbus_object_tree_list_registered_unlocked (tree, path2, &child_entries);
1882 if (child_entries !=
NULL)
1889 _dbus_object_tree_list_registered_unlocked (tree, path8, &child_entries);
1890 if (child_entries !=
NULL)
1897 _dbus_object_tree_list_registered_unlocked (tree, root, &child_entries);
1898 if (child_entries !=
NULL)
1922 if (!do_register (tree, path0,
TRUE, 0, tree_test_data))
1924 if (!do_register (tree, path1,
TRUE, 1, tree_test_data))
1926 if (!do_register (tree, path2,
TRUE, 2, tree_test_data))
1928 if (!do_register (tree, path3,
TRUE, 3, tree_test_data))
1930 if (!do_register (tree, path4,
TRUE, 4, tree_test_data))
1932 if (!do_register (tree, path5,
TRUE, 5, tree_test_data))
1934 if (!do_register (tree, path6,
TRUE, 6, tree_test_data))
1936 if (!do_register (tree, path7,
TRUE, 7, tree_test_data))
1938 if (!do_register (tree, path8,
TRUE, 8, tree_test_data))
2067 if (!do_register (tree, path2,
TRUE, 2, tree_test_data))
2071 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path2));
2072 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path1));
2073 _dbus_assert (find_subtree_registered_or_unregistered (tree, path0));
2077 if (!do_register (tree, path2,
TRUE, 2, tree_test_data))
2081 _dbus_assert (find_subtree_registered_or_unregistered (tree, path1));
2082 _dbus_assert (find_subtree_registered_or_unregistered (tree, path0));
2090 _dbus_assert (find_subtree_registered_or_unregistered (tree, path1));
2091 _dbus_assert (find_subtree_registered_or_unregistered (tree, path0));
2095 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path2));
2096 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path1));
2097 _dbus_assert (find_subtree_registered_or_unregistered (tree, path0));
2102 if (!do_register (tree, path1,
TRUE, 1, tree_test_data))
2104 if (!do_register (tree, path2,
TRUE, 2, tree_test_data))
2113 _dbus_assert (find_subtree_registered_or_unregistered (tree, path1));
2114 _dbus_assert (find_subtree_registered_or_unregistered (tree, path0));
2118 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path1));
2120 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path2));
2121 _dbus_assert (find_subtree_registered_or_unregistered (tree, path0));
2133 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path2));
2134 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path1));
2135 _dbus_assert (find_subtree_registered_or_unregistered (tree, path0));
2138 if (!do_register (tree, path3,
TRUE, 3, tree_test_data))
2143 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path3));
2144 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path2));
2145 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path1));
2146 _dbus_assert (find_subtree_registered_or_unregistered (tree, path0));
2149 if (!do_register (tree, path3,
TRUE, 3, tree_test_data))
2151 if (!do_register (tree, path4,
TRUE, 4, tree_test_data))
2159 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path3));
2161 _dbus_assert (find_subtree_registered_or_unregistered (tree, path4));
2162 _dbus_assert (find_subtree_registered_or_unregistered (tree, path2));
2163 _dbus_assert (find_subtree_registered_or_unregistered (tree, path1));
2167 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path4));
2169 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path3));
2170 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path2));
2171 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path1));
2200 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path12));
2203 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path9));
2204 _dbus_assert (find_subtree_registered_or_unregistered (tree, path5));
2217 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path13));
2219 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path10));
2220 _dbus_assert (find_subtree_registered_or_unregistered (tree, path5));
2234 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path14));
2235 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path11));
2236 _dbus_assert (find_subtree_registered_or_unregistered (tree, path5));
2240 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path12));
2241 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path9));
2242 _dbus_assert (find_subtree_registered_or_unregistered (tree, path5));
2246 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path13));
2247 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path10));
2248 _dbus_assert (!find_subtree_registered_or_unregistered (tree, path5));
2262 if (!do_register (tree, path0,
TRUE, 0, tree_test_data))
2264 if (!do_register (tree, path1,
FALSE, 1, tree_test_data))
2266 if (!do_register (tree, path2,
TRUE, 2, tree_test_data))
2268 if (!do_register (tree, path3,
TRUE, 3, tree_test_data))
2270 if (!do_register (tree, path4,
TRUE, 4, tree_test_data))
2272 if (!do_register (tree, path5,
TRUE, 5, tree_test_data))
2274 if (!do_register (tree, path6,
FALSE, 6, tree_test_data))
2276 if (!do_register (tree, path7,
TRUE, 7, tree_test_data))
2278 if (!do_register (tree, path8,
TRUE, 8, tree_test_data))
2285 if (!do_test_dispatch (tree, path0, 0, tree_test_data,
_DBUS_N_ELEMENTS (tree_test_data)))
2287 if (!do_test_dispatch (tree, path1, 1, tree_test_data,
_DBUS_N_ELEMENTS (tree_test_data)))
2289 if (!do_test_dispatch (tree, path2, 2, tree_test_data,
_DBUS_N_ELEMENTS (tree_test_data)))
2291 if (!do_test_dispatch (tree, path3, 3, tree_test_data,
_DBUS_N_ELEMENTS (tree_test_data)))
2293 if (!do_test_dispatch (tree, path4, 4, tree_test_data,
_DBUS_N_ELEMENTS (tree_test_data)))
2295 if (!do_test_dispatch (tree, path5, 5, tree_test_data,
_DBUS_N_ELEMENTS (tree_test_data)))
2297 if (!do_test_dispatch (tree, path6, 6, tree_test_data,
_DBUS_N_ELEMENTS (tree_test_data)))
2299 if (!do_test_dispatch (tree, path7, 7, tree_test_data,
_DBUS_N_ELEMENTS (tree_test_data)))
2301 if (!do_test_dispatch (tree, path8, 8, tree_test_data,
_DBUS_N_ELEMENTS (tree_test_data)))
2322_dbus_object_tree_test (
const char *test_data_dir _DBUS_GNUC_UNUSED)
2324 return _dbus_test_oom_handling (
"object tree",
2325 object_tree_test_iteration,
dbus_bool_t _dbus_connection_send_and_unlock(DBusConnection *connection, DBusMessage *message, dbus_uint32_t *client_serial)
Like dbus_connection_send(), but assumes the connection is already locked on function entry,...
DBUS_PRIVATE_EXPORT void _dbus_connection_unlock(DBusConnection *connection)
Releases the connection lock.
DBUS_PRIVATE_EXPORT void _dbus_connection_lock(DBusConnection *connection)
Acquires the connection lock.
DBUS_PRIVATE_EXPORT DBusConnection * _dbus_connection_ref_unlocked(DBusConnection *connection)
Increments the reference count of a DBusConnection.
DBusHandlerResult(* DBusObjectPathMessageFunction)(DBusConnection *connection, DBusMessage *message, void *user_data)
Called when a message is sent to a registered object path.
void(* DBusObjectPathUnregisterFunction)(DBusConnection *connection, void *user_data)
Called when a DBusObjectPathVTable is unregistered (or its connection is freed).
void dbus_connection_unref(DBusConnection *connection)
Decrements the reference count of a DBusConnection, and finalizes it if the count reaches zero.
void dbus_set_error(DBusError *error, const char *name, const char *format,...)
Assigns an error name and message to a DBusError.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
char * _dbus_strdup(const char *str)
Duplicates a string.
void _dbus_warn(const char *format,...)
Prints a warning message to stderr.
#define _DBUS_N_ELEMENTS(array)
Computes the number of elements in a fixed-size array using sizeof().
size_t _dbus_string_array_length(const char **array)
Returns the size of a string array.
void * _dbus_memdup(const void *mem, size_t n_bytes)
Duplicates a block of memory.
DBusList * _dbus_list_get_first_link(DBusList **list)
Gets the first link in the list.
void _dbus_list_remove_link(DBusList **list, DBusList *link)
Removes a link from the list.
int _dbus_list_get_length(DBusList **list)
Gets the length of a list.
dbus_bool_t _dbus_list_append(DBusList **list, void *data)
Appends a value to the list.
#define _dbus_list_get_next_link(list, link)
Gets the next link in the list, or NULL if there are no more links.
#define NULL
A null pointer, defined appropriately for C or C++.
#define TRUE
Expands to "1".
#define FALSE
Expands to "0".
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
void * dbus_realloc(void *memory, size_t bytes)
Resizes a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
void * dbus_malloc0(size_t bytes)
Allocates the given number of bytes, as with standard malloc(), but all bytes are initialized to zero...
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
void dbus_free_string_array(char **str_array)
Frees a NULL-terminated array of strings.
dbus_bool_t dbus_message_iter_append_basic(DBusMessageIter *iter, int type, const void *value)
Appends a basic-typed value to the message.
DBusMessage * dbus_message_new_method_return(DBusMessage *method_call)
Constructs a message that is a reply to a method call.
DBusMessage * dbus_message_new_method_call(const char *destination, const char *path, const char *iface, const char *method)
Constructs a new message to invoke a method on a remote object.
void dbus_message_unref(DBusMessage *message)
Decrements the reference count of a DBusMessage, freeing the message if the count reaches 0.
dbus_bool_t dbus_message_is_method_call(DBusMessage *message, const char *iface, const char *method)
Checks whether the message is a method call with the given interface and member fields.
dbus_bool_t dbus_message_get_path_decomposed(DBusMessage *message, char ***path)
Gets the object path this message is being sent to (for DBUS_MESSAGE_TYPE_METHOD_CALL) or being emitt...
void dbus_message_iter_init_append(DBusMessage *message, DBusMessageIter *iter)
Initializes a DBusMessageIter for appending arguments to the end of a message.
void _dbus_object_tree_free_all_unlocked(DBusObjectTree *tree)
Free all the handlers in the tree.
void _dbus_object_tree_unregister_and_unlock(DBusObjectTree *tree, const char **path)
Unregisters an object subtree that was registered with the same path.
void _dbus_object_tree_unref(DBusObjectTree *tree)
Decrement the reference count.
dbus_bool_t _dbus_object_tree_list_registered_and_unlock(DBusObjectTree *tree, const char **parent_path, char ***child_entries)
Lists the registered fallback handlers and object path handlers at the given parent_path.
dbus_bool_t _dbus_decompose_path(const char *data, int len, char ***path, int *path_len)
Decompose an object path.
dbus_bool_t _dbus_object_tree_register(DBusObjectTree *tree, dbus_bool_t fallback, const char **path, const DBusObjectPathVTable *vtable, void *user_data, DBusError *error)
Registers a new subtree in the global object tree.
void * _dbus_object_tree_get_user_data_unlocked(DBusObjectTree *tree, const char **path)
Looks up the data passed to _dbus_object_tree_register() for a handler at the given path.
DBusHandlerResult _dbus_object_tree_dispatch_and_unlock(DBusObjectTree *tree, DBusMessage *message, dbus_bool_t *found_object)
Tries to dispatch a message by directing it to handler for the object path listed in the message head...
DBusObjectTree * _dbus_object_tree_ref(DBusObjectTree *tree)
Increment the reference count.
DBusObjectTree * _dbus_object_tree_new(DBusConnection *connection)
Creates a new object tree, representing a mapping from paths to handler vtables.
#define DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE
XML document type declaration of the introspection format version 1.0.
#define DBUS_ERROR_OBJECT_PATH_IN_USE
There's already an object with the requested object path.
#define DBUS_TYPE_STRING
Type code marking a UTF-8 encoded, nul-terminated Unicode string.
DBusHandlerResult
Results that a message handler can return.
#define DBUS_INTERFACE_INTROSPECTABLE
The interface supported by introspectable objects.
@ DBUS_HANDLER_RESULT_NEED_MEMORY
Need more memory in order to return DBUS_HANDLER_RESULT_HANDLED or DBUS_HANDLER_RESULT_NOT_YET_HANDLE...
@ DBUS_HANDLER_RESULT_HANDLED
Message has had its effect - no need to run more handlers.
@ DBUS_HANDLER_RESULT_NOT_YET_HANDLED
Message has not had any effect - see if other handlers want it.
dbus_bool_t _dbus_string_append(DBusString *str, const char *buffer)
Appends a nul-terminated C-style string to a DBusString.
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
dbus_bool_t _dbus_string_steal_data(DBusString *str, char **data_return)
Like _dbus_string_get_data(), but removes the gotten data from the original string.
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init(), and fills it with the same contents as #_DBUS_STRING_I...
dbus_bool_t _dbus_string_append_byte(DBusString *str, unsigned char byte)
Appends a single byte to the string, returning FALSE if not enough memory.
dbus_bool_t _dbus_string_append_printf(DBusString *str, const char *format,...)
Appends a printf-style formatted string to the DBusString.
dbus_int32_t _dbus_atomic_dec(DBusAtomic *atomic)
Atomically decrement an integer.
dbus_int32_t _dbus_atomic_inc(DBusAtomic *atomic)
Atomically increments an integer.
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
An atomic integer safe to increment or decrement from multiple threads.
Implementation details of DBusConnection.
Object representing an exception.
void * data
Data stored at this element.
DBusMessageIter struct; contains no public fields.
Internals of DBusMessage.
Virtual table that must be implemented to handle a portion of the object path hierarchy.
DBusObjectPathMessageFunction message_function
Function to handle messages.
DBusObjectPathUnregisterFunction unregister_function
Function to unregister this handler.
Struct representing a single registered subtree handler, or node that's a parent of a registered subt...
DBusObjectSubtree * parent
Parent node.
DBusAtomic refcount
Reference count.
DBusObjectPathMessageFunction message_function
Function to handle messages.
DBusObjectPathUnregisterFunction unregister_function
Function to call on unregister.
int n_subtrees
Number of child nodes.
unsigned int invoke_as_fallback
Whether to invoke message_function when child nodes don't handle the message.
int max_subtrees
Number of allocated entries in subtrees.
void * user_data
Data for functions.
char name[1]
Allocated as large as necessary.
DBusObjectSubtree ** subtrees
Child nodes.
Internals of DBusObjectTree.
DBusConnection * connection
Connection this tree belongs to.
int refcount
Reference count.
DBusObjectSubtree * root
Root of the tree ("/" node)