Changes to introspection generation to remove DOCTYPE and XML
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / 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 <accessible.h>
25
26 #include "droute/droute.h"
27 #include "droute/introspect-loader.h"
28
29 /*
30  * This file contains an implementation of the D-Bus introspectable interface.
31  * For ATK objects.
32  */
33
34 /*
35  * This function finds the names of each interface that the ATK object supports
36  * and appends the introspection XML for each interface.
37  */
38 static DBusMessage *
39 impl_introspect (DBusConnection *bus, DBusMessage *message,
40                  void *user_data)
41 {
42   AtkObject *object;
43   const char *path;
44   GString *output;
45   char *final;
46
47   DBusMessage *reply;
48
49   path = dbus_message_get_path(message);
50   object = spi_dbus_get_object(path);
51
52   output = g_string_new(spi_introspection_header);
53   
54   g_string_append_printf(output, spi_introspection_node_element, path);
55
56   if (ATK_IS_ACTION (object))
57       spi_append_interface(output, "org.freedesktop.atspi.Action");
58
59   if (ATK_IS_COMPONENT (object))
60       spi_append_interface(output, "org.freedesktop.atspi.Component");
61
62   if (ATK_IS_EDITABLE_TEXT (object))
63       spi_append_interface(output, "org.freedesktop.atspi.EditableText");
64   else if (ATK_IS_TEXT (object))
65       spi_append_interface(output, "org.freedesktop.atspi.Text");
66
67   if (ATK_IS_HYPERTEXT (object))
68       spi_append_interface(output, "org.freedesktop.atspi.Hypertext");
69
70   if (ATK_IS_IMAGE (object))
71       spi_append_interface(output, "org.freedesktop.atspi.Image");
72
73   if (ATK_IS_SELECTION (object))
74       spi_append_interface(output, "org.freedesktop.atspi.Selection");
75
76   if (ATK_IS_TABLE (object))
77       spi_append_interface(output, "org.freedesktop.atspi.Table");
78
79   if (ATK_IS_VALUE (object))
80       spi_append_interface(output, "org.freedesktop.atspi.Value");
81
82   if (ATK_IS_STREAMABLE_CONTENT (object))
83       spi_append_interface(output, "org.freedesktop.atspi.StreamableContent");
84
85   if (ATK_IS_DOCUMENT (object))
86     {
87       spi_append_interface(output, "org.freedesktop.atspi.Collection");
88       spi_append_interface(output, "org.freedesktop.atspi.Document");
89     }
90
91   if (ATK_IS_HYPERLINK_IMPL (object))
92       spi_append_interface(output, "org.freedesktop.atspi.Hyperlink");
93
94   g_string_append(output, spi_introspection_footer);
95   final = g_string_free(output, FALSE);
96
97   reply = dbus_message_new_method_return (message);
98   g_assert(reply != NULL);
99   dbus_message_append_args(reply, DBUS_TYPE_STRING, &final,
100                            DBUS_TYPE_INVALID);
101
102   g_free(final);
103   return reply;
104 }
105
106 static DRouteMethod methods[] = {
107   {impl_introspect, "Introspect"},
108   {NULL, NULL}
109 };
110
111 /*
112  * Adds the introspectable interface to the DRoute object provided
113  */
114 void
115 spi_initialize_introspectable (DRouteData *data)
116 {
117   droute_add_interface (data, "org.freedesktop.atspi.Introspectable",
118                         methods, NULL,
119                         (DRouteGetDatumFunction) spi_dbus_get_path, NULL);
120 };