89a065f6eba95e19a1032a13af59168a3aaec9ba
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / adaptors / 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 "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 data)
41 {
42   /* Make sure it isn't a hyperlink */
43   if (ATK_IS_OBJECT (obj_data))
44     spi_atk_append_accessible (ATK_OBJECT (obj_data), data);
45 }
46
47 /*---------------------------------------------------------------------------*/
48
49 void
50 spi_emit_cache_removal (guint ref, DBusConnection * bus)
51 {
52   DBusMessage *message;
53
54   if ((message = dbus_message_new_signal ("/org/freedesktop/atspi/tree",
55                                           SPI_DBUS_INTERFACE_TREE,
56                                           "RemoveAccessible")))
57     {
58       DBusMessageIter iter;
59       gchar *path;
60
61       dbus_message_iter_init_append (message, &iter);
62
63       path = atk_dbus_ref_to_path (ref);
64       dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &path);
65
66       dbus_connection_send (bus, message, NULL);
67
68       dbus_message_unref (message);
69     }
70 }
71
72 void
73 spi_emit_cache_update (AtkObject * accessible, DBusConnection * bus)
74 {
75   DBusMessage *message;
76
77   if ((message = dbus_message_new_signal ("/org/freedesktop/atspi/tree",
78                                           SPI_DBUS_INTERFACE_TREE,
79                                           "UpdateAccessible")))
80     {
81       DBusMessageIter iter;
82
83       dbus_message_iter_init_append (message, &iter);
84       spi_atk_append_accessible (accessible, &iter);
85
86       dbus_connection_send (bus, message, NULL);
87
88       dbus_message_unref (message);
89     }
90 }
91
92
93 /*---------------------------------------------------------------------------*/
94
95 static DBusMessage *
96 impl_GetRoot (DBusConnection * bus, DBusMessage * message, void *user_data)
97 {
98   AtkObject *root = atk_get_root ();
99   char *path;
100   DBusMessage *reply;
101   gchar *errmsg;
102
103   if (!root)
104     {
105       reply = dbus_message_new_error (message,
106                                       DBUS_ERROR_FAILED,
107                                       "No root accessible available");
108     }
109   path = atk_dbus_object_to_path (root, FALSE);
110   if (!path)
111     {
112       reply = dbus_message_new_error (message,
113                                       DBUS_ERROR_FAILED,
114                                       "No root accessible available");
115     }
116   reply = dbus_message_new_method_return (message);
117   dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &path,
118                             DBUS_TYPE_INVALID);
119   g_free (path);
120   return reply;
121 }
122
123 /*---------------------------------------------------------------------------*/
124
125 static DBusMessage *
126 impl_GetTree (DBusConnection * bus, DBusMessage * message, void *user_data)
127 {
128   DBusMessage *reply;
129   DBusMessageIter iter, iter_array;
130
131   reply = dbus_message_new_method_return (message);
132
133   dbus_message_iter_init_append (reply, &iter);
134   dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY,
135                                     "(o(so)a(so)assusau)", &iter_array);
136   atk_dbus_foreach_registered (append_accessible_hf, &iter_array);
137   dbus_message_iter_close_container (&iter, &iter_array);
138   return reply;
139 }
140
141 /*---------------------------------------------------------------------------*/
142
143 static DRouteMethod methods[] = {
144   {impl_GetRoot, "GetRoot"},
145   {impl_GetTree, "GetTree"},
146   {NULL, NULL}
147 };
148
149 void
150 spi_initialize_tree (DRoutePath * path)
151 {
152   droute_path_add_interface (path, SPI_DBUS_INTERFACE_TREE, methods, NULL);
153 };
154
155 /*END------------------------------------------------------------------------*/