* AT-SPI - Assistive Technology Service Provider Interface
* (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
*
- * Copyright 2001 Sun Microsystems Inc.
+ * Copyright 2001, 2002 Sun Microsystems Inc.,
+ * Copyright 2001, 2002 Ximian, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
/* registry.c: the main accessibility service registry implementation */
+#undef SPI_LISTENER_DEBUG
+#undef SPI_DEBUG
+#undef SPI_QUEUE_DEBUG
+
#include <config.h>
#ifdef SPI_DEBUG
# include <stdio.h>
#endif
-/*
- * We'd like to replace the dependance on X-isms with a wrapper layer,
- * to the extent that it can't be done with pure GDK.
- * Anyone want to help?
- */
-#include <X11/Xlib.h>
-#include <gdk/gdk.h>
-#include <gdk/gdkx.h>
+#include <spi-common/spi-dbus.h>
-#include <libspi/registry.h>
+#include "registry.h"
+#include "dbus/dbus-glib-lowlevel.h"
/* Our parent GObject type */
-#define PARENT_TYPE SPI_LISTENER_TYPE
+#define PARENT_TYPE G_OBJECT_TYPE
-/* A pointer to our parent object class */
-static SpiListenerClass *spi_registry_parent_class;
+int _dbg = 0;
typedef enum {
ETYPE_FOCUS,
ETYPE_WINDOW,
ETYPE_TOOLKIT,
ETYPE_KEYBOARD,
-
+ ETYPE_MOUSE,
ETYPE_LAST_DEFINED
} EventTypeCategory;
typedef struct {
- char *event_name;
+ const char *event_name;
EventTypeCategory type_cat;
- char * major;
- char * minor;
- char * detail;
- guint hash;
+ GQuark major; /* from string segment[1] */
+ GQuark minor; /* from string segment[1]+segment[2] */
+ GQuark detail; /* from string segment[3] (not concatenated) */
} EventTypeStruct;
-typedef struct {
- Accessibility_EventListener listener;
- guint event_type_hash;
- EventTypeCategory event_type_cat;
-} SpiListenerStruct;
+G_DEFINE_TYPE(SpiRegistry, spi_registry, G_TYPE_OBJECT)
-/* static function prototypes */
-static void _registry_notify_listeners (GList *listeners,
- const Accessibility_Event *e,
- CORBA_Environment *ev);
+static void
+spi_registry_set_debug (const char *debug_flag_string)
+{
+ if (debug_flag_string)
+ _dbg = (int) g_ascii_strtod (debug_flag_string, NULL);
+}
-static long _get_unique_id();
+static void emit(SpiRegistry *registry, const char *name, int first_type, ...)
+{
+ va_list arg;
-static gboolean _device_event_controller_hook (gpointer source);
+ va_start(arg, first_type);
+ spi_dbus_emit_valist(registry->droute.bus, SPI_DBUS_PATH_DESKTOP, SPI_DBUS_INTERFACE_REGISTRY, name, first_type, arg);
+ va_end(arg);
+}
-/*
- * Implemented GObject::finalize
- */
static void
-spi_registry_object_finalize (GObject *object)
+desktop_add_application (SpiDesktop *desktop,
+ guint index, gpointer data)
{
-/* SpiRegistry *registry = SPI_REGISTRY (object); */
- GObjectClass *object_class = G_OBJECT_GET_CLASS( object);
+ SpiRegistry *registry = SPI_REGISTRY (data);
+ const SpiDesktopApplication *app = g_list_nth_data(desktop->applications, index);
+
+ emit(registry, "applicationAdd", DBUS_TYPE_UINT32, &index, DBUS_TYPE_STRING, &app->bus_name, DBUS_TYPE_INVALID);
+}
+
+
- printf("spi_registry_object_finalize called\n");
+static void
+desktop_remove_application (SpiDesktop *desktop,
+ guint index, gpointer data)
+{
+ SpiRegistry *registry = SPI_REGISTRY (data);
+ SpiDesktopApplication *app = g_list_nth_data(desktop->applications, index);
+
+ spi_dbus_remove_disconnect_match (registry->droute.bus, app->bus_name);
+ emit(registry, "applicationRemove", DBUS_TYPE_UINT32, &index, DBUS_TYPE_STRING, &app->bus_name, DBUS_TYPE_INVALID);
+}
+
+
+static void
+spi_registry_object_finalize (GObject *object)
+{
+ DBG (1, g_warning ("spi_registry_object_finalize called\n"));
+ g_object_unref (SPI_REGISTRY (object)->de_controller);
- object_class->finalize (object);
+ G_OBJECT_CLASS (spi_registry_parent_class)->finalize (object);
}
/**
* Register a new application with the accessibility broker.
*
**/
-static void
-impl_accessibility_registry_register_application (PortableServer_Servant servant,
- const Accessibility_Application application,
- CORBA_Environment * ev)
+static DBusMessage *
+impl_accessibility_registry_register_application (DBusConnection *bus, DBusMessage *message, void *user_data)
{
- SpiRegistry *registry = SPI_REGISTRY (bonobo_object_from_servant (servant));
+ SpiRegistry *registry = SPI_REGISTRY (user_data);
+ const char *application = dbus_message_get_sender (message);
#ifdef SPI_DEBUG
- fprintf (stderr, "registering app %p\n", application);
+ fprintf (stderr, "registering app %s\n", application);
#endif
- registry->desktop->applications = g_list_append (registry->desktop->applications,
- bonobo_object_dup_ref (application, ev));
+ spi_desktop_add_application (registry->desktop, application);
- /* TODO: create unique string here (with libuuid call ?) and hash ? */
- Accessibility_Application__set_id (application, _get_unique_id(), ev);
+ spi_dbus_add_disconnect_match (registry->droute.bus, application);
/*
* TODO: change the implementation below to a WM-aware one;
* e.g. don't add all apps to the SpiDesktop
*/
-}
-
-static gint
-compare_corba_objects (gconstpointer p1, gconstpointer p2)
-{
- CORBA_Environment ev;
- gint retval;
-
-#ifdef SPI_DEBUG
- fprintf (stderr, "comparing %p to %p\n",
- p1, p2);
-#endif
-
- retval = !CORBA_Object_is_equivalent ((CORBA_Object) p1, (CORBA_Object) p2, &ev);
- return retval;
-}
-
-static void
-register_with_toolkits (SpiRegistry *spi_registry_bonobo_object, EventTypeStruct *etype, CORBA_Environment *ev)
-{
- gint n_desktops;
- gint n_apps;
- gint i, j;
- Accessibility_Desktop desktop;
- Accessibility_Application app;
- Accessibility_Registry registry;
- registry = BONOBO_OBJREF (spi_registry_bonobo_object);
-
- /* for each app in each desktop, call ...Application_registerToolkitEventListener */
-
- n_desktops = Accessibility_Registry_getDesktopCount (registry, ev);
-
- for (i=0; i<n_desktops; ++i)
- {
- desktop = Accessibility_Registry_getDesktop (registry, i, ev);
- n_apps = Accessibility_Desktop__get_childCount (desktop, ev);
- for (j=0; j<n_apps; ++j)
- {
- app = (Accessibility_Application) Accessibility_Desktop_getChildAtIndex (desktop,
- j,
- ev);
- Accessibility_Application_registerToolkitEventListener (app,
- registry,
- CORBA_string_dup (etype->event_name),
-
- ev);
- }
- }
-}
-
-static gint
-compare_listener_hash (gconstpointer p1, gconstpointer p2)
-{
- return (((SpiListenerStruct *)p2)->event_type_hash - ((SpiListenerStruct *)p1)->event_type_hash);
-}
-
-static gint
-compare_listener_corbaref (gconstpointer p1, gconstpointer p2)
-{
- return compare_corba_objects (((SpiListenerStruct *)p2)->listener,
- ((SpiListenerStruct *)p1)->listener);
-}
-
-static void
-parse_event_type (EventTypeStruct *etype, char *event_name)
-{
- gchar **split_string;
-
- split_string = g_strsplit(event_name, ":", 4);
- etype->event_name = g_strndup(event_name, 255);
-
- if (!g_ascii_strncasecmp (event_name, "focus:", 6))
- {
- etype->type_cat = ETYPE_FOCUS;
- }
- else if (!g_ascii_strncasecmp (event_name, "object:", 7))
- {
- etype->type_cat = ETYPE_OBJECT;
- }
- else if (!g_ascii_strncasecmp (event_name, "window:", 7))
- {
- etype->type_cat = ETYPE_WINDOW;
- }
- else
- {
- etype->type_cat = ETYPE_TOOLKIT;
- }
-
- if (split_string[1])
- {
- etype->major = split_string[1];
- if (split_string[2])
- {
- etype->minor = split_string[2];
- if (split_string[3])
- {
- etype->detail = split_string[3];
- etype->hash = g_str_hash ( g_strconcat (split_string[1], split_string[2], split_string[3], NULL));
- }
- else
- {
- etype->detail = g_strdup ("");
- etype->hash = g_str_hash ( g_strconcat (split_string[1], split_string[2], NULL));
- }
- }
- else
- {
- etype->minor = g_strdup ("");
- etype->hash = g_str_hash ( split_string[1]);
- }
- }
- else
- {
- etype->major = g_strdup ("");
- etype->minor = g_strdup ("");
- etype->detail = g_strdup ("");
- etype->hash = g_str_hash ("");
- }
-
- /* TODO: don't forget to free the strings from caller when done ! */
+ return dbus_message_new_method_return (message);
}
/**
* De-register an application previously registered with the broker.
*
**/
-static void
-impl_accessibility_registry_deregister_application (PortableServer_Servant servant,
- const Accessibility_Application application,
- CORBA_Environment * ev)
+static DBusMessage *
+impl_accessibility_registry_deregister_application (DBusConnection *bus, DBusMessage *message, void *user_data)
{
- SpiRegistry *registry = SPI_REGISTRY (bonobo_object_from_servant (servant));
- GList *list = g_list_find_custom (registry->desktop->applications, application, compare_corba_objects);
+ SpiRegistry *registry = SPI_REGISTRY (user_data);
+ const char *application = dbus_message_get_sender (message);
-#ifdef SPI_DEBUG
- gint i;
-#endif
+ spi_desktop_remove_application (registry->desktop, application);
- if (list)
- {
#ifdef SPI_DEBUG
- fprintf (stderr, "deregistering application %p\n", application);
+ fprintf (stderr, "de-registered app %s\n", application);
#endif
- registry->desktop->applications = g_list_delete_link (registry->desktop->applications, list);
-#ifdef SPI_DEBUG
- fprintf (stderr, "there are now %d apps registered.\n", g_list_length (registry->desktop->applications));
- for (i = 0; i < g_list_length (registry->desktop->applications); ++i)
- {
- fprintf (stderr, "getting application %d\n", i);
- fprintf (stderr, "object address %p\n",
- g_list_nth_data (registry->desktop->applications, i));
- }
-#endif
- }
- else
- {
- fprintf (stderr, "could not deregister application %p\n", application);
- }
+ return dbus_message_new_method_return (message);
}
-/*
- * CORBA Accessibility::Registry::registerGlobalEventListener method implementation
- */
-static void
-impl_accessibility_registry_register_global_event_listener (
- PortableServer_Servant servant,
- Accessibility_EventListener listener,
- const CORBA_char *event_name,
- CORBA_Environment *ev)
-{
- SpiRegistry *registry = SPI_REGISTRY (bonobo_object_from_servant (servant));
- SpiListenerStruct *ls = g_malloc (sizeof (SpiListenerStruct));
- EventTypeStruct etype;
-
- fprintf(stderr, "registering for events of type %s\n", event_name);
-
- /* parse, check major event type and add listener accordingly */
- parse_event_type (&etype, (char*) event_name);
- ls->event_type_hash = etype.hash;
- ls->event_type_cat = etype.type_cat;
-
- switch (etype.type_cat)
- {
- case (ETYPE_FOCUS) :
- case (ETYPE_OBJECT) :
- case (ETYPE_PROPERTY) :
- ls->listener = CORBA_Object_duplicate (listener, ev);
- registry->object_listeners =
- g_list_append (registry->object_listeners, ls);
- break;
- case (ETYPE_WINDOW) :
- /* Support for Window Manager Events is not yet implemented */
- break;
- case (ETYPE_TOOLKIT) :
- ls->listener = CORBA_Object_duplicate (listener, ev);
- registry->toolkit_listeners =
- g_list_append (registry->toolkit_listeners, ls);
- register_with_toolkits (registry, &etype, ev);
- break;
- default:
- break;
- }
-}
-
-/*
- * CORBA Accessibility::Registry::deregisterGlobalEventListenerAll method implementation
- */
-static void
-impl_accessibility_registry_deregister_global_event_listener_all (
- PortableServer_Servant servant,
- Accessibility_EventListener listener,
- CORBA_Environment *ev)
-{
- SpiRegistry *registry = SPI_REGISTRY (bonobo_object_from_servant (servant));
- SpiListenerStruct *ls = g_malloc (sizeof (SpiListenerStruct));
- GList *list;
- ls->listener = listener;
- list = g_list_find_custom (registry->object_listeners, ls,
- compare_listener_corbaref);
-
- /*
- * TODO : de-register with toolkit if the last instance of a listener
- * to a particular toolkit event type has been deregistered.
- */
-
- while (list)
- {
- fprintf (stderr, "deregistering listener\n");
- registry->object_listeners = g_list_delete_link (registry->object_listeners, list);
- list = g_list_find_custom (registry->object_listeners, ls, compare_listener_corbaref);
- }
- list = g_list_find_custom (registry->toolkit_listeners, ls, compare_listener_corbaref);
- while (list)
- {
- fprintf (stderr, "deregistering listener\n");
- registry->toolkit_listeners = g_list_delete_link (registry->toolkit_listeners, list);
- list = g_list_find_custom (registry->toolkit_listeners, ls, compare_listener_corbaref);
- }
-}
-
-/*
- * CORBA Accessibility::Registry::deregisterGlobalEventListener method implementation
- */
-static void
-impl_accessibility_registry_deregister_global_event_listener (
- PortableServer_Servant servant,
- Accessibility_EventListener listener,
- const CORBA_char * event_name,
- CORBA_Environment *ev)
-{
- SpiRegistry *registry = SPI_REGISTRY (bonobo_object_from_servant (servant));
- SpiListenerStruct ls;
- EventTypeStruct etype;
- GList *list;
- GList **listeners;
-
- parse_event_type (&etype, (char *) event_name);
- switch (etype.type_cat)
- {
- case (ETYPE_OBJECT) :
- case (ETYPE_PROPERTY) :
- case (ETYPE_FOCUS) :
- listeners = ®istry->object_listeners;
- break;
- case (ETYPE_WINDOW) :
- /* Support for Window Manager Events is not yet implemented */
- break;
- case (ETYPE_TOOLKIT) :
- listeners = ®istry->toolkit_listeners;
- break;
- default:
- listeners = NULL;
- break;
- }
-
- if (!listeners)
- return;
-
- ls.event_type_hash = etype.hash;
- list = g_list_find_custom (*listeners, &ls, compare_listener_hash);
-
- while (list)
- {
- fprintf (stderr, "deregistering listener\n");
- *listeners = g_list_delete_link (*listeners, list);
- list = g_list_find_custom (*listeners, &ls, compare_listener_hash);
- }
-}
-
-
/**
* getDesktopCount:
* return values: a short integer indicating the current number of
* Get the current number of desktops.
*
**/
-static short
-impl_accessibility_registry_get_desktop_count (PortableServer_Servant servant,
- CORBA_Environment * ev)
+static DBusMessage *
+impl_accessibility_registry_get_desktop_count (DBusConnection *bus, DBusMessage *message, void *user_data)
{
+ dbus_int16_t n_desktops = 1;
+ DBusMessage *reply;
+
/* TODO: implement support for multiple virtual desktops */
- CORBA_short n_desktops;
- n_desktops = (CORBA_short) 1;
- return n_desktops;
+ reply = dbus_message_new_method_return (message);
+ if (reply)
+ {
+ dbus_message_append_args (reply, DBUS_TYPE_INT16, &n_desktops, DBUS_TYPE_INVALID);
+ }
+ return reply;
}
/**
* Get the nth accessible desktop.
*
**/
-static Accessibility_Desktop
-impl_accessibility_registry_get_desktop (PortableServer_Servant servant,
- const CORBA_short n,
- CORBA_Environment * ev)
+static DBusMessage *
+impl_accessibility_registry_get_desktop (DBusConnection *bus, DBusMessage *message, void *user_data)
{
- SpiRegistry *registry = SPI_REGISTRY (bonobo_object_from_servant (servant));
+ DBusError error;
+ dbus_int16_t n;
+ const char *path;
+ DBusMessage *reply;
/* TODO: implement support for multiple virtual desktops */
- if (n == 0)
- {
- return (Accessibility_Desktop)
- CORBA_Object_duplicate (BONOBO_OBJREF (registry->desktop), ev);
- }
- else
- {
- return (Accessibility_Desktop) CORBA_OBJECT_NIL;
- }
+ dbus_error_init (&error);
+ if (!dbus_message_get_args (message, &error, DBUS_TYPE_INT16, &n, DBUS_TYPE_INVALID))
+ {
+ return spi_dbus_general_error (message);
+ }
+ path = (n == 0? SPI_DBUS_PATH_DESKTOP: "/");
+ reply = dbus_message_new_method_return (message);
+ if (reply)
+ {
+ dbus_message_append_args (reply, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID);
+ }
+ return reply;
}
+
/**
* getDesktopList:
* return values: a sequence containing references to
* Get a list of accessible desktops.
*
**/
-static Accessibility_DesktopSeq *
-impl_accessibility_registry_get_desktop_list (PortableServer_Servant servant,
- CORBA_Environment * ev)
+static DBusMessage *
+impl_accessibility_registry_get_desktop_list (DBusConnection *bus, DBusMessage *message, void *user_data)
{
- /* TODO: implement support for multiple virtual desktops */
- return (Accessibility_DesktopSeq *) NULL;
+ DBusMessage *reply;
+ DBusMessageIter iter, iter_array;
+ const char *path = SPI_DBUS_PATH_DESKTOP;
+
+ reply = dbus_message_new_method_return (message);
+ if (!reply) return NULL;
+ dbus_message_iter_init_append(reply, &iter);
+ if (!dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "o", &iter_array)) goto oom;
+ dbus_message_iter_append_basic(&iter_array, DBUS_TYPE_OBJECT_PATH, &path);
+ if (!dbus_message_iter_close_container (&iter, &iter_array)) goto oom;
+ return reply;
+oom:
+ // TODO: handle out-of-memory
+ return reply;
}
-static Accessibility_DeviceEventController
-impl_accessibility_registry_get_device_event_controller (PortableServer_Servant servant,
- CORBA_Environment * ev)
-{
- SpiRegistry *registry = SPI_REGISTRY (bonobo_object_from_servant (servant));
- if (!registry->device_event_controller)
- registry->device_event_controller = spi_device_event_controller_new (registry);
-
- return CORBA_Object_duplicate (BONOBO_OBJREF (registry->device_event_controller), ev);
-}
-static void
-impl_registry_notify_event (PortableServer_Servant servant,
- const Accessibility_Event *e,
- CORBA_Environment *ev)
+static DBusMessage *
+impl_accessibility_registry_get_device_event_controller (DBusConnection *bus, DBusMessage *message, void *user_data)
{
- SpiRegistry *registry = SPI_REGISTRY (bonobo_object_from_servant (servant));
- EventTypeStruct etype;
-
- parse_event_type (&etype, e->type);
-
- switch (etype.type_cat)
- {
- case (ETYPE_OBJECT) :
- case (ETYPE_PROPERTY) :
- case (ETYPE_FOCUS) :
- _registry_notify_listeners (registry->object_listeners, e, ev);
- break;
- case (ETYPE_WINDOW) :
- _registry_notify_listeners (registry->window_listeners, e, ev);
- break;
- case (ETYPE_TOOLKIT) :
- _registry_notify_listeners (registry->toolkit_listeners, e, ev);
- break;
- case (ETYPE_KEYBOARD) :
- default:
- break;
- }
- /* Accessibility_Accessible_unref (e->source, ev);*/ /* This should be here! */
+ DBusMessage *reply;
+ const char *path = SPI_DBUS_PATH_DEC;
+
+ reply = dbus_message_new_method_return (message);
+ if (reply)
+ {
+ dbus_message_append_args (reply, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID);
+ }
+ return reply;
}
-static long
-_get_unique_id ()
-{
- static long id = 0;
- return ++id;
-}
static void
-_registry_notify_listeners (GList *listeners,
- const Accessibility_Event *e_in,
- CORBA_Environment *ev)
+spi_registry_class_init (SpiRegistryClass *klass)
{
- int n;
- int len;
- SpiListenerStruct *ls;
- EventTypeStruct etype;
- Accessibility_Event *e_out;
- guint minor_hash;
- parse_event_type (&etype, e_in->type);
- minor_hash = g_str_hash (g_strconcat (etype.major, etype.minor, NULL));
- len = g_list_length (listeners);
-
- for (n=0; n<len; ++n)
- {
- ls = (SpiListenerStruct *) g_list_nth_data (listeners, n);
-#ifdef SPI_SPI_LISTENER_DEBUG
- fprintf(stderr, "event hashes: %lx %lx %lx\n", ls->event_type_hash, etype.hash, minor_hash);
- fprintf(stderr, "event name: %s\n", etype.event_name);
-#endif
- if ((ls->event_type_hash == etype.hash) || (ls->event_type_hash == minor_hash))
- {
-#ifdef SPI_DEBUG
- fprintf(stderr, "notifying listener #%d\n", n);
- fprintf(stderr, "event source name %s\n", Accessibility_Accessible__get_name(e_in->source, ev));
-#endif
- e_out = ORBit_copy_value (e_in, TC_Accessibility_Event);
- e_out->source = CORBA_Object_duplicate (e_in->source, ev);
- Accessibility_Accessible_ref ( e_out->source, ev);
- Accessibility_EventListener_notifyEvent ((Accessibility_EventListener) ls->listener,
- e_out,
- ev);
- /* is it safe to free e_out now ? notifyEvent is a oneway... */
- CORBA_free (e_out);
- if (ev->_major != CORBA_NO_EXCEPTION) {
- fprintf(stderr,
- ("Accessibility app error: exception during event notification: %s\n"),
- CORBA_exception_id(ev));
- exit(-1);
- }
- }
- }
-}
+ GObjectClass * object_class = (GObjectClass *) klass;
-static gboolean
-_device_event_controller_hook (gpointer p)
-{
- SpiRegistry *registry = (SpiRegistry *)p;
- SpiDeviceEventController *controller = registry->device_event_controller;
- if (controller)
- spi_device_event_controller_check_key_event (controller);
- return TRUE;
+ spi_registry_parent_class = g_type_class_ref (G_TYPE_OBJECT);
+
+ object_class->finalize = spi_registry_object_finalize;
}
-static void
-spi_registry_class_init (SpiRegistryClass *klass)
+static DBusObjectPathVTable droute_vtable =
{
- GObjectClass * object_class = (GObjectClass *) klass;
- POA_Accessibility_Registry__epv *epv = &klass->epv;
-
- spi_registry_parent_class = g_type_class_ref (SPI_LISTENER_TYPE);
-
- object_class->finalize = spi_registry_object_finalize;
+ NULL,
+ &droute_message,
+ NULL, NULL, NULL, NULL
+};
- epv->registerApplication = impl_accessibility_registry_register_application;
- epv->deregisterApplication = impl_accessibility_registry_deregister_application;
- epv->registerGlobalEventListener = impl_accessibility_registry_register_global_event_listener;
- epv->deregisterGlobalEventListener = impl_accessibility_registry_deregister_global_event_listener;
- epv->deregisterGlobalEventListenerAll = impl_accessibility_registry_deregister_global_event_listener_all;
- epv->getDeviceEventController = impl_accessibility_registry_get_device_event_controller;
- epv->getDesktopCount = impl_accessibility_registry_get_desktop_count;
- epv->getDesktop = impl_accessibility_registry_get_desktop;
- epv->getDesktopList = impl_accessibility_registry_get_desktop_list;
-
- ((SpiListenerClass *) klass)->epv.notifyEvent = impl_registry_notify_event;
+DBusHandlerResult
+disconnect_watch (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ SpiRegistry *registry = SPI_REGISTRY (user_data);
+ const char *name, *old, *new;
+
+ if (!dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged"))
+ {
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+ if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &old, DBUS_TYPE_STRING, &new, DBUS_TYPE_INVALID))
+ {
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+ if (*old != '\0' && *new == '\0')
+ {
+ spi_desktop_remove_application (registry->desktop, old);
+ spi_remove_device_listeners (registry->de_controller, old);
+ }
+ return DBUS_HANDLER_RESULT_HANDLED;
}
static void
spi_registry_init (SpiRegistry *registry)
{
- registry->object_listeners = NULL;
- registry->window_listeners = NULL;
- registry->toolkit_listeners = NULL;
- registry->applications = NULL;
- registry->desktop = spi_desktop_new();
- registry->device_event_controller = NULL;
- registry->kbd_event_hook = _device_event_controller_hook;
-}
+ DBusError error;
-BONOBO_TYPE_FUNC_FULL (SpiRegistry,
- Accessibility_Registry,
- PARENT_TYPE,
- spi_registry);
+ spi_registry_set_debug (g_getenv ("AT_SPI_DEBUG"));
+ /*
+ * TODO: FIXME, this module makes the foolish assumptions that
+ * registryd uses the same display as the apps, and that the
+ * DISPLAY environment variable is set.
+ */
+ gdk_init (NULL, NULL);
+
+ registry->exit_notify_timeout = 200;
+ registry->queue_handler_id = 0;
+
+ dbus_error_init (&error);
+ registry->droute.bus = dbus_bus_get(DBUS_BUS_SESSION, &error);
+ if (!registry->droute.bus)
+ {
+ g_warning("Couldn't connect to dbus: %s\n", error.message);
+ return;
+ }
+ registry->droute.user_data = registry;
+ spi_registry_initialize_registry_interface (®istry->droute);
+ spi_registry_initialize_desktop_interface (®istry->droute);
+ spi_registry_initialize_dec_interface (®istry->droute);
+ // todo: initialize accessible and component interfaces, for desktop?
+ if (!dbus_connection_try_register_fallback (registry->droute.bus, "/org/freedesktop/atspi", &droute_vtable, ®istry->droute, &error))
+ {
+ g_warning("Couldn't register droute.\n");
+ }
+ dbus_connection_setup_with_g_main(registry->droute.bus, g_main_context_default());
+
+ // TODO: decide whether focus_object is still relevant
+ registry->desktop = spi_desktop_new ();
+ /* Register callback notification for application addition and removal */
+ g_signal_connect (G_OBJECT (registry->desktop),
+ "application_added",
+ G_CALLBACK (desktop_add_application),
+ registry);
+
+ g_signal_connect (G_OBJECT (registry->desktop),
+ "application_removed",
+ G_CALLBACK (desktop_remove_application),
+ registry);
+
+ registry->de_controller = spi_device_event_controller_new (registry);
+
+ dbus_connection_add_filter (registry->droute.bus, disconnect_watch, registry, NULL);
+}
SpiRegistry *
spi_registry_new (void)
{
- SpiRegistry *retval = g_object_new (SPI_REGISTRY_TYPE, NULL);
- return retval;
+ SpiRegistry *retval = g_object_new (SPI_REGISTRY_TYPE, NULL);
+ return retval;
}
+
+static DRouteMethod methods[] =
+{
+ { impl_accessibility_registry_register_application , "registerApplication" },
+ { impl_accessibility_registry_deregister_application, "deregisterApplication" },
+ { impl_accessibility_registry_get_desktop_count, "getDesktopCount" },
+ { impl_accessibility_registry_get_desktop, "getDesktop" },
+ { impl_accessibility_registry_get_desktop_list, "getDesktopList" },
+ { impl_accessibility_registry_get_device_event_controller, "getDeviceEventController" },
+ { NULL, NULL }
+};
+
+void
+spi_registry_initialize_registry_interface (DRouteData * data)
+{
+ droute_add_interface (data, "org.freedesktop.atspi.Registry", methods,
+ NULL, NULL, NULL);
+};