*
* Copyright 2001, 2002 Sun Microsystems Inc.,
* Copyright 2001, 2002 Ximian, Inc.
+ * Copyright 2010, 2011 Novell, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
#include "atspi-private.h"
#include "X11/Xlib.h"
+#include "dbus/dbus-glib.h"
#include <stdio.h>
#include <string.h>
static void handle_get_items (DBusPendingCall *pending, void *user_data);
static DBusConnection *bus = NULL;
-static GHashTable *apps = NULL;
static GHashTable *live_refs = NULL;
-static GQueue *exception_handlers = NULL;
-static DBusError exception;
const char *atspi_path_dec = ATSPI_DBUS_PATH_DEC;
const char *atspi_path_registry = ATSPI_DBUS_PATH_REGISTRY;
if (!app_hash)
{
- app_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_hash_table_unref);
+ app_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_object_unref);
if (!app_hash) return NULL;
}
app = g_hash_table_lookup (app_hash, bus_name);
// TODO: change below to something that will send state-change:defunct notification if necessary */
app = _atspi_application_new (bus_name);
if (!app) return NULL;
- app->bus_name = bus_name_dup;
app->hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
app->bus = dbus_connection_ref (_atspi_bus ());
+ app->cache = ATSPI_CACHE_UNDEFINED;
g_hash_table_insert (app_hash, bus_name_dup, app);
dbus_error_init (&error);
message = dbus_message_new_method_call (bus_name, atspi_path_root,
DBusMessageIter iter, iter_struct;
const char *signature = dbus_message_get_signature (message);
AtspiAccessible *a;
- int id;
if (strcmp (signature, "(so)") != 0)
{
add_app_to_desktop (AtspiAccessible *a, const char *bus_name)
{
DBusError error;
- char *root_path;
dbus_error_init (&error);
AtspiAccessible *obj = ref_accessible (bus_name, atspi_path_root);
static void
add_accessible_from_iter (DBusMessageIter *iter)
{
- gint i;
GList *new_list;
DBusMessageIter iter_struct, iter_array;
const char *app_name, *path;
- AtspiApplication *app;
AtspiAccessible *accessible;
const char *name, *description;
dbus_uint32_t role;
_atspi_dbus_set_state (accessible, &iter_struct);
dbus_message_iter_next (&iter_struct);
- accessible->cached_properties |= ATSPI_CACHE_NAME | ATSPI_CACHE_ROLE | ATSPI_CACHE_PARENT;
+ _atspi_accessible_add_cache (accessible, ATSPI_CACHE_NAME | ATSPI_CACHE_ROLE |
+ ATSPI_CACHE_PARENT | ATSPI_CACHE_DESCRIPTION);
if (!atspi_state_set_contains (accessible->states,
ATSPI_STATE_MANAGES_DESCENDANTS))
- accessible->cached_properties |= ATSPI_CACHE_CHILDREN;
+ _atspi_accessible_add_cache (accessible, ATSPI_CACHE_CHILDREN);
/* This is a bit of a hack since the cache holds a ref, so we don't need
* the one provided for us anymore */
static void
handle_get_items (DBusPendingCall *pending, void *user_data)
{
- AtspiApplication *app = user_data;
DBusMessage *reply = dbus_pending_call_steal_reply (pending);
DBusMessageIter iter, iter_array;
ref_accessible_desktop (AtspiApplication *app)
{
DBusError error;
- GArray *apps = NULL;
- GArray *additions;
- gint i;
DBusMessage *message, *reply;
DBusMessageIter iter, iter_array;
gchar *bus_name_dup;
atspi_interface_accessible,
"GetChildren");
if (!message)
- return;
- reply = _atspi_dbus_send_with_reply_and_block (message);
+ return NULL;
+ reply = _atspi_dbus_send_with_reply_and_block (message, NULL);
if (!reply || strcmp (dbus_message_get_signature (reply), "a(so)") != 0)
{
- g_error ("Couldn't get application list: %s", error.message);
+ g_warning ("Couldn't get application list: %s", error.message);
if (reply)
dbus_message_unref (reply);
- return;
+ return NULL;
}
dbus_message_iter_init (reply, &iter);
dbus_message_iter_recurse (&iter, &iter_array);
if (!a) return NULL;
if ( APP_IS_REGISTRY(a))
{
- return ref_accessible_desktop (a);
+ return a->root = ref_accessible_desktop (a);
}
return ref_accessible (app, path);
}
{
DBusMessageIter iter;
const char *sender = dbus_message_get_sender (message);
- AtspiApplication *app = get_application (sender);
- const char *type = cache_signal_type;
if (strcmp (dbus_message_get_signature (message), cache_signal_type) != 0)
{
g_warning (_("AT-SPI: AddAccessible with unknown signature %s\n"),
dbus_message_get_signature (message));
- return;
+ return DBUS_HANDLER_RESULT_HANDLED;
}
dbus_message_iter_init (message, &iter);
add_accessible_from_iter (&iter);
+ return DBUS_HANDLER_RESULT_HANDLED;
}
typedef struct
{
int type = dbus_message_get_type (closure->message);
const char *interface = dbus_message_get_interface (closure->message);
- const char *member = dbus_message_get_member (closure->message);
- dbus_uint32_t v;
- char *bus_name;
if (type == DBUS_MESSAGE_TYPE_SIGNAL &&
!strncmp (interface, "org.a11y.atspi.Event.", 21))
static int in_process_deferred_messages = 0;
if (in_process_deferred_messages)
- return;
+ return TRUE;
in_process_deferred_messages = 1;
while (deferred_messages != NULL)
{
{
int type = dbus_message_get_type (message);
const char *interface = dbus_message_get_interface (message);
- const char *member = dbus_message_get_member (message);
- dbus_uint32_t v;
- char *bus_name;
if (type == DBUS_MESSAGE_TYPE_SIGNAL &&
!strncmp (interface, "org.a11y.atspi.Event.", 21))
return canonical_display_name;
}
-/* TODO: Avoid having duplicate functions for this here and in at-spi2-atk */
-static DBusConnection *
-get_accessibility_bus ()
-{
- Atom AT_SPI_BUS;
- Atom actual_type;
- Display *bridge_display;
- int actual_format;
- unsigned char *data = NULL;
- unsigned long nitems;
- unsigned long leftover;
-
- DBusConnection *bus = NULL;
- DBusError error;
-
- bridge_display = XOpenDisplay (spi_display_name ());
- if (!bridge_display)
- {
- g_warning (_("AT-SPI: Could not get the display\n"));
- return NULL;
- }
-
- AT_SPI_BUS = XInternAtom (bridge_display, "AT_SPI_BUS", False);
- XGetWindowProperty (bridge_display,
- XDefaultRootWindow (bridge_display),
- AT_SPI_BUS, 0L,
- (long) BUFSIZ, False,
- (Atom) 31, &actual_type, &actual_format,
- &nitems, &leftover, &data);
- XCloseDisplay (bridge_display);
-
- dbus_error_init (&error);
-
- if (data == NULL)
- {
- g_warning
- (_("AT-SPI: Accessibility bus not found - Using session bus.\n"));
- bus = dbus_bus_get (DBUS_BUS_SESSION, &error);
- if (!bus)
- {
- g_warning (_("AT-SPI: Couldn't connect to bus: %s\n"), error.message);
- return NULL;
- }
- }
- else
- {
- bus = dbus_connection_open (data, &error);
- if (!bus)
- {
- g_warning (_("AT-SPI: Couldn't connect to bus: %s\n"), error.message);
- return NULL;
- }
- else
- {
- if (!dbus_bus_register (bus, &error))
- {
- g_warning (_("AT-SPI: Couldn't register with bus: %s\n"), error.message);
- return NULL;
- }
- }
- }
-
- return bus;
-}
-
/**
* atspi_init:
*
{
DBusError error;
char *match;
- int i;
if (atspi_inited)
{
get_live_refs();
dbus_error_init (&error);
- bus = get_accessibility_bus ();
+ bus = atspi_get_a11y_bus ();
if (!bus)
- {
- g_error ("Couldn't get session bus");
return 2;
- }
dbus_bus_register (bus, &error);
dbus_connection_setup_with_g_main(bus, g_main_context_default());
dbus_connection_add_filter (bus, atspi_dbus_filter, NULL, NULL);
va_list args)
{
AtspiObject *aobj = ATSPI_OBJECT (obj);
- dbus_bool_t retval;
DBusError err;
DBusMessage *msg = NULL, *reply = NULL;
DBusMessageIter iter;
}
DBusMessage *
-_atspi_dbus_send_with_reply_and_block (DBusMessage *message)
+_atspi_dbus_send_with_reply_and_block (DBusMessage *message, GError **error)
{
DBusMessage *reply;
DBusError err;
dbus_message_unref (message);
if (err.message)
{
- g_warning (_("AT-SPI: Got error: %s\n"), err.message);
+ if (error)
+ g_set_error_literal (error, ATSPI_ERROR, ATSPI_ERROR_IPC, err.message);
dbus_error_free (&err);
}
return reply;
{
DBusMessageIter iter_array, iter_dict;
GArray *array = g_array_new (TRUE, TRUE, sizeof (gchar *));
- gint count = 0;
dbus_message_iter_recurse (iter, &iter_array);
while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
accessible->interfaces |= (1 << n);
dbus_message_iter_next (&iter_array);
}
- accessible->cached_properties |= ATSPI_CACHE_INTERFACES;
+ _atspi_accessible_add_cache (accessible, ATSPI_CACHE_INTERFACES);
}
void
else
accessible->states->states = val;
}
- accessible->cached_properties |= ATSPI_CACHE_STATES;
+ _atspi_accessible_add_cache (accessible, ATSPI_CACHE_STATES);
}
GQuark
return g_quark_from_static_string ("atspi_error");
}
+/*
+ * Gets the IOR from the XDisplay.
+ */
+static char *
+get_accessibility_bus_address_x11 (void)
+{
+ Atom AT_SPI_BUS;
+ Atom actual_type;
+ Display *bridge_display;
+ int actual_format;
+ unsigned char *data = NULL;
+ unsigned long nitems;
+ unsigned long leftover;
+
+ bridge_display = XOpenDisplay (spi_display_name ());
+ if (!bridge_display)
+ {
+ g_warning ("Could not open X display");
+ return NULL;
+ }
+
+ AT_SPI_BUS = XInternAtom (bridge_display, "AT_SPI_BUS", False);
+ XGetWindowProperty (bridge_display,
+ XDefaultRootWindow (bridge_display),
+ AT_SPI_BUS, 0L,
+ (long) BUFSIZ, False,
+ (Atom) 31, &actual_type, &actual_format,
+ &nitems, &leftover, &data);
+ XCloseDisplay (bridge_display);
+
+ return g_strdup (data);
+}
+
+static char *
+get_accessibility_bus_address_dbus (void)
+{
+ DBusConnection *session_bus = NULL;
+ DBusMessage *message;
+ DBusMessage *reply;
+ char *address = NULL;
+
+ session_bus = dbus_bus_get (DBUS_BUS_SESSION, NULL);
+ if (!session_bus)
+ return NULL;
+
+ message = dbus_message_new_method_call ("org.a11y.Bus",
+ "/org/a11y/bus",
+ "org.a11y.Bus",
+ "GetAddress");
+
+ reply = dbus_connection_send_with_reply_and_block (session_bus,
+ message,
+ -1,
+ NULL);
+ dbus_message_unref (message);
+
+ if (!reply)
+ return NULL;
+
+ {
+ const char *tmp_address;
+ if (!dbus_message_get_args (reply,
+ NULL,
+ DBUS_TYPE_STRING,
+ &tmp_address,
+ DBUS_TYPE_INVALID))
+ {
+ dbus_message_unref (reply);
+ return NULL;
+ }
+ address = g_strdup (tmp_address);
+ dbus_message_unref (reply);
+ }
+
+ return address;
+}
+
+DBusConnection *
+atspi_get_a11y_bus (void)
+{
+ DBusConnection *bus = NULL;
+ DBusError error;
+ char *address;
+
+ address = get_accessibility_bus_address_x11 ();
+ if (!address)
+ address = get_accessibility_bus_address_dbus ();
+ if (!address)
+ return NULL;
+
+ dbus_error_init (&error);
+ bus = dbus_connection_open (address, &error);
+ if (!bus)
+ {
+ g_warning ("Couldn't connect to accessibility bus: %s", error.message);
+ return NULL;
+ }
+ else
+ {
+ if (!dbus_bus_register (bus, &error))
+ {
+ g_warning ("Couldn't register with accessibility bus: %s", error.message);
+ return NULL;
+ }
+ }
+
+ return bus;
+}