#include "bridge.h"
#include "event.h"
#include "adaptors.h"
+#include "object.h"
#include "accessible-register.h"
#include "accessible-leasing.h"
#include "common/spi-dbus.h"
-/*
- * Provides the path for the introspection directory.
- */
-#if !defined ATSPI_INTROSPECTION_PATH
-#error "No introspection XML directory defined"
-#endif
-
/*---------------------------------------------------------------------------*/
SpiBridge *spi_global_app_data = NULL;
return bus;
}
+static void
+set_reply (DBusPendingCall *pending, void *user_data)
+{
+ void **replyptr = (void **)user_data;
+
+ *replyptr = dbus_pending_call_steal_reply (pending);
+}
+
+static DBusMessage *
+send_and_allow_reentry (DBusConnection *bus, DBusMessage *message, DBusError *error)
+{
+ DBusPendingCall *pending;
+ DBusMessage *reply = NULL;
+
+ if (!dbus_connection_send_with_reply (bus, message, &pending, -1))
+ {
+ return NULL;
+ }
+ dbus_pending_call_set_notify (pending, set_reply, (void *)&reply, NULL);
+ while (!reply)
+ {
+ if (!dbus_connection_read_write_dispatch (bus, -1)) return NULL;
+ }
+ return reply;
+}
/*---------------------------------------------------------------------------*/
-static void
+static gboolean
register_application (SpiBridge * app)
{
- DBusMessage *message;
+ DBusMessage *message, *reply;
DBusMessageIter iter;
DBusError error;
- const char *uname = NULL;
dbus_error_init (&error);
message = dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
- SPI_DBUS_PATH_REGISTRY,
- SPI_DBUS_INTERFACE_REGISTRY,
- "RegisterApplication");
- dbus_message_set_no_reply (message, TRUE);
-
- uname = dbus_bus_get_unique_name (app->bus);
- if (!uname)
- {
- g_error ("AT-SPI: Couldn't get unique name for this connection");
- }
+ SPI_DBUS_PATH_ROOT,
+ SPI_DBUS_INTERFACE_SOCKET,
+ "Embed");
dbus_message_iter_init_append (message, &iter);
- dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &uname);
- dbus_connection_send (app->bus, message, NULL);
+ spi_object_append_reference (&iter, app->root);
+
+ reply = send_and_allow_reentry (app->bus, message, &error);
+
if (message)
dbus_message_unref (message);
+
+ if (reply)
+ {
+ DBusMessageIter iter, iter_struct;
+ gchar *app_name, *obj_path;
+
+ if (strcmp (dbus_message_get_signature (reply), "(so)") != 0)
+ {
+ g_warning ("AT-SPI: Could not obtain desktop path or name\n");
+ return FALSE;
+ }
+
+ dbus_message_iter_init (reply, &iter);
+ dbus_message_iter_recurse (&iter, &iter_struct);
+ dbus_message_iter_get_basic (&iter_struct, &app_name);
+ dbus_message_iter_next (&iter_struct);
+ dbus_message_iter_get_basic (&iter_struct, &obj_path);
+
+ app->desktop_name = g_strdup (app_name);
+ app->desktop_path = g_strdup (obj_path);
+ }
+ else
+ {
+ g_warning ("AT-SPI: Could not embed inside desktop: %s\n", error.message);
+ return FALSE;
+ }
+ return TRUE;
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
-#ifdef __ATK_PLUG_H__
static AtkPlugClass *plug_class;
static AtkSocketClass *socket_class;
gchar *path;
GString *str = g_string_new (NULL);
- path = atk_dbus_object_to_path (ATK_OBJECT (plug), TRUE);
+ path = spi_register_object_to_path (spi_global_register, G_OBJECT (plug));
g_string_printf (str, "%s:%s", uname, path);
g_free (path);
return g_string_free (str, FALSE);
gchar *plug_name, *plug_path;
/* Force registration */
- gchar *path = atk_dbus_object_to_path (accessible, TRUE);
- spi_emit_cache_update (accessible, atk_adaptor_app_data->bus);
+ gchar *path = spi_register_object_to_path (spi_global_register, G_OBJECT (accessible));
/* Let the plug know that it has been embedded */
plug_name = g_strdup (plug_id);
if (!plug_name)
{
DBusMessage *message;
*(plug_path++) = '\0';
- message = dbus_message_new_method_call (plug_name, plug_path, "org.freedesktop.atspi.Accessible", "Embedded");
+ message = dbus_message_new_method_call (plug_name, plug_path, SPI_DBUS_INTERFACE_SOCKET, "Embedded");
dbus_message_append_args (message, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID);
- dbus_connection_send (atk_adaptor_app_data->bus, message, NULL);
+ dbus_connection_send (spi_global_app_data->bus, message, NULL);
}
g_free (plug_name);
g_free (path);
plug_class->get_object_id = get_plug_id;
socket_class->embed = socket_embed_hook;
}
-#endif
gchar *atspi_dbus_name = NULL;
static gboolean atspi_no_register = FALSE;
/* Allocate global data and do ATK initializations */
spi_global_app_data = g_new0 (SpiBridge, 1);
atk_misc = atk_misc_get_instance ();
- spi_global_app_data->root = root;
+ spi_global_app_data->root = g_object_ref (root);
/* Set up D-Bus connection and register bus name */
dbus_error_init (&error);
dbus_connection_setup_with_g_main (spi_global_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;
+ /* 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.
+ */
+ spi_global_register = g_object_new (SPI_REGISTER_TYPE, NULL);
+ spi_global_leasing = g_object_new (SPI_LEASING_TYPE, NULL);
+ spi_global_cache = g_object_new (SPI_CACHE_TYPE, NULL);
/* Register droute for routing AT-SPI messages */
spi_global_app_data->droute =
- droute_new (spi_global_app_data->bus, introspection_directory);
+ droute_new (spi_global_app_data->bus);
treepath = droute_add_one (spi_global_app_data->droute,
- "/org/at_spi/cache", NULL);
+ "/org/at_spi/cache", spi_global_cache);
+
+ if (!treepath)
+ {
+ g_warning ("atk-bridge: Error in droute_add_one(). Already running?");
+ return 0;
+ }
accpath = droute_add_many (spi_global_app_data->droute,
- "/org/at_spi/accessible",
+ "/org/a11y/atspi/accessible",
NULL,
(DRouteGetDatumFunction)
spi_global_register_path_to_object);
- /*
- * Create the leasing, register and cache objects.
- * The order is important here, the cache depends on the
- * register object.
- */
- spi_global_register = g_object_new (SPI_REGISTER_TYPE, NULL);
- spi_global_leasing = g_object_new (SPI_LEASING_TYPE, NULL);
- spi_global_cache = g_object_new (SPI_CACHE_TYPE, NULL);
/* Register all interfaces with droute and set up application accessible db */
spi_initialize_cache (treepath);
spi_initialize_hypertext (accpath);
spi_initialize_image (accpath);
spi_initialize_selection (accpath);
+ spi_initialize_socket (accpath);
spi_initialize_table (accpath);
spi_initialize_text (accpath);
spi_initialize_value (accpath);
/* Register methods to send D-Bus signals on certain ATK events */
spi_atk_register_event_listeners ();
-#ifdef __ATK_PLUG_H__
- /* Hook our plug-and socket functions */
- install_plug_hooks ();
-#endif
-
/* Register this app by sending a signal out to AT-SPI registry daemon */
- if (!atspi_no_register)
+ if (!atspi_no_register && (!root || !ATK_IS_PLUG (root)))
register_application (spi_global_app_data);
g_atexit (exit_func);