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"
41 * This may be modified at run time to support
42 * command parameters for the introspection directory.
44 char *atspi_introspection_directory = ATSPI_DBUS_INTROSPECTION_DIRECTORY;
46 static const char *introspection_header =
47 "<?xml version=\"1.0\"?>\n";
49 static const char *introspection_node_element =
50 "<node name=\"%s\">\n";
52 static const char *introspection_footer =
56 append_interface (GString *str, const char *interface)
64 filename = g_build_filename(introspection_directory, interface);
66 if (g_file_get_contents(filename, &contents, &len, &err))
68 g_string_append_len(str, contents, len);
72 g_warning("AT-SPI: Cannot find introspection XML file %s - %s",
73 filename, err->message);
77 g_string_append(str, "\n");
83 * There is an installation directory with files containing introspection xml.
84 * Each file is named after the interface it describes.
86 * This function finds the names of each interface that the ATK object supports
87 * and mem copies the introspection data from the file into the message.
89 * TODO - There could be some wicked caching here, but probably not neccessary.
92 impl_introspect (DBusConnection *bus, DBusMessage *message,
101 path = dbus_message_get_path(message);
102 object = spi_dbus_get_path(path);
104 output = g_string_new(introspection_header);
106 g_string_append_printf(output, introspection_node_element, path);
108 if (ATK_IS_ACTION (o))
109 append_interface(output, "org.freedesktop.atspi.Action");
111 if (ATK_IS_COMPONENT (o))
112 bonobo_object_add_interface (bonobo_object (retval), BONOBO_OBJECT (spi_component_interface_new (o)));
113 append_interface(output, "org.freedesktop.atspi.Component");
115 if (ATK_IS_EDITABLE_TEXT (o))
116 append_interface(output, "org.freedesktop.atspi.EditableText");
117 else if (ATK_IS_TEXT (o))
118 append_interface(output, "org.freedesktop.atspi.Text");
120 if (ATK_IS_HYPERTEXT (o))
121 bonobo_object_add_interface (bonobo_object (retval), BONOBO_OBJECT (spi_hypertext_interface_new (o)));
122 append_interface(output, "org.freedesktop.atspi.Hypertext");
124 if (ATK_IS_IMAGE (o))
125 bonobo_object_add_interface (bonobo_object (retval), BONOBO_OBJECT (spi_image_interface_new (o)));
126 append_interface(output, "org.freedesktop.atspi.Image");
128 if (ATK_IS_SELECTION (o))
129 bonobo_object_add_interface (bonobo_object (retval), BONOBO_OBJECT (spi_selection_interface_new (o)));
130 append_interface(output, "org.freedesktop.atspi.Selection");
132 if (ATK_IS_TABLE (o))
133 bonobo_object_add_interface (bonobo_object (retval), BONOBO_OBJECT (spi_table_interface_new (o)));
134 append_interface(output, "org.freedesktop.atspi.Table");
136 if (ATK_IS_VALUE (o))
137 append_interface(output, "org.freedesktop.atspi.Value");
139 if (ATK_IS_STREAMABLE_CONTENT (o))
140 append_interface(output, "org.freedesktop.atspi.StreamableContent");
142 if (ATK_IS_DOCUMENT (o))
144 append_interface(output, "org.freedesktop.atspi.Collection");
145 append_interface(output, "org.freedesktop.atspi.Document");
148 if (ATK_IS_HYPERLINK_IMPL (o))
149 append_interface(output, "org.freedesktop.atspi.Hyperlink");
151 g_string_append(introspection_footer);
152 final = g_string_free(output, FALSE);
154 reply = dbus_message_new_method_return (message);
155 g_assert(reply != NULL);
156 dbus_message_append_args(reply, DBUS_TYPE_STRING, &final,
164 static DRouteMethod methods[] = {
165 {impl_introspect, "Introspect"},
170 * Adds the introspectable interface to the DRoute object provided
173 spi_initialize_introspectable (DRouteData *data)
175 droute_add_interface (data, "org.freedesktop.atspi.Accessible",
177 (DRouteGetDatumFunction) spi_dbus_get_path, NULL);