2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2008 Novell, Inc.
6 * Copyright 2001, 2002 Sun Microsystems Inc.,
7 * Copyright 2001, 2002 Ximian, Inc.
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.
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.
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.
25 #include "accessible.h"
28 get_action (DBusMessage * message)
30 AtkObject *obj = spi_dbus_get_object (dbus_message_get_path (message));
33 return ATK_ACTION (obj);
37 get_action_from_path (const char *path, void *user_data)
39 AtkObject *obj = spi_dbus_get_object (path);
40 if (!obj || !ATK_IS_ACTION(obj))
42 return ATK_ACTION (obj);
46 impl_get_nActions (const char *path, DBusMessageIter *iter, void *user_data)
48 AtkAction *action = get_action_from_path (path, user_data);
51 return droute_return_v_int32 (iter, atk_action_get_n_actions (action));
55 impl_get_description (DBusConnection *bus, DBusMessage *message, void *user_data)
60 AtkAction *action = get_action (message);
62 if (!action) return spi_dbus_general_error (message);
63 if (!dbus_message_get_args (message, NULL, DBUS_TYPE_INT32, &index, DBUS_TYPE_INVALID))
65 return spi_dbus_general_error (message);
67 desc = atk_action_get_description(action, index);
69 reply = dbus_message_new_method_return (message);
72 dbus_message_append_args (reply, DBUS_TYPE_STRING, &desc, DBUS_TYPE_INVALID);
78 impl_get_name (DBusConnection *bus, DBusMessage *message, void *user_data)
83 AtkAction *action = get_action (message);
85 if (!action) return spi_dbus_general_error (message);
86 if (!dbus_message_get_args (message, NULL, DBUS_TYPE_INT32, &index, DBUS_TYPE_INVALID))
88 return spi_dbus_general_error (message);
90 name = atk_action_get_name(action, index);
92 reply = dbus_message_new_method_return (message);
95 dbus_message_append_args (reply, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID);
101 impl_get_keybinding (DBusConnection *bus, DBusMessage *message, void *user_data)
106 AtkAction *action = get_action (message);
108 if (!action) return spi_dbus_general_error (message);
109 if (!dbus_message_get_args (message, NULL, DBUS_TYPE_INT32, &index, DBUS_TYPE_INVALID))
111 return spi_dbus_general_error (message);
113 kb = atk_action_get_keybinding(action, index);
115 reply = dbus_message_new_method_return (message);
118 dbus_message_append_args (reply, DBUS_TYPE_STRING, &kb, DBUS_TYPE_INVALID);
123 static DBusMessage *impl_getActions(DBusConnection *bus, DBusMessage *message, void *user_data)
125 AtkAction *action = get_action(message);
129 DBusMessageIter iter, iter_array, iter_struct;
132 return spi_dbus_general_error (message);
133 count = atk_action_get_n_actions(action);
134 reply = dbus_message_new_method_return (message);
135 if (!reply) goto oom;
136 dbus_message_iter_init_append (reply, &iter);
137 if (!dbus_message_iter_open_container
138 (&iter, DBUS_TYPE_ARRAY, "(sss)", &iter_array))
140 for (i = 0; i < count; i++)
142 const char *name = atk_action_get_name(action, i);
143 const char *desc = atk_action_get_description(action, i);
144 const char *kb = atk_action_get_keybinding(action, i);
145 if (!name) name = "";
146 if (!desc) desc = "";
148 if (!dbus_message_iter_open_container(&iter_array, DBUS_TYPE_STRUCT, NULL, &iter_struct)) goto oom;
149 dbus_message_iter_append_basic(&iter_struct, DBUS_TYPE_STRING, &name);
150 dbus_message_iter_append_basic(&iter_struct, DBUS_TYPE_STRING, &desc);
151 dbus_message_iter_append_basic(&iter_struct, DBUS_TYPE_STRING, &kb);
152 if (!dbus_message_iter_close_container(&iter_array, &iter_struct)) goto oom;
154 if (!dbus_message_iter_close_container (&iter, &iter_array))
158 // TODO: handle out-of-memory
162 static DBusMessage *impl_doAction(DBusConnection *bus, DBusMessage *message, void *user_data)
164 AtkAction *action = get_action(message);
171 return spi_dbus_general_error (message);
172 dbus_error_init (&error);
173 if (!dbus_message_get_args
174 (message, &error, DBUS_TYPE_INT32, &index, DBUS_TYPE_INVALID))
176 return SPI_DBUS_RETURN_ERROR (message, &error);
178 rv = atk_action_do_action(action, index);
179 reply = dbus_message_new_method_return (message);
182 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv, DBUS_TYPE_INVALID);
187 DRouteMethod methods[] =
189 { impl_get_description, "getDescription" },
190 { impl_get_name, "getName" },
191 { impl_get_keybinding, "getKeyBinding" },
192 {impl_getActions, "getActions"},
193 {impl_doAction, "doAction"},
197 static DRouteProperty properties[] =
199 { impl_get_nActions, NULL, "nActions" },
204 spi_initialize_action (DRouteData * data)
206 droute_add_interface (data, SPI_DBUS_INTERFACE_ACTION,
208 (DRouteGetDatumFunction) get_action_from_path,