- 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("Option parsing failed: %s\n", err->message);
-
- dbus_error_init(&error);
- ad->root = root;
- ad->droute.bus = dbus_bus_get(DBUS_BUS_SESSION, &error);
- g_print("D-Bus unique name is : %s\n", dbus_bus_get_unique_name(ad->droute.bus));
-
- if (!ad->droute.bus)
- {
- g_warning("Couldn't connect to dbus: %s\n", error.message);
- free(ad);
- return NULL;
- }
- if (atspi_dbus_name != NULL && dbus_bus_request_name(ad->droute.bus,
- atspi_dbus_name,
- 0,
- &error))
- {
- g_print("\nRecieved D-Bus name - %s\n", atspi_dbus_name);
- }
- spi_register_tree_object(ad->droute.bus, &ad->droute, "/org/freedesktop/atspi/tree");
- if (!dbus_connection_try_register_fallback (ad->droute.bus,
- "/org/freedesktop/atspi/accessible",
- &droute_vtable,
- &ad->droute,
- &error))
- {
- g_warning("Couldn't register droute.\n");
- free(ad);
- return NULL;
- }
-
- dbus_connection_setup_with_g_main(ad->droute.bus, g_main_context_default());
-
- atk_dbus_initialize (&ad->droute);
- return ad;
-}
-
-static int
-atk_bridge_init (gint *argc, gchar **argv[])
-{
- const char *debug_env_string = g_getenv ("AT_SPI_DEBUG");
- gchar *fname;
- gboolean success = FALSE;
-
- if (atk_bridge_initialized)
- {
- return 0;
- }
- atk_bridge_initialized = TRUE;
- atk_bridge_pid = getpid ();
-
- misc = atk_misc_get_instance();
-
- if (g_getenv ("ATK_BRIDGE_REDIRECT_LOG"))
- {
- fname = g_strconcat ("/tmp/", g_get_prgname (), ".at-spi-log", NULL);
- /* make sure we're not being redirected - security issue */
- if (!g_file_test (fname, G_FILE_TEST_IS_SYMLINK))
- freopen (fname, "w", stderr);
- g_free (fname);
- }
-
- if (debug_env_string)
- _dbg = (int) g_ascii_strtod (debug_env_string, NULL);
-
- /* Connect to dbus */
- this_app = spi_app_init (atk_get_root (), argc, argv);
-
- /*
- * We only want to enable the bridge for top level
- * applications, we detect bonobo components by seeing
- * if they were activated with the intention of extracting
- * an impl. by IID - very solid.
- */
-#ifdef WITH_BONOBO
- // TODO: Figure out if this is still needed
- if (bonobo_activation_iid_get ())
-#else
- if (0)
-#endif
- {
- DBG (1, g_message ("Found Bonobo component\n"));
- g_signal_connect (atk_get_root (),
- "children-changed::add",
- (GCallback) spi_atk_bridge_toplevel_added,
- NULL);
- g_signal_connect (atk_get_root (),
- "children-changed::remove",
- (GCallback) spi_atk_bridge_toplevel_removed,
- NULL);
- /* in this case we redefine 'success' to mean 'registry is present' */
- success = (spi_atk_bridge_get_registry () != NULL);
- }
- else
- {
- success = spi_atk_bridge_do_registration ();
- }
- /*
- * we must emit events even if we are not registered as a
- * full-fledged app; See bugzilla #400709.
- */
- if (success)
- {
- spi_atk_register_event_listeners ();
- }
- else
- {
- atk_bridge_initialized = FALSE;
- }
- g_idle_add (post_init, NULL);
-
- return 0;
-}
-
-static gboolean
-spi_atk_bridge_do_registration (void)
-{
- if (spi_atk_bridge_get_registry () == NULL)
- {
- g_warning ("Could not locate registry");
- return FALSE;
- }
-
- /* Create the accessible application server object */
- if (this_app == NULL)
- this_app = spi_app_init (atk_get_root (), 0, NULL);
-
- DBG (1, g_message ("About to register application\n"));
-
- spi_atk_bridge_register_application (spi_atk_bridge_get_registry ());
-
- g_atexit (spi_atk_bridge_exit_func);
-
- DBG (1, g_message ("Application registered & listening\n"));
- return TRUE;
-}
-
-static void
-spi_atk_bridge_toplevel_added (AtkObject *object,
- guint index,
- AtkObject *child)
-{
- if (toplevels == 0)
- {
- spi_atk_bridge_do_registration ();
- }
- toplevels++;
-}
-
-static void
-spi_atk_bridge_toplevel_removed (AtkObject *object,
- guint index,
- AtkObject *child)
-{
- toplevels--;
- if (toplevels == 0)
- {
- deregister_application (this_app);
- reinit_register_vars ();
- }
- if (toplevels < 0)
- {
- g_warning ("More toplevels removed than added\n");
- toplevels = 0;
- }
-}
-
-static void
-spi_atk_bridge_register_application (const char *registry)
-{
- DBusMessage *message, *reply;
- DBusError error;
-
- message = dbus_message_new_signal (SPI_DBUS_PATH_REGISTRY, SPI_DBUS_INTERFACE_TREE, "registerApplication");
- dbus_error_init (&error);
- dbus_connection_send (this_app->droute.bus, message, NULL);
- if (error.message) g_print (error.message);
- if (message) dbus_message_unref (message);
-}
-
-/*