2008-12-07 Mark Doffman <mark.doffman@codethink.co.uk>
[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   spi_append_interface(output, SPI_DBUS_INTERFACE_ACCESSIBLE);
57
58   if (ATK_IS_ACTION (object))
59       spi_append_interface(output, SPI_DBUS_INTERFACE_ACTION);
60
61   if (ATK_IS_COMPONENT (object))
62       spi_append_interface(output, SPI_DBUS_INTERFACE_COMPONENT);
63
64   if (ATK_IS_EDITABLE_TEXT (object))
65       spi_append_interface(output, SPI_DBUS_INTERFACE_EDITABLE_TEXT);
66
67   if (ATK_IS_TEXT (object))
68       spi_append_interface(output, SPI_DBUS_INTERFACE_TEXT);
69
70   if (ATK_IS_HYPERTEXT (object))
71       spi_append_interface(output, SPI_DBUS_INTERFACE_HYPERTEXT);
72
73   if (ATK_IS_IMAGE (object))
74       spi_append_interface(output, SPI_DBUS_INTERFACE_IMAGE);
75
76   if (ATK_IS_SELECTION (object))
77       spi_append_interface(output, SPI_DBUS_INTERFACE_SELECTION);
78
79   if (ATK_IS_TABLE (object))
80       spi_append_interface(output, SPI_DBUS_INTERFACE_TABLE);
81
82   if (ATK_IS_VALUE (object))
83       spi_append_interface(output, SPI_DBUS_INTERFACE_VALUE);
84
85   if (ATK_IS_STREAMABLE_CONTENT (object))
86       spi_append_interface(output, "org.freedesktop.atspi.StreamableContent");
87
88   if (ATK_IS_DOCUMENT (object))
89     {
90       spi_append_interface(output, "org.freedesktop.atspi.Collection");
91       spi_append_interface(output, SPI_DBUS_INTERFACE_DOCUMENT);
92     }
93
94   if (ATK_IS_HYPERLINK_IMPL (object))
95       spi_append_interface(output, SPI_DBUS_INTERFACE_HYPERLINK);
96
97   g_string_append(output, spi_introspection_footer);
98   final = g_string_free(output, FALSE);
99
100   reply = dbus_message_new_method_return (message);
101   g_assert(reply != NULL);
102   dbus_message_append_args(reply, DBUS_TYPE_STRING, &final,
103                            DBUS_TYPE_INVALID);
104
105   g_free(final);
106   return reply;
107 }
108
109 static DRouteMethod methods[] = {
110   {impl_introspect, "Introspect"},
111   {NULL, NULL}
112 };
113
114 /*
115  * Adds the introspectable interface to the DRoute object provided
116  */
117 void
118 spi_initialize_introspectable (DRouteData *data, DRouteGetDatumFunction verify_object)
119 {
120   droute_add_interface (data, "org.freedesktop.DBus.Introspectable",
121                         methods, NULL,
122                         verify_object, NULL);
123 };