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 /*---------------------------------------------------------------------------*/
64 * Returns a 'canonicalized' value for DISPLAY,
65 * with the screen number stripped off if present.
69 spi_display_name (void)
71 static const char *canonical_display_name = NULL;
72 if (!canonical_display_name)
74 const gchar *display_env = g_getenv ("AT_SPI_DISPLAY");
77 display_env = g_getenv ("DISPLAY");
78 if (!display_env || !display_env[0])
79 canonical_display_name = ":0";
82 gchar *display_p, *screen_p;
83 canonical_display_name = g_strdup (display_env);
84 display_p = strrchr (canonical_display_name, ':');
85 screen_p = strrchr (canonical_display_name, '.');
86 if (screen_p && display_p && (screen_p > display_p))
94 canonical_display_name = display_env;
97 return canonical_display_name;
100 /*---------------------------------------------------------------------------*/
103 set_reply (DBusPendingCall *pending, void *user_data)
105 void **replyptr = (void **)user_data;
107 *replyptr = dbus_pending_call_steal_reply (pending);
108 dbus_pending_call_unref (pending);
111 /*---------------------------------------------------------------------------*/
114 add_event (const char *bus_name, const char *event)
120 spi_atk_add_client (bus_name);
121 evdata = (event_data *) g_malloc (sizeof (*evdata));
124 data = g_strsplit (event, ":", 3);
130 evdata->bus_name = g_strdup (bus_name);
132 new_list = g_list_append (spi_global_app_data->events, evdata);
134 spi_global_app_data->events = new_list;
137 static GSList *clients = NULL;
142 static int replies_received = 0;
145 if (replies_received == 3)
148 spi_atk_deregister_event_listeners ();
149 spi_global_app_data->events_initialized = TRUE;
154 get_events_reply (DBusPendingCall *pending, void *user_data)
156 DBusMessage *reply = dbus_pending_call_steal_reply (pending);
157 DBusMessageIter iter, iter_array, iter_struct;
162 if (strcmp (dbus_message_get_signature (reply), "a(ss)") != 0)
164 g_warning ("atk-bridge: GetRegisteredEvents returned message with unknown signature");
168 dbus_message_iter_init (reply, &iter);
169 dbus_message_iter_recurse (&iter, &iter_array);
170 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
172 char *bus_name, *event;
173 dbus_message_iter_recurse (&iter_array, &iter_struct);
174 dbus_message_iter_get_basic (&iter_struct, &bus_name);
175 dbus_message_iter_next (&iter_struct);
176 dbus_message_iter_get_basic (&iter_struct, &event);
177 add_event (bus_name, event);
178 dbus_message_iter_next (&iter_array);
183 dbus_message_unref (reply);
185 dbus_pending_call_unref (pending);
187 tally_event_reply ();
191 get_device_events_reply (DBusPendingCall *pending, void *user_data)
193 DBusMessage *reply = dbus_pending_call_steal_reply (pending);
194 DBusMessageIter iter, iter_array, iter_struct;
199 if (strncmp (dbus_message_get_signature (reply), "a(s", 3) != 0)
201 g_warning ("atk-bridge: get_device_events_reply: unknown signature");
205 dbus_message_iter_init (reply, &iter);
206 dbus_message_iter_recurse (&iter, &iter_array);
207 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
210 dbus_message_iter_recurse (&iter_array, &iter_struct);
211 dbus_message_iter_get_basic (&iter_struct, &bus_name);
212 spi_atk_add_client (bus_name);
213 dbus_message_iter_next (&iter_array);
218 dbus_message_unref (reply);
220 dbus_pending_call_unref (pending);
222 tally_event_reply ();
226 get_registered_event_listeners (SpiBridge *app)
228 DBusMessage *message;
229 DBusPendingCall *pending = NULL;
231 message = dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
232 ATSPI_DBUS_PATH_REGISTRY,
233 ATSPI_DBUS_INTERFACE_REGISTRY,
234 "GetRegisteredEvents");
238 dbus_connection_send_with_reply (app->bus, message, &pending, -1);
239 dbus_message_unref (message);
242 spi_global_app_data->events_initialized = TRUE;
245 dbus_pending_call_set_notify (pending, get_events_reply, NULL, NULL);
247 message = dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
249 ATSPI_DBUS_INTERFACE_DEC,
250 "GetKeystrokeListeners");
254 dbus_connection_send_with_reply (app->bus, message, &pending, -1);
255 dbus_message_unref (message);
258 spi_global_app_data->events_initialized = TRUE;
261 dbus_pending_call_set_notify (pending, get_device_events_reply, NULL, NULL);
263 message = dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
265 ATSPI_DBUS_INTERFACE_DEC,
266 "GetDeviceEventListeners");
270 dbus_connection_send_with_reply (app->bus, message, &pending, -1);
271 dbus_message_unref (message);
274 spi_global_app_data->events_initialized = TRUE;
277 dbus_pending_call_set_notify (pending, get_device_events_reply, NULL, NULL);
281 register_reply (DBusPendingCall *pending, void *user_data)
284 SpiBridge *app = user_data;
285 DBusMessage *message;
287 reply = dbus_pending_call_steal_reply (pending);
288 dbus_pending_call_unref (pending);
291 gchar *app_name, *obj_path;
293 if (strcmp (dbus_message_get_signature (reply), "(so)") != 0)
295 g_warning ("AT-SPI: Could not obtain desktop path or name\n");
299 DBusMessageIter iter, iter_struct;
300 dbus_message_iter_init (reply, &iter);
301 dbus_message_iter_recurse (&iter, &iter_struct);
302 dbus_message_iter_get_basic (&iter_struct, &app_name);
303 dbus_message_iter_next (&iter_struct);
304 dbus_message_iter_get_basic (&iter_struct, &obj_path);
306 app->desktop_name = g_strdup (app_name);
307 app->desktop_path = g_strdup (obj_path);
312 g_warning ("AT-SPI: Could not embed inside desktop");
315 dbus_message_unref (reply);
317 get_registered_event_listeners (spi_global_app_data);
321 register_application (SpiBridge * app)
323 DBusMessage *message, *reply;
324 DBusMessageIter iter;
326 DBusPendingCall *pending;
327 const int max_addr_length = 128; /* should be long enough */
329 dbus_error_init (&error);
331 /* These will be overridden when we get a reply, but in practice these
332 defaults should always be correct */
333 app->desktop_name = ATSPI_DBUS_NAME_REGISTRY;
334 app->desktop_path = ATSPI_DBUS_PATH_ROOT;
336 message = dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
337 ATSPI_DBUS_PATH_ROOT,
338 ATSPI_DBUS_INTERFACE_SOCKET,
341 dbus_message_iter_init_append (message, &iter);
342 spi_object_append_reference (&iter, app->root);
344 if (!dbus_connection_send_with_reply (app->bus, message, &pending, -1)
350 dbus_pending_call_set_notify (pending, register_reply, app, NULL);
353 dbus_message_unref (message);
355 /* could this be better, we accept some amount of race in getting the temp name*/
356 /* make sure the directory exists */
357 mkdir ("/tmp/at-spi2/", S_IRWXU|S_IRWXG|S_IRWXO|S_ISVTX);
358 chmod ("/tmp/at-spi2/", S_IRWXU|S_IRWXG|S_IRWXO|S_ISVTX);
359 app->app_bus_addr = g_malloc(max_addr_length * sizeof(char));
361 sprintf (app->app_bus_addr, "unix:path=/tmp/at-spi2/socket-%d-%d", getpid(),
364 app->app_bus_addr [0] = '\0';
370 /*---------------------------------------------------------------------------*/
373 deregister_application (SpiBridge * app)
375 DBusMessage *message;
376 DBusMessageIter iter;
380 dbus_error_init (&error);
382 message = dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
383 ATSPI_DBUS_PATH_REGISTRY,
384 ATSPI_DBUS_INTERFACE_REGISTRY,
385 "DeregisterApplication");
386 dbus_message_set_no_reply (message, TRUE);
388 uname = dbus_bus_get_unique_name (app->bus);
390 dbus_message_iter_init_append (message, &iter);
391 dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &uname);
392 dbus_connection_send (app->bus, message, NULL);
394 dbus_message_unref (message);
397 /*---------------------------------------------------------------------------*/
399 /*---------------------------------------------------------------------------*/
401 static AtkPlugClass *plug_class;
402 static AtkSocketClass *socket_class;
405 get_plug_id (AtkPlug * plug)
407 const char *uname = dbus_bus_get_unique_name (spi_global_app_data->bus);
409 GString *str = g_string_new (NULL);
411 path = spi_register_object_to_path (spi_global_register, G_OBJECT (plug));
412 g_string_printf (str, "%s:%s", uname, path);
414 return g_string_free (str, FALSE);
418 socket_ref_state_set (AtkObject *accessible)
420 char *child_name, *child_path;
421 AtkSocket *socket = ATK_SOCKET (accessible);
425 DBusMessage *message, *reply;
426 DBusMessageIter iter, iter_array;
429 set = atk_state_set_new ();
431 if (!socket->embedded_plug_id)
434 child_name = g_strdup (socket->embedded_plug_id);
437 child_path = g_utf8_strchr (child_name + 1, -1, ':');
443 *(child_path++) = '\0';
444 message = dbus_message_new_method_call (child_name, child_path, ATSPI_DBUS_INTERFACE_ACCESSIBLE, "GetState");
446 reply = dbus_connection_send_with_reply_and_block (spi_global_app_data->bus, message, 1, NULL);
447 dbus_message_unref (message);
450 if (strcmp (dbus_message_get_signature (reply), "au") != 0)
452 dbus_message_unref (reply);
456 dbus_message_iter_init (reply, &iter);
457 dbus_message_iter_recurse (&iter, &iter_array);
460 dbus_message_iter_get_basic (&iter_array, &v);
461 for (j = 0; j < 32; j++)
465 AtkState state = spi_atk_state_from_spi_state ((count << 5) + j);
466 atk_state_set_add_state (set, state);
471 while (dbus_message_iter_next (&iter_array));
472 dbus_message_unref (reply);
477 socket_embed_hook (AtkSocket * socket, gchar * plug_id)
479 AtkObject *accessible = ATK_OBJECT(socket);
480 gchar *plug_name, *plug_path;
481 AtkObjectClass *klass;
483 /* Force registration */
484 gchar *path = spi_register_object_to_path (spi_global_register, G_OBJECT (accessible));
485 /* Let the plug know that it has been embedded */
486 plug_name = g_strdup (plug_id);
492 plug_path = g_utf8_strchr (plug_name + 1, -1, ':');
495 DBusMessage *message;
496 *(plug_path++) = '\0';
497 message = dbus_message_new_method_call (plug_name, plug_path, ATSPI_DBUS_INTERFACE_SOCKET, "Embedded");
498 dbus_message_append_args (message, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID);
499 dbus_connection_send (spi_global_app_data->bus, message, NULL);
504 klass = ATK_OBJECT_GET_CLASS (accessible);
505 klass->ref_state_set = socket_ref_state_set;
509 install_plug_hooks ()
513 data = g_type_class_ref (ATK_TYPE_PLUG);
514 plug_class = ATK_PLUG_CLASS (data);
515 data = g_type_class_ref (ATK_TYPE_SOCKET);
516 socket_class = ATK_SOCKET_CLASS (data);
517 plug_class->get_object_id = get_plug_id;
518 socket_class->embed = socket_embed_hook;
522 get_ancestral_uid (uint pid)
528 gboolean got_ppid = 0;
529 gboolean got_uid = 0;
531 sprintf (buf, "/proc/%d/status", pid);
532 fp = fopen (buf, "r");
535 while ((!got_ppid || !got_uid) && fgets (buf, sizeof (buf), fp))
537 if (sscanf (buf, "PPid:\t%d", &ppid) == 1)
539 else if (sscanf (buf, "Uid:\t%d", &uid) == 1)
544 if (!got_ppid || !got_uid)
548 if (ppid == 0 || ppid == 1)
550 return get_ancestral_uid (ppid);
554 user_check (DBusConnection *bus, unsigned long uid, void *data)
556 if (uid == getuid () || uid == geteuid ())
559 return get_ancestral_uid (getpid ()) == uid;
564 new_connection_cb (DBusServer *server, DBusConnection *con, void *data)
568 dbus_connection_set_unix_user_function (con, user_check, NULL, NULL);
569 dbus_connection_ref(con);
570 atspi_dbus_connection_setup_with_g_main(con, NULL);
571 droute_intercept_dbus (con);
572 droute_context_register (spi_global_app_data->droute, con);
574 spi_global_app_data->direct_connections = g_list_append (spi_global_app_data->direct_connections, con);
584 dbus_error_init(&err);
585 server = dbus_server_listen(spi_global_app_data->app_bus_addr, &err);
588 g_warning ("atk-bridge: Couldn't listen on dbus server: %s", err.message);
589 dbus_error_init (&err);
590 spi_global_app_data->app_bus_addr [0] = '\0';
591 g_main_context_unref (spi_global_app_data->main_context);
592 spi_global_app_data->main_context = NULL;
596 atspi_dbus_server_setup_with_g_main(server, NULL);
597 dbus_server_set_new_connection_function(server, new_connection_cb, NULL, NULL);
599 spi_global_app_data->server = server;
606 gchar *atspi_dbus_name = NULL;
607 static gboolean atspi_no_register = FALSE;
609 static GOptionEntry atspi_option_entries[] = {
610 {"atspi-dbus-name", 0, 0, G_OPTION_ARG_STRING, &atspi_dbus_name,
611 "D-Bus bus name to register as", NULL},
612 {"atspi-no-register", 0, 0, G_OPTION_ARG_NONE, &atspi_no_register,
613 "Do not register with Registry Daemon", NULL},
618 introspect_children_cb (const char *path, void *data)
620 if (!strcmp (path, "/org/a11y/atspi/accessible"))
622 return g_strdup ("<node name=\"root\"/>\n");
623 /* TODO: Should we place the whole hierarchy here? */
629 handle_event_listener_registered (DBusConnection *bus, DBusMessage *message,
635 if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &sender,
636 DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID))
639 add_event (sender, name);
643 remove_events (const char *bus_name, const char *event)
649 remove_data = g_strsplit (event, ":", 3);
655 for (list = spi_global_app_data->events; list;)
657 event_data *evdata = list->data;
658 if (!g_strcmp0 (evdata->bus_name, bus_name) &&
659 spi_event_is_subtype (evdata->data, remove_data))
661 GList *events = spi_global_app_data->events;
663 g_strfreev (evdata->data);
664 g_free (evdata->bus_name);
666 spi_global_app_data->events = g_list_remove (events, evdata);
674 g_strfreev (remove_data);
678 handle_event_listener_deregistered (DBusConnection *bus, DBusMessage *message,
681 const char *orig_name;
685 if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &sender,
686 DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID))
689 remove_events (sender, name);
693 handle_device_listener_registered (DBusConnection *bus, DBusMessage *message,
697 DBusMessageIter iter, iter_struct;
699 if (strncmp (dbus_message_get_signature (message), "(s", 2) != 0)
701 g_warning ("atk-bridge: handle_device_listener_register: unknown signature");
705 dbus_message_iter_init (message, &iter);
706 dbus_message_iter_recurse (&iter, &iter_struct);
707 dbus_message_iter_get_basic (&iter_struct, &sender);
708 spi_atk_add_client (sender);
711 static DBusHandlerResult
712 signal_filter (DBusConnection *bus, DBusMessage *message, void *user_data)
714 const char *interface = dbus_message_get_interface (message);
715 const char *member = dbus_message_get_member (message);
716 DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
718 if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_SIGNAL)
719 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
721 if (!strcmp (interface, ATSPI_DBUS_INTERFACE_REGISTRY))
723 result = DBUS_HANDLER_RESULT_HANDLED;
724 if (!strcmp (member, "EventListenerRegistered"))
725 handle_event_listener_registered (bus, message, user_data);
726 else if (!strcmp (member, "EventListenerDeregistered"))
727 handle_event_listener_deregistered (bus, message, user_data);
729 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
731 else if (!strcmp (interface, ATSPI_DBUS_INTERFACE_DEVICE_EVENT_LISTENER))
733 result = DBUS_HANDLER_RESULT_HANDLED;
734 if (!strcmp (member, "KeystrokeListenerRegistered"))
735 handle_device_listener_registered (bus, message, user_data);
736 else if (!strcmp (member, "DeviceListenerRegistered"))
737 handle_device_listener_registered (bus, message, user_data);
739 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
742 if (!g_strcmp0(interface, DBUS_INTERFACE_DBUS) &&
743 !g_strcmp0(member, "NameOwnerChanged"))
745 char *name, *old, *new;
746 result = DBUS_HANDLER_RESULT_HANDLED;
747 if (dbus_message_get_args (message, NULL,
748 DBUS_TYPE_STRING, &name,
749 DBUS_TYPE_STRING, &old,
750 DBUS_TYPE_STRING, &new,
753 if (*old != '\0' && *new == '\0')
754 spi_atk_remove_client (old);
764 * The following needs to be initialized.
766 * - DRoute for routing message to their accessible objects.
767 * - Event handlers for emmitting signals on specific ATK events.
768 * - setup the bus for p2p communication
769 * - Application registration with the AT-SPI registry.
773 adaptor_init (gint * argc, gchar ** argv[])
779 gchar *introspection_directory;
780 static gboolean inited = FALSE;
787 DRoutePath *treepath, *accpath;
789 root = atk_get_root ();
790 g_warn_if_fail (root);
797 /* Parse command line options */
798 opt = g_option_context_new (NULL);
799 g_option_context_add_main_entries (opt, atspi_option_entries, NULL);
800 g_option_context_set_ignore_unknown_options (opt, TRUE);
801 if (!g_option_context_parse (opt, argc, argv, &err))
802 g_warning ("AT-SPI Option parsing failed: %s\n", err->message);
803 g_option_context_free (opt);
805 /* Allocate global data and do ATK initializations */
806 spi_global_app_data = g_new0 (SpiBridge, 1);
807 spi_global_app_data->root = g_object_ref (root);
809 /* Set up D-Bus connection and register bus name */
810 dbus_error_init (&error);
811 spi_global_app_data->bus = atspi_get_a11y_bus ();
812 if (!spi_global_app_data->bus)
814 g_free (spi_global_app_data);
815 spi_global_app_data = NULL;
820 if (atspi_dbus_name != NULL)
822 if (dbus_bus_request_name
823 (spi_global_app_data->bus, atspi_dbus_name, 0, &error))
825 g_print ("AT-SPI Recieved D-Bus name - %s\n", atspi_dbus_name);
830 ("AT-SPI D-Bus name requested but could not be allocated - %s\n",
835 spi_global_app_data->main_context = g_main_context_new ();
837 atspi_dbus_connection_setup_with_g_main (spi_global_app_data->bus, NULL);
839 /* Hook our plug-and socket functions */
840 install_plug_hooks ();
843 * Create the leasing, register and cache objects.
844 * The order is important here, the cache depends on the
847 spi_global_register = g_object_new (SPI_REGISTER_TYPE, NULL);
848 spi_global_leasing = g_object_new (SPI_LEASING_TYPE, NULL);
849 spi_global_cache = g_object_new (SPI_CACHE_TYPE, NULL);
851 /* Register droute for routing AT-SPI messages */
852 spi_global_app_data->droute =
855 treepath = droute_add_one (spi_global_app_data->droute,
856 "/org/a11y/atspi/cache", spi_global_cache);
860 g_warning ("atk-bridge: Error in droute_add_one(). Already running?");
864 accpath = droute_add_many (spi_global_app_data->droute,
865 "/org/a11y/atspi/accessible",
867 introspect_children_cb,
869 (DRouteGetDatumFunction)
870 spi_global_register_path_to_object);
873 /* Register all interfaces with droute and set up application accessible db */
874 spi_initialize_cache (treepath);
875 spi_initialize_accessible (accpath);
876 spi_initialize_application (accpath);
877 spi_initialize_action (accpath);
878 spi_initialize_collection (accpath);
879 spi_initialize_component (accpath);
880 spi_initialize_document (accpath);
881 spi_initialize_editabletext (accpath);
882 spi_initialize_hyperlink (accpath);
883 spi_initialize_hypertext (accpath);
884 spi_initialize_image (accpath);
885 spi_initialize_selection (accpath);
886 spi_initialize_socket (accpath);
887 spi_initialize_table (accpath);
888 spi_initialize_text (accpath);
889 spi_initialize_value (accpath);
891 droute_context_register (spi_global_app_data->droute,
892 spi_global_app_data->bus);
894 /* Register methods to send D-Bus signals on certain ATK events */
895 spi_atk_register_event_listeners ();
897 /* Set up filter and match rules to catch signals */
898 dbus_bus_add_match (spi_global_app_data->bus, "type='signal', interface='org.a11y.atspi.Registry', sender='org.a11y.atspi.Registry'", NULL);
899 dbus_bus_add_match (spi_global_app_data->bus, "type='signal', interface='org.a11y.atspi.DeviceEventListener', sender='org.a11y.atspi.Registry'", NULL);
900 dbus_connection_add_filter (spi_global_app_data->bus, signal_filter, NULL,
903 /* Register this app by sending a signal out to AT-SPI registry daemon */
904 if (!atspi_no_register && (!root || !ATK_IS_PLUG (root)))
905 register_application (spi_global_app_data);
907 get_registered_event_listeners (spi_global_app_data);
915 adaptor_cleanup (void)
920 if (!spi_global_app_data)
923 spi_atk_tidy_windows ();
924 spi_atk_deregister_event_listeners ();
926 deregister_application (spi_global_app_data);
928 if (spi_global_app_data->bus)
930 dbus_connection_remove_filter (spi_global_app_data->bus, signal_filter, NULL);
931 droute_context_unregister (spi_global_app_data->droute, spi_global_app_data->bus);
932 dbus_connection_unref (spi_global_app_data->bus);
935 for (l = spi_global_app_data->direct_connections; l; l = l->next)
937 DBusConnection *connection;
939 connection = l->data;
941 droute_context_unregister (spi_global_app_data->droute, connection);
942 droute_unintercept_dbus (connection);
943 dbus_connection_unref (connection);
945 g_list_free (spi_global_app_data->direct_connections);
947 for (ls = clients; ls; ls = ls->next)
949 g_slist_free (clients);
952 g_object_unref (spi_global_cache);
953 g_object_unref (spi_global_leasing);
954 g_object_unref (spi_global_register);
956 if (spi_global_app_data->main_context)
957 g_main_context_unref (spi_global_app_data->main_context);
959 droute_free (spi_global_app_data->droute);
961 g_free (spi_global_app_data);
962 spi_global_app_data = NULL;
965 /*---------------------------------------------------------------------------*/
968 gtk_module_init (gint * argc, gchar ** argv[])
970 const gchar *load_bridge = g_getenv ("NO_AT_BRIDGE");
972 if (!load_bridge || g_ascii_strtod (load_bridge, NULL) == 0)
974 return adaptor_init (argc, argv);
980 g_module_check_init (GModule *module)
982 g_module_make_resident (module);
988 gnome_accessibility_module_init (void)
990 const gchar *load_bridge = g_getenv ("NO_AT_BRIDGE");
992 if (!load_bridge || g_ascii_strtod (load_bridge, NULL) == 0)
994 adaptor_init (NULL, NULL);
996 if (g_getenv ("AT_SPI_DEBUG"))
998 g_print ("Atk Accessibility bridge initialized\n");
1004 gnome_accessibility_module_shutdown (void)
1009 /*---------------------------------------------------------------------------*/
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------------------------------------------------------------------------*/