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);
45 static DBusMessage *impl_getActions(DBusConnection *bus, DBusMessage *message, void *user_data)
47 AtkAction *action = get_action(message);
51 DBusMessageIter iter, iter_array, iter_struct;
54 return spi_dbus_general_error (message);
55 count = atk_action_get_n_actions(action);
56 reply = dbus_message_new_method_return (message);
58 dbus_message_iter_init_append (reply, &iter);
59 if (!dbus_message_iter_open_container
60 (&iter, DBUS_TYPE_ARRAY, "(sss)", &iter_array))
62 for (i = 0; i < count; i++)
64 const char *name = atk_action_get_name(action, i);
65 const char *desc = atk_action_get_description(action, i);
66 const char *kb = atk_action_get_keybinding(action, i);
70 if (!dbus_message_iter_open_container(&iter_array, DBUS_TYPE_STRUCT, NULL, &iter_struct)) goto oom;
71 dbus_message_iter_append_basic(&iter_struct, DBUS_TYPE_STRING, &name);
72 dbus_message_iter_append_basic(&iter_struct, DBUS_TYPE_STRING, &desc);
73 dbus_message_iter_append_basic(&iter_struct, DBUS_TYPE_STRING, &kb);
74 if (!dbus_message_iter_close_container(&iter_array, &iter_struct)) goto oom;
76 if (!dbus_message_iter_close_container (&iter, &iter_array))
80 // TODO: handle out-of-memory
84 static DBusMessage *impl_doAction(DBusConnection *bus, DBusMessage *message, void *user_data)
86 AtkAction *action = get_action(message);
93 return spi_dbus_general_error (message);
94 dbus_error_init (&error);
95 if (!dbus_message_get_args
96 (message, &error, DBUS_TYPE_INT32, &index, DBUS_TYPE_INVALID))
98 return SPI_DBUS_RETURN_ERROR (message, &error);
100 rv = atk_action_do_action(action, index);
101 reply = dbus_message_new_method_return (message);
104 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv, DBUS_TYPE_INVALID);
109 DRouteMethod methods[] =
111 {impl_getActions, "getActions"},
112 {impl_doAction, "doAction"},
117 spi_initialize_action (DRouteData * data)
119 droute_add_interface (data, "org.freedesktop.atspi.Action",
121 (DRouteGetDatumFunction) get_action_from_path,