Remove unused functions
[platform/core/uifw/at-spi2-atk.git] / libspi / introspectable.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2008 Codethink Ltd.
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 #include <glib.h>
24 #include <dbus.h>
25
26 #include "droute.h"
27
28 /*
29  * This file contains an implementation of the D-Bus introspectable interface.
30  * For ATK objects.
31  */
32
33 /*
34  * Provides the dist install path for the introspection directory.
35  */
36 #if !defined ATSPI_DBUS_INTROSPECTION_DIRECTORY
37     #error "No introspection XML directory defined"
38 #endif
39
40 char *spi_introspection_directory = ATSPI_DBUS_INTROSPECTION_DIRECTORY;
41
42 static const char *introspection_header =
43 "<?xml version=\"1.0\"?>\n";
44
45 static const char *introspection_node_element =
46 "<node name=\"%s\">\n";
47
48 static const char *introspection_footer =
49 "</node>";
50
51 void
52 spi_initialize_introspectable (DRouteData *data);
53
54 static void
55 append_interface (GString *str, const char *interface)
56 {
57   char *filename;
58   char *contents;
59   gsize len;
60
61   GError *err = NULL;
62
63   filename = g_build_filename(spi_introspection_directory, interface, NULL);
64
65   if (g_file_get_contents(filename, &contents, &len, &err))
66     {
67       g_string_append_len(str, contents, len);
68     }
69   else
70     {
71       g_warning("AT-SPI: Cannot find introspection XML file %s - %s",
72                 filename, err->message);
73       g_error_free(err);
74     }
75
76   g_string_append(str, "\n");
77   g_free(filename);
78   g_free(contents);
79 }
80
81 /*
82  * There is an installation directory with files containing introspection xml.
83  * Each file is named after the interface it describes.
84  *
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.
87  *
88  * TODO - There could be some wicked caching here, but probably not neccessary.
89  */
90 static DBusMessage *
91 impl_introspect (DBusConnection *bus, DBusMessage *message,
92                  void *user_data)
93 {
94   AtkObject *object;
95   const char *path;
96   GString *output;
97   char *final;
98
99   DBusMessage *reply;
100
101   path = dbus_message_get_path(message);
102   object = spi_dbus_get_object(path);
103
104   output = g_string_new(introspection_header);
105   
106   g_string_append_printf(output, introspection_node_element, path);
107
108   if (ATK_IS_ACTION (object))
109       append_interface(output, "org.freedesktop.atspi.Action");
110
111   if (ATK_IS_COMPONENT (object))
112       append_interface(output, "org.freedesktop.atspi.Component");
113
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");
118
119   if (ATK_IS_HYPERTEXT (object))
120       append_interface(output, "org.freedesktop.atspi.Hypertext");
121
122   if (ATK_IS_IMAGE (object))
123       append_interface(output, "org.freedesktop.atspi.Image");
124
125   if (ATK_IS_SELECTION (object))
126       append_interface(output, "org.freedesktop.atspi.Selection");
127
128   if (ATK_IS_TABLE (object))
129       append_interface(output, "org.freedesktop.atspi.Table");
130
131   if (ATK_IS_VALUE (object))
132       append_interface(output, "org.freedesktop.atspi.Value");
133
134   if (ATK_IS_STREAMABLE_CONTENT (object))
135       append_interface(output, "org.freedesktop.atspi.StreamableContent");
136
137   if (ATK_IS_DOCUMENT (object))
138     {
139       append_interface(output, "org.freedesktop.atspi.Collection");
140       append_interface(output, "org.freedesktop.atspi.Document");
141     }
142
143   if (ATK_IS_HYPERLINK_IMPL (object))
144       append_interface(output, "org.freedesktop.atspi.Hyperlink");
145
146   g_string_append(output, introspection_footer);
147   final = g_string_free(output, FALSE);
148
149   reply = dbus_message_new_method_return (message);
150   g_assert(reply != NULL);
151   dbus_message_append_args(reply, DBUS_TYPE_STRING, &final,
152                            DBUS_TYPE_INVALID);
153
154   g_free(final);
155   return reply;
156 }
157
158 static DRouteMethod methods[] = {
159   {impl_introspect, "Introspect"},
160   {NULL, NULL}
161 };
162
163 /*
164  * Adds the introspectable interface to the DRoute object provided
165  */
166 void
167 spi_initialize_introspectable (DRouteData *data)
168 {
169   droute_add_interface (data, "org.freedesktop.atspi.Accessible",
170                         methods, NULL,
171                         (DRouteGetDatumFunction) spi_dbus_get_path, NULL);
172 };