+/*
+ * spi_app_init
+ *
+ * The following needs to be initialized.
+ *
+ * - DRoute for routing message to their accessible objects.
+ * - Event handlers for emmitting signals on specific ATK events.
+ * - Application registration with the AT-SPI registry.
+ *
+ */
+static int
+adaptor_init (gint *argc, gchar **argv[])
+{
+ GOptionContext *opt;
+ GError *err = NULL;
+ DBusError error;
+ DBusConnection *bus;
+ AtkObject *root;
+ gchar *introspection_directory;
+ static gboolean inited = FALSE;
+
+ if (inited)
+ return 0;
+
+ inited = TRUE;
+
+ DRoutePath *treepath, *accpath;
+
+ root = atk_get_root ();
+ g_return_val_if_fail (root, 0);
+
+ /* Parse command line options */
+ opt = g_option_context_new(NULL);
+ g_option_context_add_main_entries(opt, atspi_option_entries, NULL);
+ g_option_context_set_ignore_unknown_options(opt, TRUE);
+ if (!g_option_context_parse(opt, argc, argv, &err))
+ g_warning("AT-SPI Option parsing failed: %s\n", err->message);
+
+ /* Allocate global data and do ATK initializations */
+ atk_adaptor_app_data = g_new0 (SpiAppData, 1);
+ atk_misc = atk_misc_get_instance ();
+ atk_adaptor_app_data->root = root;
+
+ /* Set up D-Bus connection and register bus name */
+ dbus_error_init (&error);
+ atk_adaptor_app_data->bus = dbus_bus_get (DBUS_BUS_SESSION, &error);
+ if (!atk_adaptor_app_data->bus)
+ {
+ g_warning ("AT-SPI Couldn't connect to D-Bus: %s\n", error.message);
+ g_free(atk_adaptor_app_data);
+ atk_adaptor_app_data = NULL;
+ return 0;
+ }
+ if (atspi_dbus_name != NULL &&
+ dbus_bus_request_name(atk_adaptor_app_data->bus, atspi_dbus_name, 0, &error))
+ {
+ g_print("AT-SPI Recieved D-Bus name - %s\n", atspi_dbus_name);
+ }
+
+ dbus_connection_setup_with_g_main(atk_adaptor_app_data->bus, g_main_context_default());
+
+ /* Get D-Bus introspection directory */
+ introspection_directory = (char *) g_getenv("ATSPI_INTROSPECTION_PATH");
+ if (introspection_directory == NULL)
+ introspection_directory = ATSPI_INTROSPECTION_PATH;
+
+ /* Register droute for routing AT-SPI messages */
+ atk_adaptor_app_data->droute = droute_new (atk_adaptor_app_data->bus, introspection_directory);
+
+ treepath = droute_add_one (atk_adaptor_app_data->droute,
+ "/org/freedesktop/atspi/tree",
+ NULL);
+
+ accpath = droute_add_many (atk_adaptor_app_data->droute,
+ "/org/freedesktop/atspi/accessible",
+ NULL,
+ (DRouteGetDatumFunction) atk_dbus_path_to_gobject);
+
+ /* Register all interfaces with droute and set up application accessible db */
+ spi_initialize_tree (treepath);
+
+ spi_initialize_accessible (accpath);
+ spi_initialize_application (accpath);
+ spi_initialize_action(accpath);
+ spi_initialize_collection (accpath);
+ spi_initialize_component (accpath);
+ spi_initialize_document (accpath);
+ spi_initialize_editabletext (accpath);
+ spi_initialize_hyperlink (accpath);
+ spi_initialize_hypertext (accpath);
+ spi_initialize_image (accpath);
+ spi_initialize_selection (accpath);
+ spi_initialize_table (accpath);
+ spi_initialize_text (accpath);
+ spi_initialize_value (accpath);
+
+ /* Initialize the AtkObject registration */
+ atk_dbus_initialize (atk_adaptor_app_data->root);
+
+ /* Register methods to send D-Bus signals on certain ATK events */
+ spi_atk_register_event_listeners ();
+
+ /* Register this app by sending a signal out to AT-SPI registry daemon */
+ register_application (atk_adaptor_app_data);
+
+ g_atexit (exit_func);
+
+ return 0;