spec file, manifest and gbs.conf adapted for Tizen
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / adaptors / action-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 #include "bridge.h"
28
29 #include "spi-dbus.h"
30
31 #include "introspection.h"
32
33 static dbus_bool_t
34 impl_get_NActions (DBusMessageIter * iter, void *user_data)
35 {
36   AtkAction *action = (AtkAction *) user_data;
37
38   g_return_val_if_fail (ATK_IS_ACTION (user_data), FALSE);
39   return droute_return_v_int32 (iter, atk_action_get_n_actions (action));
40 }
41
42 static DBusMessage *
43 impl_get_description (DBusConnection * bus, DBusMessage * message,
44                       void *user_data)
45 {
46   AtkAction *action = (AtkAction *) user_data;
47   DBusMessage *reply;
48   dbus_int32_t index;
49   const char *desc;
50
51   g_return_val_if_fail (ATK_IS_ACTION (user_data),
52                         droute_not_yet_handled_error (message));
53   if (!dbus_message_get_args
54       (message, NULL, DBUS_TYPE_INT32, &index, DBUS_TYPE_INVALID))
55     {
56       return droute_invalid_arguments_error (message);
57     }
58   desc = atk_action_get_description (action, index);
59   if (!desc)
60     desc = "";
61   reply = dbus_message_new_method_return (message);
62   if (reply)
63     {
64       dbus_message_append_args (reply, DBUS_TYPE_STRING, &desc,
65                                 DBUS_TYPE_INVALID);
66     }
67   return reply;
68 }
69
70 static DBusMessage *
71 impl_get_name (DBusConnection * bus, DBusMessage * message, void *user_data)
72 {
73   DBusMessage *reply;
74   dbus_int32_t index;
75   const char *name;
76   AtkAction *action = (AtkAction *) user_data;
77
78   g_return_val_if_fail (ATK_IS_ACTION (user_data),
79                         droute_not_yet_handled_error (message));
80   if (!dbus_message_get_args
81       (message, NULL, DBUS_TYPE_INT32, &index, DBUS_TYPE_INVALID))
82     {
83       return droute_invalid_arguments_error (message);
84     }
85   name = atk_action_get_name (action, index);
86   if (!name)
87     name = "";
88   reply = dbus_message_new_method_return (message);
89   if (reply)
90     {
91       dbus_message_append_args (reply, DBUS_TYPE_STRING, &name,
92                                 DBUS_TYPE_INVALID);
93     }
94   return reply;
95 }
96
97 static DBusMessage *
98 impl_get_localized_name (DBusConnection * bus, DBusMessage * message, void *user_data)
99 {
100   DBusMessage *reply;
101   dbus_int32_t index;
102   const char *name;
103   AtkAction *action = (AtkAction *) user_data;
104
105   g_return_val_if_fail (ATK_IS_ACTION (user_data),
106                         droute_not_yet_handled_error (message));
107   if (!dbus_message_get_args
108       (message, NULL, DBUS_TYPE_INT32, &index, DBUS_TYPE_INVALID))
109     {
110       return droute_invalid_arguments_error (message);
111     }
112   name = atk_action_get_localized_name (action, index);
113   if (!name)
114     name = "";
115   reply = dbus_message_new_method_return (message);
116   if (reply)
117     {
118       dbus_message_append_args (reply, DBUS_TYPE_STRING, &name,
119                                 DBUS_TYPE_INVALID);
120     }
121   return reply;
122 }
123
124 static DBusMessage *
125 impl_get_keybinding (DBusConnection * bus, DBusMessage * message,
126                      void *user_data)
127 {
128   DBusMessage *reply;
129   dbus_int32_t index;
130   const char *kb;
131   AtkAction *action = (AtkAction *) user_data;
132
133   g_return_val_if_fail (ATK_IS_ACTION (user_data),
134                         droute_not_yet_handled_error (message));
135   if (!dbus_message_get_args
136       (message, NULL, DBUS_TYPE_INT32, &index, DBUS_TYPE_INVALID))
137     {
138       return droute_invalid_arguments_error (message);
139     }
140   kb = atk_action_get_keybinding (action, index);
141   if (!kb)
142     kb = "";
143   reply = dbus_message_new_method_return (message);
144   if (reply)
145     {
146       dbus_message_append_args (reply, DBUS_TYPE_STRING, &kb,
147                                 DBUS_TYPE_INVALID);
148     }
149   return reply;
150 }
151
152 static DBusMessage *
153 impl_GetActions (DBusConnection * bus, DBusMessage * message, void *user_data)
154 {
155   AtkAction *action = (AtkAction *) user_data;
156   DBusMessage *reply;
157   gint count;
158   gint i;
159   DBusMessageIter iter, iter_array, iter_struct;
160
161   g_return_val_if_fail (ATK_IS_ACTION (user_data),
162                         droute_not_yet_handled_error (message));
163   count = atk_action_get_n_actions (action);
164   reply = dbus_message_new_method_return (message);
165   if (!reply)
166     goto oom;
167   dbus_message_iter_init_append (reply, &iter);
168   if (!dbus_message_iter_open_container
169       (&iter, DBUS_TYPE_ARRAY, "(sss)", &iter_array))
170     goto oom;
171   for (i = 0; i < count; i++)
172     {
173       const char *name = atk_action_get_name (action, i);
174       const char *lname = atk_action_get_localized_name (action, i);
175       const char *desc = atk_action_get_description (action, i);
176       const char *kb = atk_action_get_keybinding (action, i);
177       if (!name)
178         name = "";
179       if (!lname)
180         lname = "";
181       if (!desc)
182         desc = "";
183       if (!kb)
184         kb = "";
185       if (!dbus_message_iter_open_container
186           (&iter_array, DBUS_TYPE_STRUCT, NULL, &iter_struct))
187         goto oom;
188       dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &name);
189       dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &lname);
190       dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &desc);
191       dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &kb);
192       if (!dbus_message_iter_close_container (&iter_array, &iter_struct))
193         goto oom;
194     }
195   if (!dbus_message_iter_close_container (&iter, &iter_array))
196     goto oom;
197   return reply;
198 oom:
199   // TODO: handle out-of-memory
200   return reply;
201 }
202
203 static DBusMessage *
204 impl_DoAction (DBusConnection * bus, DBusMessage * message, void *user_data)
205 {
206   AtkAction *action = (AtkAction *) user_data;
207   dbus_int32_t index;
208   dbus_bool_t rv = TRUE;
209   DBusMessage *reply;
210
211   g_return_val_if_fail (ATK_IS_ACTION (user_data),
212                         droute_not_yet_handled_error (message));
213   if (!dbus_message_get_args
214       (message, NULL, DBUS_TYPE_INT32, &index, DBUS_TYPE_INVALID))
215     {
216       return droute_invalid_arguments_error (message);
217     }
218   reply = dbus_message_new_method_return (message);
219   if (reply)
220     {
221       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
222                                 DBUS_TYPE_INVALID);
223     }
224   dbus_connection_send (bus, reply, NULL);
225   dbus_message_unref (reply);
226   atk_action_do_action (action, index);
227   return NULL;
228 }
229
230 DRouteMethod methods[] = {
231   {impl_get_description, "GetDescription"}
232   ,
233   {impl_get_name, "GetName"}
234   ,
235   {impl_get_localized_name, "GetLocalizedName"}
236   ,
237   {impl_get_keybinding, "GetKeyBinding"}
238   ,
239   {impl_GetActions, "GetActions"}
240   ,
241   {impl_DoAction, "DoAction"}
242   ,
243   {NULL, NULL}
244 };
245
246 static DRouteProperty properties[] = {
247   {impl_get_NActions, NULL, "NActions"},
248   {NULL, NULL}
249 };
250
251 void
252 spi_initialize_action (DRoutePath * path)
253 {
254   spi_atk_add_interface (path,
255                              ATSPI_DBUS_INTERFACE_ACTION,
256                              spi_org_a11y_atspi_Action, methods, properties);
257 };