2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2008 Novell, Inc.
6 * Copyright 2001, 2002 Sun Microsystems Inc.,
7 * Copyright 2001, 2002 Ximian, Inc.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
25 #include "accessible.h"
27 #define get_object(message) spi_dbus_get_object(dbus_message_get_path(message))
30 spi_dbus_append_tree_helper (DBusMessageIter * iter_array, AtkObject * obj,
33 DBusMessageIter iter_struct, iter_sub, iter_sub_array;
35 const char *name, *desc;
36 dbus_uint16_t updating = 1;
43 dbus_message_iter_open_container (iter_array, DBUS_TYPE_STRUCT, NULL,
45 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_UINT16, &updating);
46 path = spi_dbus_get_path (obj);
47 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH, &path);
48 dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_STRUCT, NULL,
50 dbus_message_iter_open_container (&iter_sub, DBUS_TYPE_ARRAY, "o",
52 childcount = atk_object_get_n_accessible_children (obj);
53 for (i = 0; i < childcount; i++)
55 AtkObject *child = atk_object_ref_accessible_child (obj, i);
56 char *child_path = spi_dbus_get_path (child);
59 dbus_message_iter_append_basic (&iter_sub_array,
60 DBUS_TYPE_OBJECT_PATH, &child_path);
64 g_object_unref (child);
66 if (!dbus_message_iter_close_container (&iter_sub, &iter_sub_array))
68 dbus_message_iter_open_container (&iter_sub, DBUS_TYPE_ARRAY, "s",
70 for (l = data->interfaces; l; l = g_slist_next (l))
72 DRouteInterface *iface_def = (DRouteInterface *) l->data;
74 if (iface_def->get_datum)
76 datum = (*iface_def->get_datum) (path, data->user_data);
80 dbus_message_iter_append_basic (&iter_sub_array, DBUS_TYPE_STRING,
82 if (iface_def->free_datum)
83 (*iface_def->free_datum) (datum);
85 if (!dbus_message_iter_close_container (&iter_sub, &iter_sub_array))
87 name = atk_object_get_name (obj);
90 dbus_message_iter_append_basic (&iter_sub, DBUS_TYPE_STRING, &name);
91 role = spi_accessible_role_from_atk_role (atk_object_get_role (obj));
92 dbus_message_iter_append_basic (&iter_sub, DBUS_TYPE_UINT32, &role);
93 desc = atk_object_get_description (obj);
96 dbus_message_iter_append_basic (&iter_sub, DBUS_TYPE_STRING, &desc);
97 if (!dbus_message_iter_close_container (&iter_struct, &iter_sub))
99 if (!dbus_message_iter_close_container (iter_array, &iter_struct))
101 for (i = 0; i < childcount; i++)
103 AtkObject *child = atk_object_ref_accessible_child (obj, i);
107 result = spi_dbus_append_tree_helper (iter_array, child, data);
108 g_object_unref (child);
115 if (path) g_free(path);
120 spi_dbus_append_tree (DBusMessage * message, AtkObject * obj,
123 DBusMessageIter iter, iter_array;
126 dbus_message_iter_init_append (message, &iter);
127 dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "(qo(aoassus))",
129 result = spi_dbus_append_tree_helper (&iter_array, obj, data);
131 result = dbus_message_iter_close_container (&iter, &iter_array);
136 impl_getTree (DBusConnection * bus, DBusMessage * message, void *user_data)
142 root = atk_get_root ();
144 path = spi_dbus_get_path (root);
146 return spi_dbus_general_error (message);
147 reply = dbus_message_new_method_return (message);
148 dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &path,
151 spi_dbus_append_tree (reply, root, (DRouteData *) user_data);
155 static DRouteMethod methods[] = {
156 {DROUTE_METHOD, impl_getTree, "getTree", "o,root,o:a(go(aoassus)),tree,o",
158 {0, NULL, NULL, NULL}
162 spi_initialize_tree (DRouteData * data)
164 droute_add_interface (data, "org.freedesktop.atspi.AccessibleTree",
165 methods, NULL, NULL, NULL);