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 <glib/gi18n.h>
41 #include <atspi/atspi.h>
47 #include "accessible-stateset.h"
49 #include "accessible-register.h"
50 #include "accessible-leasing.h"
51 #include "accessible-cache.h"
55 /*---------------------------------------------------------------------------*/
57 static DBusHandlerResult
58 signal_filter (DBusConnection *bus, DBusMessage *message, void *user_data);
60 SpiBridge *spi_global_app_data = NULL;
62 /*static Display *bridge_display = NULL;*/
64 /*---------------------------------------------------------------------------*/
67 * Returns a 'canonicalized' value for DISPLAY,
68 * with the screen number stripped off if present.
72 spi_display_name (void)
74 static const char *canonical_display_name = NULL;
75 if (!canonical_display_name)
77 const gchar *display_env = g_getenv ("AT_SPI_DISPLAY");
80 display_env = g_getenv ("DISPLAY");
81 if (!display_env || !display_env[0])
82 canonical_display_name = ":0";
85 gchar *display_p, *screen_p;
86 canonical_display_name = g_strdup (display_env);
87 display_p = strrchr (canonical_display_name, ':');
88 screen_p = strrchr (canonical_display_name, '.');
89 if (screen_p && display_p && (screen_p > display_p))
97 canonical_display_name = display_env;
100 return canonical_display_name;
103 /*---------------------------------------------------------------------------*/
106 set_reply (DBusPendingCall *pending, void *user_data)
108 void **replyptr = (void **)user_data;
110 *replyptr = dbus_pending_call_steal_reply (pending);
111 dbus_pending_call_unref (pending);
114 /*---------------------------------------------------------------------------*/
117 add_event (const char *bus_name, const char *event)
123 spi_atk_add_client (bus_name);
124 evdata = (event_data *) g_malloc (sizeof (*evdata));
127 data = g_strsplit (event, ":", 3);
133 evdata->bus_name = g_strdup (bus_name);
135 new_list = g_list_append (spi_global_app_data->events, evdata);
137 spi_global_app_data->events = new_list;
140 static GSList *clients = NULL;
145 static int replies_received = 0;
148 if (replies_received == 3)
151 spi_atk_deregister_event_listeners ();
152 spi_global_app_data->events_initialized = TRUE;
157 get_events_reply (DBusPendingCall *pending, void *user_data)
159 DBusMessage *reply = dbus_pending_call_steal_reply (pending);
160 DBusMessageIter iter, iter_array, iter_struct;
165 if (strcmp (dbus_message_get_signature (reply), "a(ss)") != 0)
167 g_warning ("atk-bridge: GetRegisteredEvents returned message with unknown signature");
171 dbus_message_iter_init (reply, &iter);
172 dbus_message_iter_recurse (&iter, &iter_array);
173 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
175 char *bus_name, *event;
176 dbus_message_iter_recurse (&iter_array, &iter_struct);
177 dbus_message_iter_get_basic (&iter_struct, &bus_name);
178 dbus_message_iter_next (&iter_struct);
179 dbus_message_iter_get_basic (&iter_struct, &event);
180 add_event (bus_name, event);
181 dbus_message_iter_next (&iter_array);
186 dbus_message_unref (reply);
188 dbus_pending_call_unref (pending);
190 tally_event_reply ();
194 get_device_events_reply (DBusPendingCall *pending, void *user_data)
196 DBusMessage *reply = dbus_pending_call_steal_reply (pending);
197 DBusMessageIter iter, iter_array, iter_struct;
202 if (strncmp (dbus_message_get_signature (reply), "a(s", 3) != 0)
204 g_warning ("atk-bridge: get_device_events_reply: unknown signature");
208 dbus_message_iter_init (reply, &iter);
209 dbus_message_iter_recurse (&iter, &iter_array);
210 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
213 dbus_message_iter_recurse (&iter_array, &iter_struct);
214 dbus_message_iter_get_basic (&iter_struct, &bus_name);
215 spi_atk_add_client (bus_name);
216 dbus_message_iter_next (&iter_array);
221 dbus_message_unref (reply);
223 dbus_pending_call_unref (pending);
225 tally_event_reply ();
229 get_registered_event_listeners (SpiBridge *app)
231 DBusMessage *message;
232 DBusPendingCall *pending = NULL;
234 message = dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
235 ATSPI_DBUS_PATH_REGISTRY,
236 ATSPI_DBUS_INTERFACE_REGISTRY,
237 "GetRegisteredEvents");
241 dbus_connection_send_with_reply (app->bus, message, &pending, -1);
242 dbus_message_unref (message);
245 spi_global_app_data->events_initialized = TRUE;
248 dbus_pending_call_set_notify (pending, get_events_reply, NULL, NULL);
250 message = dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
252 ATSPI_DBUS_INTERFACE_DEC,
253 "GetKeystrokeListeners");
257 dbus_connection_send_with_reply (app->bus, message, &pending, -1);
258 dbus_message_unref (message);
261 spi_global_app_data->events_initialized = TRUE;
264 dbus_pending_call_set_notify (pending, get_device_events_reply, NULL, NULL);
266 message = dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
268 ATSPI_DBUS_INTERFACE_DEC,
269 "GetDeviceEventListeners");
273 dbus_connection_send_with_reply (app->bus, message, &pending, -1);
274 dbus_message_unref (message);
277 spi_global_app_data->events_initialized = TRUE;
280 dbus_pending_call_set_notify (pending, get_device_events_reply, NULL, NULL);
284 register_reply (DBusPendingCall *pending, void *user_data)
287 SpiBridge *app = user_data;
288 DBusMessage *message;
290 reply = dbus_pending_call_steal_reply (pending);
291 dbus_pending_call_unref (pending);
294 gchar *app_name, *obj_path;
296 if (strcmp (dbus_message_get_signature (reply), "(so)") != 0)
298 g_warning ("AT-SPI: Could not obtain desktop path or name\n");
302 DBusMessageIter iter, iter_struct;
303 dbus_message_iter_init (reply, &iter);
304 dbus_message_iter_recurse (&iter, &iter_struct);
305 dbus_message_iter_get_basic (&iter_struct, &app_name);
306 dbus_message_iter_next (&iter_struct);
307 dbus_message_iter_get_basic (&iter_struct, &obj_path);
309 app->desktop_name = g_strdup (app_name);
310 app->desktop_path = g_strdup (obj_path);
315 g_warning ("AT-SPI: Could not embed inside desktop");
318 dbus_message_unref (reply);
320 get_registered_event_listeners (spi_global_app_data);
324 register_application (SpiBridge * app)
326 DBusMessage *message, *reply;
327 DBusMessageIter iter;
329 DBusPendingCall *pending;
330 const int max_addr_length = 128; /* should be long enough */
332 dbus_error_init (&error);
334 /* These will be overridden when we get a reply, but in practice these
335 defaults should always be correct */
336 app->desktop_name = ATSPI_DBUS_NAME_REGISTRY;
337 app->desktop_path = ATSPI_DBUS_PATH_ROOT;
339 message = dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
340 ATSPI_DBUS_PATH_ROOT,
341 ATSPI_DBUS_INTERFACE_SOCKET,
344 dbus_message_iter_init_append (message, &iter);
345 spi_object_append_reference (&iter, app->root);
347 if (!dbus_connection_send_with_reply (app->bus, message, &pending, -1)
353 dbus_pending_call_set_notify (pending, register_reply, app, NULL);
356 dbus_message_unref (message);
358 /* could this be better, we accept some amount of race in getting the temp name*/
359 /* make sure the directory exists */
360 mkdir ("/tmp/at-spi2/", S_IRWXU|S_IRWXG|S_IRWXO|S_ISVTX);
361 chmod ("/tmp/at-spi2/", S_IRWXU|S_IRWXG|S_IRWXO|S_ISVTX);
362 app->app_bus_addr = g_malloc(max_addr_length * sizeof(char));
364 sprintf (app->app_bus_addr, "unix:path=/tmp/at-spi2/socket-%d-%d", getpid(),
367 app->app_bus_addr [0] = '\0';
373 /*---------------------------------------------------------------------------*/
376 deregister_application (SpiBridge * app)
378 DBusMessage *message;
379 DBusMessageIter iter;
383 dbus_error_init (&error);
385 message = dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
386 ATSPI_DBUS_PATH_REGISTRY,
387 ATSPI_DBUS_INTERFACE_REGISTRY,
388 "DeregisterApplication");
389 dbus_message_set_no_reply (message, TRUE);
391 uname = dbus_bus_get_unique_name (app->bus);
393 dbus_message_iter_init_append (message, &iter);
394 dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &uname);
395 dbus_connection_send (app->bus, message, NULL);
397 dbus_message_unref (message);
400 /*---------------------------------------------------------------------------*/
402 /*---------------------------------------------------------------------------*/
404 static AtkPlugClass *plug_class;
405 static AtkSocketClass *socket_class;
408 get_plug_id (AtkPlug * plug)
410 const char *uname = dbus_bus_get_unique_name (spi_global_app_data->bus);
412 GString *str = g_string_new (NULL);
414 path = spi_register_object_to_path (spi_global_register, G_OBJECT (plug));
415 g_string_printf (str, "%s:%s", uname, path);
417 return g_string_free (str, FALSE);
421 socket_ref_state_set (AtkObject *accessible)
423 char *child_name, *child_path;
424 AtkSocket *socket = ATK_SOCKET (accessible);
428 DBusMessage *message, *reply;
429 DBusMessageIter iter, iter_array;
432 set = atk_state_set_new ();
434 if (!socket->embedded_plug_id)
437 child_name = g_strdup (socket->embedded_plug_id);
440 child_path = g_utf8_strchr (child_name + 1, -1, ':');
446 *(child_path++) = '\0';
447 message = dbus_message_new_method_call (child_name, child_path, ATSPI_DBUS_INTERFACE_ACCESSIBLE, "GetState");
449 reply = dbus_connection_send_with_reply_and_block (spi_global_app_data->bus, message, 1, NULL);
450 dbus_message_unref (message);
453 if (strcmp (dbus_message_get_signature (reply), "au") != 0)
455 dbus_message_unref (reply);
459 dbus_message_iter_init (reply, &iter);
460 dbus_message_iter_recurse (&iter, &iter_array);
463 dbus_message_iter_get_basic (&iter_array, &v);
464 for (j = 0; j < 32; j++)
468 AtkState state = spi_atk_state_from_spi_state ((count << 5) + j);
469 atk_state_set_add_state (set, state);
474 while (dbus_message_iter_next (&iter_array));
475 dbus_message_unref (reply);
480 socket_embed_hook (AtkSocket * socket, gchar * plug_id)
482 AtkObject *accessible = ATK_OBJECT(socket);
483 gchar *plug_name, *plug_path;
484 AtkObjectClass *klass;
486 /* Force registration */
487 gchar *path = spi_register_object_to_path (spi_global_register, G_OBJECT (accessible));
488 /* Let the plug know that it has been embedded */
489 plug_name = g_strdup (plug_id);
495 plug_path = g_utf8_strchr (plug_name + 1, -1, ':');
498 DBusMessage *message;
499 *(plug_path++) = '\0';
500 message = dbus_message_new_method_call (plug_name, plug_path, ATSPI_DBUS_INTERFACE_SOCKET, "Embedded");
501 dbus_message_append_args (message, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID);
502 dbus_connection_send (spi_global_app_data->bus, message, NULL);
507 klass = ATK_OBJECT_GET_CLASS (accessible);
508 klass->ref_state_set = socket_ref_state_set;
512 install_plug_hooks ()
516 data = g_type_class_ref (ATK_TYPE_PLUG);
517 plug_class = ATK_PLUG_CLASS (data);
518 data = g_type_class_ref (ATK_TYPE_SOCKET);
519 socket_class = ATK_SOCKET_CLASS (data);
520 plug_class->get_object_id = get_plug_id;
521 socket_class->embed = socket_embed_hook;
525 get_ancestral_uid (uint pid)
531 gboolean got_ppid = 0;
532 gboolean got_uid = 0;
534 sprintf (buf, "/proc/%d/status", pid);
535 fp = fopen (buf, "r");
538 while ((!got_ppid || !got_uid) && fgets (buf, sizeof (buf), fp))
540 if (sscanf (buf, "PPid:\t%d", &ppid) == 1)
542 else if (sscanf (buf, "Uid:\t%d", &uid) == 1)
547 if (!got_ppid || !got_uid)
551 if (ppid == 0 || ppid == 1)
553 return get_ancestral_uid (ppid);
557 user_check (DBusConnection *bus, unsigned long uid, void *data)
559 if (uid == getuid () || uid == geteuid ())
562 return get_ancestral_uid (getpid ()) == uid;
567 new_connection_cb (DBusServer *server, DBusConnection *con, void *data)
571 dbus_connection_set_unix_user_function (con, user_check, NULL, NULL);
572 dbus_connection_ref(con);
573 atspi_dbus_connection_setup_with_g_main(con, NULL);
574 droute_intercept_dbus (con);
575 droute_context_register (spi_global_app_data->droute, con);
577 spi_global_app_data->direct_connections = g_list_append (spi_global_app_data->direct_connections, con);
587 dbus_error_init(&err);
588 server = dbus_server_listen(spi_global_app_data->app_bus_addr, &err);
591 g_warning (_("atk-bridge: Couldn't listen on dbus server: %s"), err.message);
592 dbus_error_init (&err);
593 spi_global_app_data->app_bus_addr [0] = '\0';
594 g_main_context_unref (spi_global_app_data->main_context);
595 spi_global_app_data->main_context = NULL;
599 atspi_dbus_server_setup_with_g_main(server, NULL);
600 dbus_server_set_new_connection_function(server, new_connection_cb, NULL, NULL);
602 spi_global_app_data->server = server;
609 gchar *atspi_dbus_name = NULL;
610 static gboolean atspi_no_register = FALSE;
612 static GOptionEntry atspi_option_entries[] = {
613 {"atspi-dbus-name", 0, 0, G_OPTION_ARG_STRING, &atspi_dbus_name,
614 "D-Bus bus name to register as", NULL},
615 {"atspi-no-register", 0, 0, G_OPTION_ARG_NONE, &atspi_no_register,
616 "Do not register with Registry Daemon", NULL},
621 introspect_children_cb (const char *path, void *data)
623 if (!strcmp (path, "/org/a11y/atspi/accessible"))
625 return g_strdup ("<node name=\"root\"/>\n");
626 /* TODO: Should we place the whole hierarchy here? */
632 handle_event_listener_registered (DBusConnection *bus, DBusMessage *message,
638 if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &sender,
639 DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID))
642 add_event (sender, name);
646 remove_events (const char *bus_name, const char *event)
652 remove_data = g_strsplit (event, ":", 3);
658 for (list = spi_global_app_data->events; list;)
660 event_data *evdata = list->data;
661 if (!g_strcmp0 (evdata->bus_name, bus_name) &&
662 spi_event_is_subtype (evdata->data, remove_data))
664 GList *events = spi_global_app_data->events;
666 g_strfreev (evdata->data);
667 g_free (evdata->bus_name);
669 spi_global_app_data->events = g_list_remove (events, evdata);
677 g_strfreev (remove_data);
681 handle_event_listener_deregistered (DBusConnection *bus, DBusMessage *message,
684 const char *orig_name;
688 if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &sender,
689 DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID))
692 remove_events (sender, name);
696 handle_device_listener_registered (DBusConnection *bus, DBusMessage *message,
700 DBusMessageIter iter, iter_struct;
702 if (strncmp (dbus_message_get_signature (message), "(s", 2) != 0)
704 g_warning ("atk-bridge: handle_device_listener_register: unknown signature");
708 dbus_message_iter_init (message, &iter);
709 dbus_message_iter_recurse (&iter, &iter_struct);
710 dbus_message_iter_get_basic (&iter_struct, &sender);
711 spi_atk_add_client (sender);
714 static DBusHandlerResult
715 signal_filter (DBusConnection *bus, DBusMessage *message, void *user_data)
717 const char *interface = dbus_message_get_interface (message);
718 const char *member = dbus_message_get_member (message);
719 DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
721 if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_SIGNAL)
722 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
724 if (!strcmp (interface, ATSPI_DBUS_INTERFACE_REGISTRY))
726 result = DBUS_HANDLER_RESULT_HANDLED;
727 if (!strcmp (member, "EventListenerRegistered"))
728 handle_event_listener_registered (bus, message, user_data);
729 else if (!strcmp (member, "EventListenerDeregistered"))
730 handle_event_listener_deregistered (bus, message, user_data);
732 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
734 else if (!strcmp (interface, ATSPI_DBUS_INTERFACE_DEVICE_EVENT_LISTENER))
736 result = DBUS_HANDLER_RESULT_HANDLED;
737 if (!strcmp (member, "KeystrokeListenerRegistered"))
738 handle_device_listener_registered (bus, message, user_data);
739 else if (!strcmp (member, "DeviceListenerRegistered"))
740 handle_device_listener_registered (bus, message, user_data);
742 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
745 if (!g_strcmp0(interface, DBUS_INTERFACE_DBUS) &&
746 !g_strcmp0(member, "NameOwnerChanged"))
748 char *name, *old, *new;
749 result = DBUS_HANDLER_RESULT_HANDLED;
750 if (dbus_message_get_args (message, NULL,
751 DBUS_TYPE_STRING, &name,
752 DBUS_TYPE_STRING, &old,
753 DBUS_TYPE_STRING, &new,
756 if (*old != '\0' && *new == '\0')
757 spi_atk_remove_client (old);
767 * The following needs to be initialized.
769 * - DRoute for routing message to their accessible objects.
770 * - Event handlers for emmitting signals on specific ATK events.
771 * - setup the bus for p2p communication
772 * - Application registration with the AT-SPI registry.
776 adaptor_init (gint * argc, gchar ** argv[])
782 gchar *introspection_directory;
783 static gboolean inited = FALSE;
790 DRoutePath *treepath, *accpath;
792 root = atk_get_root ();
793 g_warn_if_fail (root);
800 /* Parse command line options */
801 opt = g_option_context_new (NULL);
802 g_option_context_add_main_entries (opt, atspi_option_entries, NULL);
803 g_option_context_set_ignore_unknown_options (opt, TRUE);
804 if (!g_option_context_parse (opt, argc, argv, &err))
805 g_warning ("AT-SPI Option parsing failed: %s\n", err->message);
806 g_option_context_free (opt);
808 /* Allocate global data and do ATK initializations */
809 spi_global_app_data = g_new0 (SpiBridge, 1);
810 spi_global_app_data->root = g_object_ref (root);
812 /* Set up D-Bus connection and register bus name */
813 dbus_error_init (&error);
814 spi_global_app_data->bus = atspi_get_a11y_bus ();
815 if (!spi_global_app_data->bus)
817 g_free (spi_global_app_data);
818 spi_global_app_data = NULL;
823 if (atspi_dbus_name != NULL)
825 if (dbus_bus_request_name
826 (spi_global_app_data->bus, atspi_dbus_name, 0, &error))
828 g_print ("AT-SPI Recieved D-Bus name - %s\n", atspi_dbus_name);
833 ("AT-SPI D-Bus name requested but could not be allocated - %s\n",
838 spi_global_app_data->main_context = g_main_context_new ();
840 atspi_dbus_connection_setup_with_g_main (spi_global_app_data->bus, NULL);
842 /* Hook our plug-and socket functions */
843 install_plug_hooks ();
846 * Create the leasing, register and cache objects.
847 * The order is important here, the cache depends on the
850 spi_global_register = g_object_new (SPI_REGISTER_TYPE, NULL);
851 spi_global_leasing = g_object_new (SPI_LEASING_TYPE, NULL);
852 spi_global_cache = g_object_new (SPI_CACHE_TYPE, NULL);
854 /* Register droute for routing AT-SPI messages */
855 spi_global_app_data->droute =
858 treepath = droute_add_one (spi_global_app_data->droute,
859 "/org/a11y/atspi/cache", spi_global_cache);
863 g_warning ("atk-bridge: Error in droute_add_one(). Already running?");
867 accpath = droute_add_many (spi_global_app_data->droute,
868 "/org/a11y/atspi/accessible",
870 introspect_children_cb,
872 (DRouteGetDatumFunction)
873 spi_global_register_path_to_object);
876 /* Register all interfaces with droute and set up application accessible db */
877 spi_initialize_cache (treepath);
878 spi_initialize_accessible (accpath);
879 spi_initialize_application (accpath);
880 spi_initialize_action (accpath);
881 spi_initialize_collection (accpath);
882 spi_initialize_component (accpath);
883 spi_initialize_document (accpath);
884 spi_initialize_editabletext (accpath);
885 spi_initialize_hyperlink (accpath);
886 spi_initialize_hypertext (accpath);
887 spi_initialize_image (accpath);
888 spi_initialize_selection (accpath);
889 spi_initialize_socket (accpath);
890 spi_initialize_table (accpath);
891 spi_initialize_text (accpath);
892 spi_initialize_value (accpath);
894 droute_context_register (spi_global_app_data->droute,
895 spi_global_app_data->bus);
897 /* Register methods to send D-Bus signals on certain ATK events */
898 spi_atk_register_event_listeners ();
900 /* Set up filter and match rules to catch signals */
901 dbus_bus_add_match (spi_global_app_data->bus, "type='signal', interface='org.a11y.atspi.Registry', sender='org.a11y.atspi.Registry'", NULL);
902 dbus_bus_add_match (spi_global_app_data->bus, "type='signal', interface='org.a11y.atspi.DeviceEventListener', sender='org.a11y.atspi.Registry'", NULL);
903 dbus_connection_add_filter (spi_global_app_data->bus, signal_filter, NULL,
906 /* Register this app by sending a signal out to AT-SPI registry daemon */
907 if (!atspi_no_register && (!root || !ATK_IS_PLUG (root)))
908 register_application (spi_global_app_data);
910 get_registered_event_listeners (spi_global_app_data);
917 /*---------------------------------------------------------------------------*/
920 gtk_module_init (gint * argc, gchar ** argv[])
922 const gchar *load_bridge = g_getenv ("NO_AT_BRIDGE");
924 if (!load_bridge || g_ascii_strtod (load_bridge, NULL) == 0)
926 return adaptor_init (argc, argv);
932 g_module_check_init (GModule *module)
934 g_module_make_resident (module);
940 gnome_accessibility_module_init (void)
942 const gchar *load_bridge = g_getenv ("NO_AT_BRIDGE");
944 if (!load_bridge || g_ascii_strtod (load_bridge, NULL) == 0)
946 adaptor_init (NULL, NULL);
948 if (g_getenv ("AT_SPI_DEBUG"))
950 g_print ("Atk Accessibility bridge initialized\n");
956 gnome_accessibility_module_shutdown (void)
961 if (!spi_global_app_data)
964 spi_atk_tidy_windows ();
965 spi_atk_deregister_event_listeners ();
967 deregister_application (spi_global_app_data);
969 if (spi_global_app_data->bus)
971 dbus_connection_remove_filter (spi_global_app_data->bus, signal_filter, NULL);
972 droute_context_unregister (spi_global_app_data->droute, spi_global_app_data->bus);
973 dbus_connection_unref (spi_global_app_data->bus);
976 for (l = spi_global_app_data->direct_connections; l; l = l->next)
978 DBusConnection *connection;
980 connection = l->data;
982 droute_context_unregister (spi_global_app_data->droute, connection);
983 droute_unintercept_dbus (connection);
984 dbus_connection_unref (connection);
986 g_list_free (spi_global_app_data->direct_connections);
988 for (ls = clients; ls; ls = ls->next)
990 g_slist_free (clients);
993 g_object_unref (spi_global_cache);
994 g_object_unref (spi_global_leasing);
995 g_object_unref (spi_global_register);
997 if (spi_global_app_data->main_context)
998 g_main_context_unref (spi_global_app_data->main_context);
1000 droute_free (spi_global_app_data->droute);
1002 g_free (spi_global_app_data);
1003 spi_global_app_data = NULL;
1005 /* Not currently creating an XDisplay */
1008 XCloseDisplay (bridge_display);
1012 static gchar *name_match_tmpl =
1013 "type='signal', interface='org.freedesktop.DBus', member='NameOwnerChanged', arg0='%s'";
1016 spi_atk_add_client (const char *bus_name)
1021 for (l = clients; l; l = l->next)
1023 if (!g_strcmp0 (l->data, bus_name))
1026 if (!clients && spi_global_app_data->events_initialized)
1027 spi_atk_register_event_listeners ();
1028 clients = g_slist_append (clients, g_strdup (bus_name));
1029 match = g_strdup_printf (name_match_tmpl, bus_name);
1030 dbus_bus_add_match (spi_global_app_data->bus, match, NULL);
1035 spi_atk_remove_client (const char *bus_name)
1043 next_node = l->next;
1045 if (!g_strcmp0 (l->data, bus_name))
1047 gchar *match = g_strdup_printf (name_match_tmpl, l->data);
1048 dbus_bus_remove_match (spi_global_app_data->bus, match, NULL);
1051 clients = g_slist_delete_link (clients, l);
1053 spi_atk_deregister_event_listeners ();
1060 /*END------------------------------------------------------------------------*/