+ if (!g_strcmp0(interface, DBUS_INTERFACE_DBUS) &&
+ !g_strcmp0(member, "NameOwnerChanged"))
+ {
+ char *name, *old, *new;
+ result = DBUS_HANDLER_RESULT_HANDLED;
+ if (dbus_message_get_args (message, NULL,
+ DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_STRING, &old,
+ DBUS_TYPE_STRING, &new,
+ DBUS_TYPE_INVALID))
+ {
+ if (*old != '\0' && *new == '\0')
+ spi_atk_remove_client (old);
+ }
+ }
+
+ return result;
+}
+
+/*
+ * 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.
+ * - setup the bus for p2p communication
+ * - Application registration with the AT-SPI registry.
+ *
+ */
+static int
+adaptor_init (gint * argc, gchar ** argv[])
+{
+ GOptionContext *opt;
+ GError *err = NULL;
+ DBusError error;
+ AtkObject *root;
+ gchar *introspection_directory;
+ static gboolean inited = FALSE;
+
+ if (inited)
+ return 0;
+
+ inited = TRUE;
+
+ DRoutePath *treepath, *accpath;
+
+ root = atk_get_root ();
+ g_warn_if_fail (root);
+ if (!root)
+ {
+ inited = FALSE;
+ return -1;
+ }
+
+ /* 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);
+ g_option_context_free (opt);
+
+ /* Allocate global data and do ATK initializations */
+ spi_global_app_data = g_new0 (SpiBridge, 1);
+ spi_global_app_data->root = g_object_ref (root);
+
+ /* Set up D-Bus connection and register bus name */
+ dbus_error_init (&error);
+ spi_global_app_data->bus = atspi_get_a11y_bus ();
+ if (!spi_global_app_data->bus)
+ {
+ g_free (spi_global_app_data);
+ spi_global_app_data = NULL;
+ inited = FALSE;
+ return -1;
+ }
+
+ if (atspi_dbus_name != NULL)
+ {
+ if (dbus_bus_request_name
+ (spi_global_app_data->bus, atspi_dbus_name, 0, &error))
+ {
+ g_print ("AT-SPI Recieved D-Bus name - %s\n", atspi_dbus_name);
+ }
+ else
+ {
+ g_print
+ ("AT-SPI D-Bus name requested but could not be allocated - %s\n",
+ atspi_dbus_name);
+ }
+ }
+
+ spi_global_app_data->main_context = g_main_context_new ();
+
+ atspi_dbus_connection_setup_with_g_main (spi_global_app_data->bus, NULL);
+
+ /* Hook our plug-and socket functions */
+ install_plug_hooks ();
+
+ /*
+ * Create the leasing, register and cache objects.
+ * The order is important here, the cache depends on the
+ * register object.