2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2008, 2009 Codethink Ltd.
6 * Copyright 2001, 2002, 2003 Sun Microsystems Inc.,
7 * Copyright 2001, 2002, 2003 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.
29 #include <X11/Xatom.h>
38 #include <droute/droute.h>
40 #include <atspi/atspi.h>
46 #include "accessible-stateset.h"
48 #include "accessible-register.h"
49 #include "accessible-leasing.h"
50 #include "accessible-cache.h"
54 /*---------------------------------------------------------------------------*/
56 static DBusHandlerResult
57 signal_filter (DBusConnection *bus, DBusMessage *message, void *user_data);
59 SpiBridge *spi_global_app_data = NULL;
61 /*static Display *bridge_display = NULL;*/
63 /*---------------------------------------------------------------------------*/
66 * Returns a 'canonicalized' value for DISPLAY,
67 * with the screen number stripped off if present.
71 spi_display_name (void)
73 static const char *canonical_display_name = NULL;
74 if (!canonical_display_name)
76 const gchar *display_env = g_getenv ("AT_SPI_DISPLAY");
79 display_env = g_getenv ("DISPLAY");
80 if (!display_env || !display_env[0])
81 canonical_display_name = ":0";
84 gchar *display_p, *screen_p;
85 canonical_display_name = g_strdup (display_env);
86 display_p = strrchr (canonical_display_name, ':');
87 screen_p = strrchr (canonical_display_name, '.');
88 if (screen_p && display_p && (screen_p > display_p))
96 canonical_display_name = display_env;
99 return canonical_display_name;
102 /*---------------------------------------------------------------------------*/
105 set_reply (DBusPendingCall *pending, void *user_data)
107 void **replyptr = (void **)user_data;
109 *replyptr = dbus_pending_call_steal_reply (pending);
110 dbus_pending_call_unref (pending);
113 /*---------------------------------------------------------------------------*/
116 add_event (const char *bus_name, const char *event)
122 spi_atk_add_client (bus_name);
123 evdata = (event_data *) g_malloc (sizeof (*evdata));
126 data = g_strsplit (event, ":", 3);
132 evdata->bus_name = g_strdup (bus_name);
134 new_list = g_list_append (spi_global_app_data->events, evdata);
136 spi_global_app_data->events = new_list;
139 static GSList *clients = NULL;
144 static int replies_received = 0;
147 if (replies_received == 3)
150 spi_atk_deregister_event_listeners ();
151 spi_global_app_data->events_initialized = TRUE;
156 get_events_reply (DBusPendingCall *pending, void *user_data)
158 DBusMessage *reply = dbus_pending_call_steal_reply (pending);
159 DBusMessageIter iter, iter_array, iter_struct;
164 if (strcmp (dbus_message_get_signature (reply), "a(ss)") != 0)
166 g_warning ("atk-bridge: GetRegisteredEvents returned message with unknown signature");
170 dbus_message_iter_init (reply, &iter);
171 dbus_message_iter_recurse (&iter, &iter_array);
172 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
174 char *bus_name, *event;
175 dbus_message_iter_recurse (&iter_array, &iter_struct);
176 dbus_message_iter_get_basic (&iter_struct, &bus_name);
177 dbus_message_iter_next (&iter_struct);
178 dbus_message_iter_get_basic (&iter_struct, &event);
179 add_event (bus_name, event);
180 dbus_message_iter_next (&iter_array);
185 dbus_message_unref (reply);
187 dbus_pending_call_unref (pending);
189 tally_event_reply ();
193 get_device_events_reply (DBusPendingCall *pending, void *user_data)
195 DBusMessage *reply = dbus_pending_call_steal_reply (pending);
196 DBusMessageIter iter, iter_array, iter_struct;
201 if (strncmp (dbus_message_get_signature (reply), "a(s", 3) != 0)
203 g_warning ("atk-bridge: get_device_events_reply: unknown signature");
207 dbus_message_iter_init (reply, &iter);
208 dbus_message_iter_recurse (&iter, &iter_array);
209 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
212 dbus_message_iter_recurse (&iter_array, &iter_struct);
213 dbus_message_iter_get_basic (&iter_struct, &bus_name);
214 spi_atk_add_client (bus_name);
215 dbus_message_iter_next (&iter_array);
220 dbus_message_unref (reply);
222 dbus_pending_call_unref (pending);
224 tally_event_reply ();
228 get_registered_event_listeners (SpiBridge *app)
230 DBusMessage *message;
231 DBusPendingCall *pending = NULL;
233 message = dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
234 ATSPI_DBUS_PATH_REGISTRY,
235 ATSPI_DBUS_INTERFACE_REGISTRY,
236 "GetRegisteredEvents");
240 dbus_connection_send_with_reply (app->bus, message, &pending, -1);
241 dbus_message_unref (message);
244 spi_global_app_data->events_initialized = TRUE;
247 dbus_pending_call_set_notify (pending, get_events_reply, NULL, NULL);
249 message = dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
251 ATSPI_DBUS_INTERFACE_DEC,
252 "GetKeystrokeListeners");
256 dbus_connection_send_with_reply (app->bus, message, &pending, -1);
257 dbus_message_unref (message);
260 spi_global_app_data->events_initialized = TRUE;
263 dbus_pending_call_set_notify (pending, get_device_events_reply, NULL, NULL);
265 message = dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
267 ATSPI_DBUS_INTERFACE_DEC,
268 "GetDeviceEventListeners");
272 dbus_connection_send_with_reply (app->bus, message, &pending, -1);
273 dbus_message_unref (message);
276 spi_global_app_data->events_initialized = TRUE;
279 dbus_pending_call_set_notify (pending, get_device_events_reply, NULL, NULL);
283 register_reply (DBusPendingCall *pending, void *user_data)
286 SpiBridge *app = user_data;
287 DBusMessage *message;
289 reply = dbus_pending_call_steal_reply (pending);
290 dbus_pending_call_unref (pending);
293 gchar *app_name, *obj_path;
295 if (strcmp (dbus_message_get_signature (reply), "(so)") != 0)
297 g_warning ("AT-SPI: Could not obtain desktop path or name\n");
301 DBusMessageIter iter, iter_struct;
302 dbus_message_iter_init (reply, &iter);
303 dbus_message_iter_recurse (&iter, &iter_struct);
304 dbus_message_iter_get_basic (&iter_struct, &app_name);
305 dbus_message_iter_next (&iter_struct);
306 dbus_message_iter_get_basic (&iter_struct, &obj_path);
308 app->desktop_name = g_strdup (app_name);
309 app->desktop_path = g_strdup (obj_path);
314 g_warning ("AT-SPI: Could not embed inside desktop");
317 dbus_message_unref (reply);
319 get_registered_event_listeners (spi_global_app_data);
323 register_application (SpiBridge * app)
325 DBusMessage *message, *reply;
326 DBusMessageIter iter;
328 DBusPendingCall *pending;
329 const int max_addr_length = 128; /* should be long enough */
331 dbus_error_init (&error);
333 /* These will be overridden when we get a reply, but in practice these
334 defaults should always be correct */
335 app->desktop_name = ATSPI_DBUS_NAME_REGISTRY;
336 app->desktop_path = ATSPI_DBUS_PATH_ROOT;
338 message = dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
339 ATSPI_DBUS_PATH_ROOT,
340 ATSPI_DBUS_INTERFACE_SOCKET,
343 dbus_message_iter_init_append (message, &iter);
344 spi_object_append_reference (&iter, app->root);
346 if (!dbus_connection_send_with_reply (app->bus, message, &pending, -1)
352 dbus_pending_call_set_notify (pending, register_reply, app, NULL);
355 dbus_message_unref (message);
357 /* could this be better, we accept some amount of race in getting the temp name*/
358 /* make sure the directory exists */
359 mkdir ("/tmp/at-spi2/", S_IRWXU|S_IRWXG|S_IRWXO|S_ISVTX);
360 chmod ("/tmp/at-spi2/", S_IRWXU|S_IRWXG|S_IRWXO|S_ISVTX);
361 app->app_bus_addr = g_malloc(max_addr_length * sizeof(char));
363 sprintf (app->app_bus_addr, "unix:path=/tmp/at-spi2/socket-%d-%d", getpid(),
366 app->app_bus_addr [0] = '\0';
372 /*---------------------------------------------------------------------------*/
375 deregister_application (SpiBridge * app)
377 DBusMessage *message;
378 DBusMessageIter iter;
382 dbus_error_init (&error);
384 message = dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
385 ATSPI_DBUS_PATH_REGISTRY,
386 ATSPI_DBUS_INTERFACE_REGISTRY,
387 "DeregisterApplication");
388 dbus_message_set_no_reply (message, TRUE);
390 uname = dbus_bus_get_unique_name (app->bus);
392 dbus_message_iter_init_append (message, &iter);
393 dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &uname);
394 dbus_connection_send (app->bus, message, NULL);
396 dbus_message_unref (message);
399 /*---------------------------------------------------------------------------*/
401 /*---------------------------------------------------------------------------*/
403 static AtkPlugClass *plug_class;
404 static AtkSocketClass *socket_class;
407 get_plug_id (AtkPlug * plug)
409 const char *uname = dbus_bus_get_unique_name (spi_global_app_data->bus);
411 GString *str = g_string_new (NULL);
413 path = spi_register_object_to_path (spi_global_register, G_OBJECT (plug));
414 g_string_printf (str, "%s:%s", uname, path);
416 return g_string_free (str, FALSE);
420 socket_ref_state_set (AtkObject *accessible)
422 char *child_name, *child_path;
423 AtkSocket *socket = ATK_SOCKET (accessible);
427 DBusMessage *message, *reply;
428 DBusMessageIter iter, iter_array;
431 set = atk_state_set_new ();
433 if (!socket->embedded_plug_id)
436 child_name = g_strdup (socket->embedded_plug_id);
439 child_path = g_utf8_strchr (child_name + 1, -1, ':');
445 *(child_path++) = '\0';
446 message = dbus_message_new_method_call (child_name, child_path, ATSPI_DBUS_INTERFACE_ACCESSIBLE, "GetState");
448 reply = dbus_connection_send_with_reply_and_block (spi_global_app_data->bus, message, 1, NULL);
449 dbus_message_unref (message);
452 if (strcmp (dbus_message_get_signature (reply), "au") != 0)
454 dbus_message_unref (reply);
458 dbus_message_iter_init (reply, &iter);
459 dbus_message_iter_recurse (&iter, &iter_array);
462 dbus_message_iter_get_basic (&iter_array, &v);
463 for (j = 0; j < 32; j++)
467 AtkState state = spi_atk_state_from_spi_state ((count << 5) + j);
468 atk_state_set_add_state (set, state);
473 while (dbus_message_iter_next (&iter_array));
474 dbus_message_unref (reply);
479 socket_embed_hook (AtkSocket * socket, gchar * plug_id)
481 AtkObject *accessible = ATK_OBJECT(socket);
482 gchar *plug_name, *plug_path;
483 AtkObjectClass *klass;
485 /* Force registration */
486 gchar *path = spi_register_object_to_path (spi_global_register, G_OBJECT (accessible));
487 /* Let the plug know that it has been embedded */
488 plug_name = g_strdup (plug_id);
494 plug_path = g_utf8_strchr (plug_name + 1, -1, ':');
497 DBusMessage *message;
498 *(plug_path++) = '\0';
499 message = dbus_message_new_method_call (plug_name, plug_path, ATSPI_DBUS_INTERFACE_SOCKET, "Embedded");
500 dbus_message_append_args (message, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID);
501 dbus_connection_send (spi_global_app_data->bus, message, NULL);
506 klass = ATK_OBJECT_GET_CLASS (accessible);
507 klass->ref_state_set = socket_ref_state_set;
511 install_plug_hooks ()
515 data = g_type_class_ref (ATK_TYPE_PLUG);
516 plug_class = ATK_PLUG_CLASS (data);
517 data = g_type_class_ref (ATK_TYPE_SOCKET);
518 socket_class = ATK_SOCKET_CLASS (data);
519 plug_class->get_object_id = get_plug_id;
520 socket_class->embed = socket_embed_hook;
524 get_ancestral_uid (uint pid)
530 gboolean got_ppid = 0;
531 gboolean got_uid = 0;
533 sprintf (buf, "/proc/%d/status", pid);
534 fp = fopen (buf, "r");
537 while ((!got_ppid || !got_uid) && fgets (buf, sizeof (buf), fp))
539 if (sscanf (buf, "PPid:\t%d", &ppid) == 1)
541 else if (sscanf (buf, "Uid:\t%d", &uid) == 1)
546 if (!got_ppid || !got_uid)
550 if (ppid == 0 || ppid == 1)
552 return get_ancestral_uid (ppid);
556 user_check (DBusConnection *bus, unsigned long uid, void *data)
558 if (uid == getuid () || uid == geteuid ())
561 return get_ancestral_uid (getpid ()) == uid;
566 new_connection_cb (DBusServer *server, DBusConnection *con, void *data)
570 dbus_connection_set_unix_user_function (con, user_check, NULL, NULL);
571 dbus_connection_ref(con);
572 atspi_dbus_connection_setup_with_g_main(con, NULL);
573 droute_intercept_dbus (con);
574 droute_context_register (spi_global_app_data->droute, con);
576 spi_global_app_data->direct_connections = g_list_append (spi_global_app_data->direct_connections, con);
586 dbus_error_init(&err);
587 server = dbus_server_listen(spi_global_app_data->app_bus_addr, &err);
590 g_warning ("atk-bridge: Couldn't listen on dbus server: %s", err.message);
591 dbus_error_init (&err);
592 spi_global_app_data->app_bus_addr [0] = '\0';
593 g_main_context_unref (spi_global_app_data->main_context);
594 spi_global_app_data->main_context = NULL;
598 atspi_dbus_server_setup_with_g_main(server, NULL);
599 dbus_server_set_new_connection_function(server, new_connection_cb, NULL, NULL);
601 spi_global_app_data->server = server;
608 gchar *atspi_dbus_name = NULL;
609 static gboolean atspi_no_register = FALSE;
611 static GOptionEntry atspi_option_entries[] = {
612 {"atspi-dbus-name", 0, 0, G_OPTION_ARG_STRING, &atspi_dbus_name,
613 "D-Bus bus name to register as", NULL},
614 {"atspi-no-register", 0, 0, G_OPTION_ARG_NONE, &atspi_no_register,
615 "Do not register with Registry Daemon", NULL},
620 introspect_children_cb (const char *path, void *data)
622 if (!strcmp (path, "/org/a11y/atspi/accessible"))
624 return g_strdup ("<node name=\"root\"/>\n");
625 /* TODO: Should we place the whole hierarchy here? */
631 handle_event_listener_registered (DBusConnection *bus, DBusMessage *message,
637 if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &sender,
638 DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID))
641 add_event (sender, name);
645 remove_events (const char *bus_name, const char *event)
651 remove_data = g_strsplit (event, ":", 3);
657 for (list = spi_global_app_data->events; list;)
659 event_data *evdata = list->data;
660 if (!g_strcmp0 (evdata->bus_name, bus_name) &&
661 spi_event_is_subtype (evdata->data, remove_data))
663 GList *events = spi_global_app_data->events;
665 g_strfreev (evdata->data);
666 g_free (evdata->bus_name);
668 spi_global_app_data->events = g_list_remove (events, evdata);
676 g_strfreev (remove_data);
680 handle_event_listener_deregistered (DBusConnection *bus, DBusMessage *message,
683 const char *orig_name;
687 if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &sender,
688 DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID))
691 remove_events (sender, name);
695 handle_device_listener_registered (DBusConnection *bus, DBusMessage *message,
699 DBusMessageIter iter, iter_struct;
701 if (strncmp (dbus_message_get_signature (message), "(s", 2) != 0)
703 g_warning ("atk-bridge: handle_device_listener_register: unknown signature");
707 dbus_message_iter_init (message, &iter);
708 dbus_message_iter_recurse (&iter, &iter_struct);
709 dbus_message_iter_get_basic (&iter_struct, &sender);
710 spi_atk_add_client (sender);
713 static DBusHandlerResult
714 signal_filter (DBusConnection *bus, DBusMessage *message, void *user_data)
716 const char *interface = dbus_message_get_interface (message);
717 const char *member = dbus_message_get_member (message);
718 DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
720 if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_SIGNAL)
721 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
723 if (!strcmp (interface, ATSPI_DBUS_INTERFACE_REGISTRY))
725 result = DBUS_HANDLER_RESULT_HANDLED;
726 if (!strcmp (member, "EventListenerRegistered"))
727 handle_event_listener_registered (bus, message, user_data);
728 else if (!strcmp (member, "EventListenerDeregistered"))
729 handle_event_listener_deregistered (bus, message, user_data);
731 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
733 else if (!strcmp (interface, ATSPI_DBUS_INTERFACE_DEVICE_EVENT_LISTENER))
735 result = DBUS_HANDLER_RESULT_HANDLED;
736 if (!strcmp (member, "KeystrokeListenerRegistered"))
737 handle_device_listener_registered (bus, message, user_data);
738 else if (!strcmp (member, "DeviceListenerRegistered"))
739 handle_device_listener_registered (bus, message, user_data);
741 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
744 if (!g_strcmp0(interface, DBUS_INTERFACE_DBUS) &&
745 !g_strcmp0(member, "NameOwnerChanged"))
747 char *name, *old, *new;
748 result = DBUS_HANDLER_RESULT_HANDLED;
749 if (dbus_message_get_args (message, NULL,
750 DBUS_TYPE_STRING, &name,
751 DBUS_TYPE_STRING, &old,
752 DBUS_TYPE_STRING, &new,
755 if (*old != '\0' && *new == '\0')
756 spi_atk_remove_client (old);
766 * The following needs to be initialized.
768 * - DRoute for routing message to their accessible objects.
769 * - Event handlers for emmitting signals on specific ATK events.
770 * - setup the bus for p2p communication
771 * - Application registration with the AT-SPI registry.
775 adaptor_init (gint * argc, gchar ** argv[])
781 gchar *introspection_directory;
782 static gboolean inited = FALSE;
789 DRoutePath *treepath, *accpath;
791 root = atk_get_root ();
792 g_warn_if_fail (root);
799 /* Parse command line options */
800 opt = g_option_context_new (NULL);
801 g_option_context_add_main_entries (opt, atspi_option_entries, NULL);
802 g_option_context_set_ignore_unknown_options (opt, TRUE);
803 if (!g_option_context_parse (opt, argc, argv, &err))
804 g_warning ("AT-SPI Option parsing failed: %s\n", err->message);
805 g_option_context_free (opt);
807 /* Allocate global data and do ATK initializations */
808 spi_global_app_data = g_new0 (SpiBridge, 1);
809 spi_global_app_data->root = g_object_ref (root);
811 /* Set up D-Bus connection and register bus name */
812 dbus_error_init (&error);
813 spi_global_app_data->bus = atspi_get_a11y_bus ();
814 if (!spi_global_app_data->bus)
816 g_free (spi_global_app_data);
817 spi_global_app_data = NULL;
822 if (atspi_dbus_name != NULL)
824 if (dbus_bus_request_name
825 (spi_global_app_data->bus, atspi_dbus_name, 0, &error))
827 g_print ("AT-SPI Recieved D-Bus name - %s\n", atspi_dbus_name);
832 ("AT-SPI D-Bus name requested but could not be allocated - %s\n",
837 spi_global_app_data->main_context = g_main_context_new ();
839 atspi_dbus_connection_setup_with_g_main (spi_global_app_data->bus, NULL);
841 /* Hook our plug-and socket functions */
842 install_plug_hooks ();
845 * Create the leasing, register and cache objects.
846 * The order is important here, the cache depends on the
849 spi_global_register = g_object_new (SPI_REGISTER_TYPE, NULL);
850 spi_global_leasing = g_object_new (SPI_LEASING_TYPE, NULL);
851 spi_global_cache = g_object_new (SPI_CACHE_TYPE, NULL);
853 /* Register droute for routing AT-SPI messages */
854 spi_global_app_data->droute =
857 treepath = droute_add_one (spi_global_app_data->droute,
858 "/org/a11y/atspi/cache", spi_global_cache);
862 g_warning ("atk-bridge: Error in droute_add_one(). Already running?");
866 accpath = droute_add_many (spi_global_app_data->droute,
867 "/org/a11y/atspi/accessible",
869 introspect_children_cb,
871 (DRouteGetDatumFunction)
872 spi_global_register_path_to_object);
875 /* Register all interfaces with droute and set up application accessible db */
876 spi_initialize_cache (treepath);
877 spi_initialize_accessible (accpath);
878 spi_initialize_application (accpath);
879 spi_initialize_action (accpath);
880 spi_initialize_collection (accpath);
881 spi_initialize_component (accpath);
882 spi_initialize_document (accpath);
883 spi_initialize_editabletext (accpath);
884 spi_initialize_hyperlink (accpath);
885 spi_initialize_hypertext (accpath);
886 spi_initialize_image (accpath);
887 spi_initialize_selection (accpath);
888 spi_initialize_socket (accpath);
889 spi_initialize_table (accpath);
890 spi_initialize_text (accpath);
891 spi_initialize_value (accpath);
893 droute_context_register (spi_global_app_data->droute,
894 spi_global_app_data->bus);
896 /* Register methods to send D-Bus signals on certain ATK events */
897 spi_atk_register_event_listeners ();
899 /* Set up filter and match rules to catch signals */
900 dbus_bus_add_match (spi_global_app_data->bus, "type='signal', interface='org.a11y.atspi.Registry', sender='org.a11y.atspi.Registry'", NULL);
901 dbus_bus_add_match (spi_global_app_data->bus, "type='signal', interface='org.a11y.atspi.DeviceEventListener', sender='org.a11y.atspi.Registry'", NULL);
902 dbus_connection_add_filter (spi_global_app_data->bus, signal_filter, NULL,
905 /* Register this app by sending a signal out to AT-SPI registry daemon */
906 if (!atspi_no_register && (!root || !ATK_IS_PLUG (root)))
907 register_application (spi_global_app_data);
909 get_registered_event_listeners (spi_global_app_data);
916 /*---------------------------------------------------------------------------*/
919 gtk_module_init (gint * argc, gchar ** argv[])
921 const gchar *load_bridge = g_getenv ("NO_AT_BRIDGE");
923 if (!load_bridge || g_ascii_strtod (load_bridge, NULL) == 0)
925 return adaptor_init (argc, argv);
931 g_module_check_init (GModule *module)
933 g_module_make_resident (module);
939 gnome_accessibility_module_init (void)
941 const gchar *load_bridge = g_getenv ("NO_AT_BRIDGE");
943 if (!load_bridge || g_ascii_strtod (load_bridge, NULL) == 0)
945 adaptor_init (NULL, NULL);
947 if (g_getenv ("AT_SPI_DEBUG"))
949 g_print ("Atk Accessibility bridge initialized\n");
955 gnome_accessibility_module_shutdown (void)
960 if (!spi_global_app_data)
963 spi_atk_tidy_windows ();
964 spi_atk_deregister_event_listeners ();
966 deregister_application (spi_global_app_data);
968 if (spi_global_app_data->bus)
970 dbus_connection_remove_filter (spi_global_app_data->bus, signal_filter, NULL);
971 droute_context_unregister (spi_global_app_data->droute, spi_global_app_data->bus);
972 dbus_connection_unref (spi_global_app_data->bus);
975 for (l = spi_global_app_data->direct_connections; l; l = l->next)
977 DBusConnection *connection;
979 connection = l->data;
981 droute_context_unregister (spi_global_app_data->droute, connection);
982 droute_unintercept_dbus (connection);
983 dbus_connection_unref (connection);
985 g_list_free (spi_global_app_data->direct_connections);
987 for (ls = clients; ls; ls = ls->next)
989 g_slist_free (clients);
992 g_object_unref (spi_global_cache);
993 g_object_unref (spi_global_leasing);
994 g_object_unref (spi_global_register);
996 if (spi_global_app_data->main_context)
997 g_main_context_unref (spi_global_app_data->main_context);
999 droute_free (spi_global_app_data->droute);
1001 g_free (spi_global_app_data);
1002 spi_global_app_data = NULL;
1004 /* Not currently creating an XDisplay */
1007 XCloseDisplay (bridge_display);
1011 static gchar *name_match_tmpl =
1012 "type='signal', interface='org.freedesktop.DBus', member='NameOwnerChanged', arg0='%s'";
1015 spi_atk_add_client (const char *bus_name)
1020 for (l = clients; l; l = l->next)
1022 if (!g_strcmp0 (l->data, bus_name))
1025 if (!clients && spi_global_app_data->events_initialized)
1026 spi_atk_register_event_listeners ();
1027 clients = g_slist_append (clients, g_strdup (bus_name));
1028 match = g_strdup_printf (name_match_tmpl, bus_name);
1029 dbus_bus_add_match (spi_global_app_data->bus, match, NULL);
1034 spi_atk_remove_client (const char *bus_name)
1042 next_node = l->next;
1044 if (!g_strcmp0 (l->data, bus_name))
1046 gchar *match = g_strdup_printf (name_match_tmpl, l->data);
1047 dbus_bus_remove_match (spi_global_app_data->bus, match, NULL);
1050 clients = g_slist_delete_link (clients, l);
1052 spi_atk_deregister_event_listeners ();
1059 /*END------------------------------------------------------------------------*/