2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2008 Codethink Ltd.
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.
29 * This file contains an implementation of the D-Bus introspectable interface.
34 * Provides the dist install path for the introspection directory.
36 #if !defined ATSPI_DBUS_INTROSPECTION_DIRECTORY
37 #error "No introspection XML directory defined"
40 char *spi_introspection_directory = ATSPI_DBUS_INTROSPECTION_DIRECTORY;
42 static const char *introspection_header =
43 "<?xml version=\"1.0\"?>\n";
45 static const char *introspection_node_element =
46 "<node name=\"%s\">\n";
48 static const char *introspection_footer =
52 spi_initialize_introspectable (DRouteData *data);
55 append_interface (GString *str, const char *interface)
63 filename = g_build_filename(spi_introspection_directory, interface, NULL);
65 if (g_file_get_contents(filename, &contents, &len, &err))
67 g_string_append_len(str, contents, len);
71 g_warning("AT-SPI: Cannot find introspection XML file %s - %s",
72 filename, err->message);
76 g_string_append(str, "\n");
82 * There is an installation directory with files containing introspection xml.
83 * Each file is named after the interface it describes.
85 * This function finds the names of each interface that the ATK object supports
86 * and mem copies the introspection data from the file into the message.
88 * TODO - There could be some wicked caching here, but probably not neccessary.
91 impl_introspect (DBusConnection *bus, DBusMessage *message,
101 path = dbus_message_get_path(message);
102 object = spi_dbus_get_object(path);
104 output = g_string_new(introspection_header);
106 g_string_append_printf(output, introspection_node_element, path);
108 if (ATK_IS_ACTION (object))
109 append_interface(output, "org.freedesktop.atspi.Action");
111 if (ATK_IS_COMPONENT (object))
112 append_interface(output, "org.freedesktop.atspi.Component");
114 if (ATK_IS_EDITABLE_TEXT (object))
115 append_interface(output, "org.freedesktop.atspi.EditableText");
116 else if (ATK_IS_TEXT (object))
117 append_interface(output, "org.freedesktop.atspi.Text");
119 if (ATK_IS_HYPERTEXT (object))
120 append_interface(output, "org.freedesktop.atspi.Hypertext");
122 if (ATK_IS_IMAGE (object))
123 append_interface(output, "org.freedesktop.atspi.Image");
125 if (ATK_IS_SELECTION (object))
126 append_interface(output, "org.freedesktop.atspi.Selection");
128 if (ATK_IS_TABLE (object))
129 append_interface(output, "org.freedesktop.atspi.Table");
131 if (ATK_IS_VALUE (object))
132 append_interface(output, "org.freedesktop.atspi.Value");
134 if (ATK_IS_STREAMABLE_CONTENT (object))
135 append_interface(output, "org.freedesktop.atspi.StreamableContent");
137 if (ATK_IS_DOCUMENT (object))
139 append_interface(output, "org.freedesktop.atspi.Collection");
140 append_interface(output, "org.freedesktop.atspi.Document");
143 if (ATK_IS_HYPERLINK_IMPL (object))
144 append_interface(output, "org.freedesktop.atspi.Hyperlink");
146 g_string_append(output, introspection_footer);
147 final = g_string_free(output, FALSE);
149 reply = dbus_message_new_method_return (message);
150 g_assert(reply != NULL);
151 dbus_message_append_args(reply, DBUS_TYPE_STRING, &final,
158 static DRouteMethod methods[] = {
159 {impl_introspect, "Introspect"},
164 * Adds the introspectable interface to the DRoute object provided
167 spi_initialize_introspectable (DRouteData *data)
169 droute_add_interface (data, "org.freedesktop.atspi.Accessible",
171 (DRouteGetDatumFunction) spi_dbus_get_path, NULL);