Make a new traversal function. Modify tree-adaptor
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / tree-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  * Copyright 2008, 2009 Codethink Ltd.
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the
22  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23  * Boston, MA 02111-1307, USA.
24  */
25
26 #include <string.h>
27
28 #include <atk/atk.h>
29 #include <droute/droute.h>
30
31 #include "bridge.h"
32 #include "accessible-register.h"
33 #include "accessible-marshaller.h"
34 #include "spi-common/spi-dbus.h"
35
36 /*---------------------------------------------------------------------------*/
37
38 /* For use as a GHFunc */
39 static void
40 append_accessible_hf (gpointer key, gpointer obj_data, gpointer iter)
41 {
42   spi_atk_append_accessible (ATK_OBJECT(obj_data), iter);
43 }
44
45 /*---------------------------------------------------------------------------*/
46
47 void
48 spi_emit_cache_removal (guint ref,  DBusConnection *bus)
49 {
50   DBusMessage *message;
51   DBusMessageIter iter;
52   gchar *path;
53
54   message = dbus_message_new_signal ("/org/freedesktop/atspi/tree", SPI_DBUS_INTERFACE_TREE, "removeAccessible");
55
56   dbus_message_iter_init_append (message, &iter);
57
58   path = atk_dbus_ref_to_path (ref);
59   dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &path);
60
61   dbus_connection_send(bus, message, NULL);
62 }
63
64 void
65 spi_emit_cache_update (AtkObject *accessible, DBusConnection *bus)
66 {
67    DBusMessage *message;
68    DBusMessageIter iter;
69    message = dbus_message_new_signal ("/org/freedesktop/atspi/tree", SPI_DBUS_INTERFACE_TREE, "updateAccessible");
70
71    dbus_message_iter_init_append (message, &iter);
72    spi_atk_append_accessible (accessible, &iter);
73
74    dbus_connection_send(bus, message, NULL);
75 }
76
77
78 /*---------------------------------------------------------------------------*/
79
80 static DBusMessage *
81 impl_getRoot (DBusConnection *bus, DBusMessage *message, void *user_data)
82 {
83   AtkObject *root = atk_get_root();
84   char *path;
85   DBusMessage *reply;
86
87   if (!root)
88       return spi_dbus_general_error (message);
89   path = atk_dbus_object_to_path (root);
90   if (!path)
91       return spi_dbus_general_error (message);
92   reply = dbus_message_new_method_return (message);
93   dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID);
94   g_free (path);
95   return reply;
96 }
97
98 /*---------------------------------------------------------------------------*/
99
100 static DBusMessage *
101 impl_getTree (DBusConnection *bus, DBusMessage *message, void *user_data)
102 {
103   DBusMessage *reply;
104   DBusMessageIter iter, iter_array;
105
106   reply = dbus_message_new_method_return (message);
107
108   dbus_message_iter_init_append (reply, &iter);
109   dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(ooaoassusau)", &iter_array);
110   atk_dbus_foreach_registered(append_accessible_hf, &iter_array);
111   dbus_message_iter_close_container(&iter, &iter_array);
112   return reply;
113 }
114
115 /*---------------------------------------------------------------------------*/
116
117 static DRouteMethod methods[] = {
118   {impl_getRoot, "getRoot"},
119   {impl_getTree, "getTree"},
120   {NULL, NULL}
121 };
122
123 void
124 spi_initialize_tree (DRoutePath *path)
125 {
126   droute_path_add_interface (path,
127                              SPI_DBUS_INTERFACE_TREE,
128                              methods,
129                              NULL);
130 };
131
132 /*END------------------------------------------------------------------------*/