Fix cache update signature
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / adaptors / document-adaptor.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 <atk/atk.h>
26 #include <droute/droute.h>
27
28 #include "common/spi-dbus.h"
29 #include "object.h"
30
31 static DBusMessage *
32 impl_GetLocale (DBusConnection * bus, DBusMessage * message, void *user_data)
33 {
34   AtkDocument *document = (AtkDocument *) user_data;
35   const gchar *lc;
36   DBusMessage *reply;
37
38   g_return_val_if_fail (ATK_IS_DOCUMENT (user_data),
39                         droute_not_yet_handled_error (message));
40   lc = atk_document_get_locale (document);
41   if (!lc)
42     lc = "";
43   reply = dbus_message_new_method_return (message);
44   if (reply)
45     {
46       dbus_message_append_args (reply, DBUS_TYPE_STRING, &lc,
47                                 DBUS_TYPE_INVALID);
48     }
49   return reply;
50 }
51
52 static DBusMessage *
53 impl_GetAttributeValue (DBusConnection * bus, DBusMessage * message,
54                         void *user_data)
55 {
56   AtkDocument *document = (AtkDocument *) user_data;
57   DBusError error;
58   gchar *attributename;
59   const gchar *atr;
60   DBusMessage *reply;
61
62   g_return_val_if_fail (ATK_IS_DOCUMENT (user_data),
63                         droute_not_yet_handled_error (message));
64   dbus_error_init (&error);
65   if (!dbus_message_get_args
66       (message, &error, DBUS_TYPE_STRING, &attributename, DBUS_TYPE_INVALID))
67     {
68       return droute_invalid_arguments_error (message);
69     }
70   atr = atk_document_get_attribute_value (document, attributename);
71   if (!atr)
72     atr = "";
73   reply = dbus_message_new_method_return (message);
74   if (reply)
75     {
76       dbus_message_append_args (reply, DBUS_TYPE_STRING, &atr,
77                                 DBUS_TYPE_INVALID);
78     }
79   return reply;
80 }
81
82 static DBusMessage *
83 impl_GetAttributes (DBusConnection * bus, DBusMessage * message,
84                     void *user_data)
85 {
86   AtkDocument *document = (AtkDocument *) user_data;
87   DBusMessage *reply;
88   AtkAttributeSet *attributes;
89   DBusMessageIter iter;
90
91   g_return_val_if_fail (ATK_IS_DOCUMENT (user_data),
92                         droute_not_yet_handled_error (message));
93
94   attributes = atk_document_get_attributes (document);
95
96   reply = dbus_message_new_method_return (message);
97   if (reply)
98     {
99       dbus_message_iter_init_append (reply, &iter);
100       spi_atk_append_attribute_set (&iter, attributes);
101     }
102
103   if (attributes)
104     atk_attribute_set_free (attributes);
105   return reply;
106 }
107
108 static DRouteMethod methods[] = {
109   {impl_GetLocale, "GetLocale"},
110   {impl_GetAttributeValue, "GetAttributeValue"},
111   {impl_GetAttributes, "GetAttributes"},
112   {NULL, NULL}
113 };
114
115 void
116 spi_initialize_document (DRoutePath * path)
117 {
118   droute_path_add_interface (path,
119                              SPI_DBUS_INTERFACE_DOCUMENT, methods, NULL);
120 };