Changes to introspection generation to remove DOCTYPE and XML
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / document.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2008 Novell, Inc.
6  * Copyright 2001, 2002 Sun Microsystems Inc.,
7  * Copyright 2001, 2002 Ximian, Inc.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public
20  * License along with this library; if not, write to the
21  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22  * Boston, MA 02111-1307, USA.
23  */
24
25 #include "accessible.h"
26
27 static AtkDocument *
28 get_document (DBusMessage * message)
29 {
30   AtkObject *obj = spi_dbus_get_object (dbus_message_get_path (message));
31   if (!obj)
32     return NULL;
33   return ATK_DOCUMENT (obj);
34 }
35
36 static AtkDocument *
37 get_document_from_path (const char *path, void *user_data)
38 {
39   AtkObject *obj = spi_dbus_get_object (path);
40   if (!obj || !ATK_IS_DOCUMENT(obj))
41     return NULL;
42   return ATK_DOCUMENT (obj);
43 }
44
45 static DBusMessage *
46 impl_getLocale (DBusConnection * bus, DBusMessage * message, void *user_data)
47 {
48   AtkDocument *document = get_document (message);
49   const gchar *lc;
50   DBusMessage *reply;
51
52   if (!document)
53     return spi_dbus_general_error (message);
54   lc = atk_document_get_locale (document);
55   if (!lc)
56     lc = "";
57   reply = dbus_message_new_method_return (message);
58   if (reply)
59     {
60       dbus_message_append_args (reply, DBUS_TYPE_STRING, &lc,
61                                 DBUS_TYPE_INVALID);
62     }
63   return reply;
64 }
65
66 static DBusMessage *
67 impl_getAttributeValue (DBusConnection * bus, DBusMessage * message,
68                         void *user_data)
69 {
70   AtkDocument *document = get_document (message);
71   DBusError error;
72   gchar *attributename;
73   const gchar *atr;
74   DBusMessage *reply;
75
76   if (!document)
77     return spi_dbus_general_error (message);
78   dbus_error_init (&error);
79   if (!dbus_message_get_args
80       (message, &error, DBUS_TYPE_STRING, &attributename, DBUS_TYPE_INVALID))
81     {
82       return SPI_DBUS_RETURN_ERROR (message, &error);
83     }
84   atr = atk_document_get_attribute_value (document, attributename);
85   if (!atr)
86     atr = "";
87   reply = dbus_message_new_method_return (message);
88   if (reply)
89     {
90       dbus_message_append_args (reply, DBUS_TYPE_STRING, &atr,
91                                 DBUS_TYPE_INVALID);
92     }
93   return reply;
94 }
95
96 static DBusMessage *
97 impl_getAttributes (DBusConnection * bus, DBusMessage * message,
98                     void *user_data)
99 {
100   AtkDocument *document = get_document (message);
101   DBusMessage *reply;
102   AtkAttributeSet *attributes;
103   AtkAttribute *attr = NULL;
104   char **retval;
105   gint n_attributes = 0;
106   gint i;
107
108   if (!document)
109     return spi_dbus_general_error (message);
110
111   attributes = atk_document_get_attributes (document);
112   if (attributes)
113     n_attributes = g_slist_length (attributes);
114
115   retval = (char **) g_malloc (n_attributes * sizeof (char *));
116
117   for (i = 0; i < n_attributes; ++i)
118     {
119       attr = g_slist_nth_data (attributes, i);
120       retval[i] = g_strconcat (attr->name, ":", attr->value, NULL);
121     }
122   if (attributes)
123     atk_attribute_set_free (attributes);
124   reply = dbus_message_new_method_return (message);
125   if (reply)
126     {
127       dbus_message_append_args (reply, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
128                                 &retval, n_attributes, DBUS_TYPE_INVALID);
129     }
130   for (i = 0; i < n_attributes; i++)
131     g_free (retval[i]);
132   g_free (retval);
133   return reply;
134 }
135
136 static DRouteMethod methods[] = {
137   {impl_getLocale, "getLocale"},
138   {impl_getAttributeValue, "getAttributeValue"},
139   {impl_getAttributes, "getAttributes"},
140   {NULL, NULL}
141 };
142
143 void
144 spi_initialize_document (DRouteData * data)
145 {
146   droute_add_interface (data, "org.freedesktop.atspi.Document",
147                         methods, NULL,
148                         (DRouteGetDatumFunction) get_document_from_path,
149                         NULL);
150 };