51b12bc3beb73b95d91fa2463be247f8d73c37d3
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / bridge.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2008, 2009 Codethink Ltd.
6  * Copyright 2001, 2002, 2003 Sun Microsystems Inc.,
7  * Copyright 2001, 2002, 2003 Ximian, Inc.
8  *
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.
13  *
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.
18  *
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.
23  */
24
25 #define _GNU_SOURCE
26 #include "config.h"
27
28 #include <X11/Xlib.h>
29 #include <X11/Xatom.h>
30 #include <unistd.h>
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <stdarg.h>
34 #include <string.h>
35 #include<sys/stat.h>
36 #include <atk/atk.h>
37
38 #include <droute/droute.h>
39 #include <gmodule.h>
40 #include <glib/gi18n.h>
41 #include <atspi/atspi.h>
42
43 #include "bridge.h"
44 #include "event.h"
45 #include "adaptors.h"
46 #include "object.h"
47 #include "common/spi-stateset.h"
48
49 #include "accessible-register.h"
50 #include "accessible-leasing.h"
51 #include "accessible-cache.h"
52
53 #include "common/spi-dbus.h"
54
55 /*---------------------------------------------------------------------------*/
56
57 SpiBridge *spi_global_app_data = NULL;
58
59 /*static Display *bridge_display = NULL;*/
60
61 /*---------------------------------------------------------------------------*/
62
63 /*
64  * Returns a 'canonicalized' value for DISPLAY,
65  * with the screen number stripped off if present.
66  *
67  */
68 static const gchar *
69 spi_display_name (void)
70 {
71   static const char *canonical_display_name = NULL;
72   if (!canonical_display_name)
73     {
74       const gchar *display_env = g_getenv ("AT_SPI_DISPLAY");
75       if (!display_env)
76         {
77           display_env = g_getenv ("DISPLAY");
78           if (!display_env || !display_env[0])
79             canonical_display_name = ":0";
80           else
81             {
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))
87                 {
88                   *screen_p = '\0';
89                 }
90             }
91         }
92       else
93         {
94           canonical_display_name = display_env;
95         }
96     }
97   return canonical_display_name;
98 }
99
100 /*---------------------------------------------------------------------------*/
101
102 static void
103 set_reply (DBusPendingCall *pending, void *user_data)
104 {
105     void **replyptr = (void **)user_data;
106
107     *replyptr = dbus_pending_call_steal_reply (pending);
108   dbus_pending_call_unref (pending);
109 }
110
111 /*---------------------------------------------------------------------------*/
112
113 static void
114 add_event (const char *bus_name, const char *event)
115 {
116   event_data *evdata;
117   gchar **data;
118   GList *new_list;
119
120   evdata = (event_data *) g_malloc (sizeof (*evdata));
121   if (!evdata)
122     return;
123   data = g_strsplit (event, ":", 3);
124   if (!data)
125     {
126       g_free (evdata);
127       return;
128     }
129   evdata->bus_name = g_strdup (bus_name);
130   evdata->data = data;
131   new_list = g_list_append (spi_global_app_data->events, evdata);
132   if (new_list)
133     spi_global_app_data->events = new_list;
134 }
135
136 static void
137 get_registered_event_listeners (SpiBridge *app)
138 {
139   DBusMessage *message, *reply;
140   DBusMessageIter iter, iter_array, iter_struct;
141
142   message = dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
143                                          SPI_DBUS_PATH_REGISTRY,
144                                          SPI_DBUS_INTERFACE_REGISTRY,
145                                          "GetRegisteredEvents");
146   spi_global_app_data->events_initialized = TRUE;
147   if (!message)
148     return;
149
150   reply = dbus_connection_send_with_reply_and_block (app->bus, message, 5000, NULL);
151   dbus_message_unref (message);
152   if (!reply)
153     return;
154   if (strcmp (dbus_message_get_signature (reply), "a(ss)") != 0)
155     {
156       /* TODO: Add a warning when it's okay to add strings */
157       dbus_message_unref (reply);
158       return;
159     }
160   dbus_message_iter_init (reply, &iter);
161   dbus_message_iter_recurse (&iter, &iter_array);
162   while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
163     {
164       char *bus_name, *event;
165       dbus_message_iter_recurse (&iter_array, &iter_struct);
166       dbus_message_iter_get_basic (&iter_struct, &bus_name);
167       dbus_message_iter_next (&iter_struct);
168       dbus_message_iter_get_basic (&iter_struct, &event);
169       add_event (bus_name, event);
170       dbus_message_iter_next (&iter_array);
171     }
172   dbus_message_unref (reply);
173 }
174
175 static void
176 register_reply (DBusPendingCall *pending, void *user_data)
177 {
178   DBusMessage *reply;
179   SpiBridge *app = user_data;
180   DBusMessage *message;
181
182   reply = dbus_pending_call_steal_reply (pending);
183   dbus_pending_call_unref (pending);
184   if (reply)
185     {
186       gchar *app_name, *obj_path;
187
188       if (strcmp (dbus_message_get_signature (reply), "(so)") != 0)
189         {
190           g_warning ("AT-SPI: Could not obtain desktop path or name\n");
191         }
192       else
193         {
194           DBusMessageIter iter, iter_struct;
195           dbus_message_iter_init (reply, &iter);
196           dbus_message_iter_recurse (&iter, &iter_struct);
197           dbus_message_iter_get_basic (&iter_struct, &app_name);
198           dbus_message_iter_next (&iter_struct);
199           dbus_message_iter_get_basic (&iter_struct, &obj_path);
200
201           app->desktop_name = g_strdup (app_name);
202           app->desktop_path = g_strdup (obj_path);
203         }
204     }
205   else
206     {
207       g_warning ("AT-SPI: Could not embed inside desktop");
208       return;
209     }
210   dbus_message_unref (reply);
211
212   get_registered_event_listeners (spi_global_app_data);
213 }
214
215 static gboolean
216 register_application (SpiBridge * app)
217 {
218   DBusMessage *message, *reply;
219   DBusMessageIter iter;
220   DBusError error;
221   DBusPendingCall *pending;
222   const int max_addr_length = 128; /* should be long enough */
223
224   dbus_error_init (&error);
225
226   /* These will be overridden when we get a reply, but in practice these
227      defaults should always be correct */
228   app->desktop_name = SPI_DBUS_NAME_REGISTRY;
229   app->desktop_path = SPI_DBUS_PATH_ROOT;
230
231   message = dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
232                                           SPI_DBUS_PATH_ROOT,
233                                           SPI_DBUS_INTERFACE_SOCKET,
234                                           "Embed");
235
236   dbus_message_iter_init_append (message, &iter);
237   spi_object_append_reference (&iter, app->root);
238   
239     if (!dbus_connection_send_with_reply (app->bus, message, &pending, -1)
240         || !pending)
241     {
242         return FALSE;
243     }
244
245     dbus_pending_call_set_notify (pending, register_reply, app, NULL);
246
247   if (message)
248     dbus_message_unref (message);
249
250   /* could this be better, we accept some amount of race in getting the temp name*/
251   /* make sure the directory exists */
252   mkdir ("/tmp/at-spi2/", S_IRWXU|S_IRWXG|S_IRWXO|S_ISVTX);
253   chmod ("/tmp/at-spi2/", S_IRWXU|S_IRWXG|S_IRWXO|S_ISVTX);
254   app->app_bus_addr = g_malloc(max_addr_length * sizeof(char));
255 #ifndef DISABLE_P2P
256   sprintf (app->app_bus_addr, "unix:path=/tmp/at-spi2/socket-%d-%d", getpid(),
257            rand());
258 #else
259   app->app_bus_addr [0] = '\0';
260 #endif
261
262   return TRUE;
263 }
264
265 /*---------------------------------------------------------------------------*/
266
267 static void
268 deregister_application (SpiBridge * app)
269 {
270   DBusMessage *message;
271   DBusMessageIter iter;
272   DBusError error;
273   const char *uname;
274
275   dbus_error_init (&error);
276
277   message = dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
278                                           SPI_DBUS_PATH_REGISTRY,
279                                           SPI_DBUS_INTERFACE_REGISTRY,
280                                           "DeregisterApplication");
281   dbus_message_set_no_reply (message, TRUE);
282
283   uname = dbus_bus_get_unique_name (app->bus);
284
285   dbus_message_iter_init_append (message, &iter);
286   dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &uname);
287   dbus_connection_send (app->bus, message, NULL);
288   if (message)
289     dbus_message_unref (message);
290 }
291
292 /*---------------------------------------------------------------------------*/
293
294 static void
295 exit_func (void)
296 {
297   if (!spi_global_app_data)
298     {
299       return;
300     }
301
302   spi_atk_tidy_windows ();
303   spi_atk_deregister_event_listeners ();
304   deregister_application (spi_global_app_data);
305
306   g_free (spi_global_app_data);
307   spi_global_app_data = NULL;
308
309   /* Not currently creating an XDisplay */
310 #if 0
311   if (bridge_display)
312     XCloseDisplay (bridge_display);
313 #endif
314 }
315
316 /*---------------------------------------------------------------------------*/
317
318 static AtkPlugClass *plug_class;
319 static AtkSocketClass *socket_class;
320
321 static gchar *
322 get_plug_id (AtkPlug * plug)
323 {
324   const char *uname = dbus_bus_get_unique_name (spi_global_app_data->bus);
325   gchar *path;
326   GString *str = g_string_new (NULL);
327
328   path = spi_register_object_to_path (spi_global_register, G_OBJECT (plug));
329   g_string_printf (str, "%s:%s", uname, path);
330   g_free (path);
331   return g_string_free (str, FALSE);
332 }
333
334 AtkStateSet *
335 socket_ref_state_set (AtkObject *accessible)
336 {
337   char *child_name, *child_path;
338   AtkSocket *socket = ATK_SOCKET (accessible);
339   int count = 0;
340   int j;
341   int v;
342   DBusMessage *message, *reply;
343   DBusMessageIter iter, iter_array;
344   AtkStateSet *set;
345
346   if (!socket->embedded_plug_id)
347     return NULL;
348
349   child_name = g_strdup (socket->embedded_plug_id);
350   if (!child_name)
351     return NULL;
352   child_path = g_utf8_strchr (child_name + 1, -1, ':');
353   if (!child_path)
354     {
355       g_free (child_name);
356       return NULL;
357     }
358   *(child_path++) = '\0';
359   message = dbus_message_new_method_call (child_name, child_path, SPI_DBUS_INTERFACE_ACCESSIBLE, "GetState");
360   g_free (child_name);
361   reply = dbus_connection_send_with_reply_and_block (spi_global_app_data->bus, message, 1, NULL);
362   dbus_message_unref (message);
363   if (reply == NULL)
364     return NULL;
365   if (strcmp (dbus_message_get_signature (reply), "au") != 0)
366     {
367       dbus_message_unref (reply);
368       return NULL;
369     }
370   set = atk_state_set_new ();
371   if (!set)
372     return  NULL;
373   dbus_message_iter_init (reply, &iter);
374   dbus_message_iter_recurse (&iter, &iter_array);
375   do
376     {
377       dbus_message_iter_get_basic (&iter_array, &v);
378       for (j = 0; j < 32; j++)
379         {
380           if (v & (1 << j))
381             {
382               AtkState state = spi_atk_state_from_spi_state ((count << 5) + j);
383               atk_state_set_add_state (set, state);
384             }
385         }
386       count++;
387     }
388   while (dbus_message_iter_next (&iter_array));
389   dbus_message_unref (reply);
390   return set;
391 }
392
393 static void
394 socket_embed_hook (AtkSocket * socket, gchar * plug_id)
395 {
396   AtkObject *accessible = ATK_OBJECT(socket);
397   gchar *plug_name, *plug_path;
398   AtkObjectClass *klass;
399
400   /* Force registration */
401   gchar *path = spi_register_object_to_path (spi_global_register, G_OBJECT (accessible));
402   /* Let the plug know that it has been embedded */
403   plug_name = g_strdup (plug_id);
404   if (!plug_name)
405     {
406       g_free (path);
407       return;
408     }
409   plug_path = g_utf8_strchr (plug_name + 1, -1, ':');
410   if (plug_path)
411     {
412       DBusMessage *message;
413       *(plug_path++) = '\0';
414       message = dbus_message_new_method_call (plug_name, plug_path, SPI_DBUS_INTERFACE_SOCKET, "Embedded");
415       dbus_message_append_args (message, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID);
416       dbus_connection_send (spi_global_app_data->bus, message, NULL);
417     }
418   g_free (plug_name);
419   g_free (path);
420
421   klass = ATK_OBJECT_GET_CLASS (accessible);
422   klass->ref_state_set = socket_ref_state_set;
423 }
424
425 static void
426 install_plug_hooks ()
427 {
428   gpointer data;
429
430   data = g_type_class_ref (ATK_TYPE_PLUG);
431   plug_class = ATK_PLUG_CLASS (data);
432   data = g_type_class_ref (ATK_TYPE_SOCKET);
433   socket_class = ATK_SOCKET_CLASS (data);
434   plug_class->get_object_id = get_plug_id;
435   socket_class->embed = socket_embed_hook;
436 }
437
438 static uint
439 get_ancestral_uid (uint pid)
440 {
441   FILE *fp;
442   char buf [80];
443   int ppid = 0;
444   int uid = 0;
445   gboolean got_ppid = 0;
446   gboolean got_uid = 0;
447
448   sprintf (buf, "/proc/%d/status", pid);
449   fp = fopen (buf, "r");
450   if (!fp)
451     return 0;
452   while ((!got_ppid || !got_uid) && fgets (buf, sizeof (buf), fp))
453   {
454     if (sscanf (buf, "PPid:\t%d", &ppid) == 1)
455       got_ppid = TRUE;
456     else if (sscanf (buf, "Uid:\t%d", &uid) == 1)
457       got_uid = TRUE;
458   }
459   fclose (fp);
460
461   if (!got_ppid || !got_uid)
462     return 0;
463   if (uid != 0)
464     return uid;
465   if (ppid == 0 || ppid == 1)
466     return 0;
467   return get_ancestral_uid (ppid);
468 }
469
470 static dbus_bool_t
471 user_check (DBusConnection *bus, unsigned long uid)
472 {
473   if (uid == getuid () || uid == geteuid ())
474     return TRUE;
475   if (getuid () == 0)
476     return get_ancestral_uid (getpid ()) == uid;
477   return FALSE;
478 }
479
480 static void
481 new_connection_cb (DBusServer *server, DBusConnection *con, void *data)
482 {
483   GList *new_list;
484
485   dbus_connection_set_unix_user_function (con, user_check, NULL, NULL);
486   dbus_connection_ref(con);
487   atspi_dbus_connection_setup_with_g_main(con, NULL);
488   droute_intercept_dbus (con);
489   droute_context_register (spi_global_app_data->droute, con);
490
491   new_list = g_list_append (spi_global_app_data->direct_connections, con);
492   if (new_list)
493     spi_global_app_data->direct_connections = new_list;
494 }
495
496 static int
497 setup_bus (void)
498 {
499 #ifndef DISABLE_P2P
500   DBusServer *server;
501   DBusError err;
502
503   dbus_error_init(&err);
504   server = dbus_server_listen(spi_global_app_data->app_bus_addr, &err);
505   if (server == NULL)
506   {
507     g_warning (_("atk-bridge: Couldn't listen on dbus server: %s"), err.message);
508     dbus_error_init (&err);
509     spi_global_app_data->app_bus_addr [0] = '\0';
510     g_main_context_unref (spi_global_app_data->main_context);
511     spi_global_app_data->main_context = NULL;
512     return -1;
513   }
514
515   atspi_dbus_server_setup_with_g_main(server, NULL);
516   dbus_server_set_new_connection_function(server, new_connection_cb, NULL, NULL);
517
518   spi_global_app_data->server = server;
519 #endif
520
521   return 0;
522 }
523
524
525 gchar *atspi_dbus_name = NULL;
526 static gboolean atspi_no_register = FALSE;
527
528 static GOptionEntry atspi_option_entries[] = {
529   {"atspi-dbus-name", 0, 0, G_OPTION_ARG_STRING, &atspi_dbus_name,
530    "D-Bus bus name to register as", NULL},
531   {"atspi-no-register", 0, 0, G_OPTION_ARG_NONE, &atspi_no_register,
532    "Do not register with Registry Daemon", NULL},
533   {NULL}
534 };
535
536 static gchar *
537 introspect_children_cb (const char *path, void *data)
538 {
539   if (!strcmp (path, "/org/a11y/atspi/accessible"))
540     {
541       return g_strdup ("<node name=\"root\"/>\n");
542       /* TODO: Should we place the whole hierarchy here? */
543     }
544   return NULL;
545 }
546
547 static void
548 handle_event_listener_registered (DBusConnection *bus, DBusMessage *message,
549                                   void *user_data)
550 {
551   const char *name;
552   char *sender;
553
554   if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &sender,
555     DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID))
556     return;
557
558   add_event (sender, name);
559 }
560
561 static void
562 remove_events (const char *bus_name, const char *event)
563 {
564   event_data *evdata;
565   gchar **remove_data;
566   GList *list;
567
568   remove_data = g_strsplit (event, ":", 3);
569   if (!remove_data)
570     {
571       return;
572     }
573
574   for (list = spi_global_app_data->events; list;)
575     {
576       event_data *evdata = list->data;
577       if (!g_strcmp0 (evdata->bus_name, bus_name) &&
578           spi_event_is_subtype (evdata->data, remove_data))
579         {
580           GList *events = spi_global_app_data->events;
581           list = list->next;
582           g_strfreev (evdata->data);
583           g_free (evdata->bus_name);
584           g_free (evdata);
585           spi_global_app_data->events = g_list_remove (events, evdata);
586         }
587       else
588         {
589           list = list->next;
590         }
591     }
592
593   g_strfreev (remove_data);
594 }
595
596 static void
597 handle_event_listener_deregistered (DBusConnection *bus, DBusMessage *message,
598                                     void *user_data)
599 {
600   const char *orig_name;
601   gchar *name;
602   char *sender;
603
604   if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &sender,
605                               DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID))
606     return;
607
608   remove_events (sender, name);
609 }
610
611 static DBusHandlerResult
612 signal_filter (DBusConnection *bus, DBusMessage *message, void *user_data)
613 {
614   const char *interface = dbus_message_get_interface (message);
615   const char *member = dbus_message_get_member (message);
616   DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
617
618   if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_SIGNAL)
619     return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
620
621   if (!strcmp (interface, SPI_DBUS_INTERFACE_REGISTRY))
622     {
623       result = DBUS_HANDLER_RESULT_HANDLED;
624       if (!strcmp (member, "EventListenerRegistered"))
625         handle_event_listener_registered (bus, message, user_data);
626       else if (!strcmp (member, "EventListenerDeregistered"))
627         handle_event_listener_deregistered (bus, message, user_data);
628       else
629         result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
630     }
631   return result;
632 }
633
634 /*
635  * spi_app_init
636  *
637  * The following needs to be initialized.
638  *
639  * - DRoute for routing message to their accessible objects.
640  * - Event handlers for emmitting signals on specific ATK events.
641  * - setup the bus for p2p communication
642  * - Application registration with the AT-SPI registry.
643  *
644  */
645 static int
646 adaptor_init (gint * argc, gchar ** argv[])
647 {
648   GOptionContext *opt;
649   GError *err = NULL;
650   DBusError error;
651   AtkObject *root;
652   gchar *introspection_directory;
653   static gboolean inited = FALSE;
654
655   if (inited)
656     return 0;
657
658   inited = TRUE;
659
660   DRoutePath *treepath, *accpath;
661
662   root = atk_get_root ();
663   g_warn_if_fail (root);
664   if (!root)
665     {
666       inited = FALSE;
667       return -1;
668     }
669
670   /* Parse command line options */
671   opt = g_option_context_new (NULL);
672   g_option_context_add_main_entries (opt, atspi_option_entries, NULL);
673   g_option_context_set_ignore_unknown_options (opt, TRUE);
674   if (!g_option_context_parse (opt, argc, argv, &err))
675     g_warning ("AT-SPI Option parsing failed: %s\n", err->message);
676   g_option_context_free (opt);
677
678   /* Allocate global data and do ATK initializations */
679   spi_global_app_data = g_new0 (SpiBridge, 1);
680   spi_global_app_data->root = g_object_ref (root);
681
682   /* Set up D-Bus connection and register bus name */
683   dbus_error_init (&error);
684   spi_global_app_data->bus = atspi_get_a11y_bus ();
685   if (!spi_global_app_data->bus)
686     {
687       g_free (spi_global_app_data);
688       spi_global_app_data = NULL;
689       inited = FALSE;
690       return -1;
691     }
692
693   if (atspi_dbus_name != NULL)
694     {
695       if (dbus_bus_request_name
696           (spi_global_app_data->bus, atspi_dbus_name, 0, &error))
697         {
698           g_print ("AT-SPI Recieved D-Bus name - %s\n", atspi_dbus_name);
699         }
700       else
701         {
702           g_print
703             ("AT-SPI D-Bus name requested but could not be allocated - %s\n",
704              atspi_dbus_name);
705         }
706     }
707
708   spi_global_app_data->main_context = g_main_context_new ();
709
710   atspi_dbus_connection_setup_with_g_main (spi_global_app_data->bus, NULL);
711
712   /* Hook our plug-and socket functions */
713   install_plug_hooks ();
714
715   /* 
716    * Create the leasing, register and cache objects.
717    * The order is important here, the cache depends on the
718    * register object.
719    */
720   spi_global_register = g_object_new (SPI_REGISTER_TYPE, NULL);
721   spi_global_leasing  = g_object_new (SPI_LEASING_TYPE, NULL);
722   spi_global_cache    = g_object_new (SPI_CACHE_TYPE, NULL);
723
724   /* Register droute for routing AT-SPI messages */
725   spi_global_app_data->droute =
726     droute_new ();
727
728   treepath = droute_add_one (spi_global_app_data->droute,
729                              "/org/a11y/atspi/cache", spi_global_cache);
730
731   if (!treepath)
732     {
733       g_warning ("atk-bridge: Error in droute_add_one().  Already running?");
734       return -1;
735     }
736
737   accpath = droute_add_many (spi_global_app_data->droute,
738                              "/org/a11y/atspi/accessible",
739                              NULL,
740                              introspect_children_cb,
741                              NULL,
742                              (DRouteGetDatumFunction)
743                              spi_global_register_path_to_object);
744
745
746   /* Register all interfaces with droute and set up application accessible db */
747   spi_initialize_cache (treepath);
748   spi_initialize_accessible (accpath);
749   spi_initialize_application (accpath);
750   spi_initialize_action (accpath);
751   spi_initialize_collection (accpath);
752   spi_initialize_component (accpath);
753   spi_initialize_document (accpath);
754   spi_initialize_editabletext (accpath);
755   spi_initialize_hyperlink (accpath);
756   spi_initialize_hypertext (accpath);
757   spi_initialize_image (accpath);
758   spi_initialize_selection (accpath);
759   spi_initialize_socket (accpath);
760   spi_initialize_table (accpath);
761   spi_initialize_text (accpath);
762   spi_initialize_value (accpath);
763
764   droute_context_register (spi_global_app_data->droute,
765                            spi_global_app_data->bus);
766
767   /* Register methods to send D-Bus signals on certain ATK events */
768   spi_atk_register_event_listeners ();
769
770   /* Set up filter and match rules to catch signals */
771   dbus_bus_add_match (spi_global_app_data->bus, "type='signal', interface='org.a11y.atspi.Registry', sender='org.a11y.atspi.Registry'", NULL);
772   dbus_connection_add_filter (spi_global_app_data->bus, signal_filter, NULL,
773                               NULL);
774
775   /* Register this app by sending a signal out to AT-SPI registry daemon */
776   if (!atspi_no_register && (!root || !ATK_IS_PLUG (root)))
777     register_application (spi_global_app_data);
778   else
779     get_registered_event_listeners (spi_global_app_data);
780
781   setup_bus();
782
783   return 0;
784 }
785
786 /*---------------------------------------------------------------------------*/
787
788 int
789 gtk_module_init (gint * argc, gchar ** argv[])
790 {
791   const gchar *load_bridge = g_getenv ("NO_AT_BRIDGE");
792
793   if (!load_bridge || g_ascii_strtod (load_bridge, NULL) == 0)
794     {
795       return adaptor_init (argc, argv);
796     }
797   return 0;
798 }
799
800 gchar*
801 g_module_check_init (GModule *module)
802 {
803   g_module_make_resident (module);
804
805   return NULL;
806 }
807
808 void
809 gnome_accessibility_module_init (void)
810 {
811   const gchar *load_bridge = g_getenv ("NO_AT_BRIDGE");
812
813   if (!load_bridge || g_ascii_strtod (load_bridge, NULL) == 0)
814     {
815       adaptor_init (NULL, NULL);
816
817       if (g_getenv ("AT_SPI_DEBUG"))
818         {
819           g_print ("Atk Accessibility bridge initialized\n");
820         }
821     }
822 }
823
824 void
825 gnome_accessibility_module_shutdown (void)
826 {
827   spi_atk_deregister_event_listeners ();
828   exit_func ();
829 }
830
831 /*END------------------------------------------------------------------------*/