2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2008 Novell, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
27 #include "accessible.h"
30 static guint objindex;
33 deregister_object (gpointer data, GObject *obj)
35 spi_dbus_notify_remove(ATK_OBJECT(obj), NULL);
36 g_hash_table_remove (path2ptr, &obj);
40 register_object (GObject * obj)
46 path2ptr = g_hash_table_new_full (g_int_hash, g_int_equal, g_free, NULL);
51 while (g_hash_table_lookup (path2ptr, &objindex))
54 /* g_object_get_data returning 0 means no data, so handle wrap-around */
58 new_int = (gint *)g_malloc(sizeof(gint));
62 g_hash_table_insert (path2ptr, new_int, obj);
64 g_object_set_data (G_OBJECT (obj), "dbus-id", (gpointer) objindex);
65 g_object_weak_ref(G_OBJECT(obj), deregister_object, NULL);
66 spi_dbus_notify_change(obj, TRUE, NULL);
71 spi_dbus_get_object (const char *path)
77 if (strncmp(path, "/org/freedesktop/atspi/accessible", 33) != 0) return NULL;
78 path += 33; /* skip over preamble */
79 if (path[0] == '\0') return atk_get_root();
80 if (path[0] != '/') return NULL;
83 data = g_hash_table_lookup (path2ptr, &index);
85 return ATK_OBJECT (data);
90 spi_dbus_get_path (AtkObject * obj)
92 if (!obj) return NULL;
93 guint index = (guint) g_object_get_data (G_OBJECT (obj), "dbus-id");
95 index = register_object (obj);
96 return g_strdup_printf ("/org/freedesktop/atspi/accessible/%d", index);
99 /* Reply with the given object and dereference it if unref is TRUE */
101 spi_dbus_return_object (DBusMessage * message, AtkObject * obj, int unref)
104 const char *path = spi_dbus_get_path (obj);
106 g_object_unref (obj);
109 /* Should we have a more specific error for this? */
110 return spi_dbus_general_error (message);
112 reply = dbus_message_new_method_return (message);
115 dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, path,
122 spi_dbus_return_v_object (DBusMessageIter * iter, AtkObject * obj, int unref)
124 const char *path = spi_dbus_get_path (obj);
126 g_object_unref (obj);
129 return droute_return_v_object (iter, path);
133 spi_dbus_initialize (DRouteData * data)
135 spi_initialize_accessible (data);
136 spi_initialize_action(data);
137 spi_initialize_component (data);
138 spi_initialize_document (data);
139 spi_initialize_editabletext (data);
140 spi_initialize_hyperlink (data);
141 spi_initialize_hypertext (data);
142 spi_initialize_image (data);
143 spi_initialize_selection (data);
144 spi_initialize_table (data);
145 spi_initialize_tree (data);
146 spi_initialize_text (data);
147 spi_initialize_value (data);
148 spi_initialize_introspectable(data, (DRouteGetDatumFunction) spi_dbus_get_object);
152 spi_get_tree (AtkObject * obj, GString * str, DRouteData * data)
163 role = spi_accessible_role_from_atk_role (atk_object_get_role (obj));;
164 name = atk_object_get_name (obj);
167 path = spi_dbus_get_path (obj);
168 g_string_append_printf (str,
169 "<object path=\"%s\" name=\"%s\" role=\"%d\">\n",
171 for (l = data->interfaces; l; l = g_slist_next (l))
173 DRouteInterface *iface_def = (DRouteInterface *) l->data;
175 if (iface_def->get_datum)
176 datum = (*iface_def->get_datum) (path, data->user_data);
179 g_string_append_printf (str, "<interface name=\"%s\"/>\n",
181 if (iface_def->free_datum)
182 (*iface_def->free_datum) (datum);
185 childcount = atk_object_get_n_accessible_children (obj);
186 for (i = 0; i < childcount; i++)
188 AtkObject *child = atk_object_ref_accessible_child (obj, i);
189 str = spi_get_tree (child, str, data);
190 g_object_unref (child);
192 str = g_string_append (str, "</object>\n");