* 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
* Boston, MA 02111-1307, USA.
*/
-/*
- * registry.c: test for accessibility implementation
- *
- */
+/* registry.c: the main accessibility service registry implementation */
+#undef SPI_LISTENER_DEBUG
+#undef SPI_DEBUG
+
+#include <config.h>
#ifdef SPI_DEBUG
-#include <stdio.h>
+# include <stdio.h>
#endif
-#include <config.h>
-#include <bonobo/Bonobo.h>
-
-/*
- * This pulls the CORBA definitions for the "Accessibility::Registry" server
- */
-#include <libspi/Accessibility.h>
-/*
- * This pulls the definition for the BonoboObject (GType)
- */
+#include <bonobo/bonobo-exception.h>
+#include "../libspi/spi-private.h"
#include "registry.h"
-/*
- * Our parent GObject type
- */
-#define PARENT_TYPE LISTENER_TYPE
+/* Our parent GObject type */
+#define PARENT_TYPE SPI_LISTENER_TYPE
-/*
- * A pointer to our parent object class
- */
-static ListenerClass *registry_parent_class;
+/* A pointer to our parent object class */
+static SpiListenerClass *spi_registry_parent_class;
+
+int _dbg = 0;
typedef enum {
ETYPE_FOCUS,
+ ETYPE_OBJECT,
+ ETYPE_PROPERTY,
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;
+ GQuark event_type_quark;
EventTypeCategory event_type_cat;
-} ListenerStruct;
+} SpiListenerStruct;
+
+static void
+spi_registry_set_debug (const char *debug_flag_string)
+{
+ if (debug_flag_string)
+ _dbg = (int) g_ascii_strtod (debug_flag_string, NULL);
+}
+
+SpiListenerStruct *
+spi_listener_struct_new (Accessibility_EventListener listener, CORBA_Environment *ev)
+{
+ SpiListenerStruct *retval = g_malloc (sizeof (SpiListenerStruct));
+ retval->listener = bonobo_object_dup_ref (listener, ev);
+ return retval;
+}
+
+
+void
+spi_listener_struct_free (SpiListenerStruct *ls, CORBA_Environment *ev)
+{
+ bonobo_object_release_unref (ls->listener, ev);
+ g_free (ls);
+}
+
+static void
+desktop_add_application (SpiDesktop *desktop,
+ guint index, gpointer data)
+{
+ BonoboObject *registry = BONOBO_OBJECT (data);
+ Accessibility_Event e;
+ CORBA_Environment ev;
+ Accessibility_Accessible a;
+
+ CORBA_exception_init (&ev);
+ e.type = "object:children-changed:add";
+ e.source = BONOBO_OBJREF (desktop);
+ e.detail1 = index;
+ e.detail2 = 0;
+ a = Accessibility_Accessible_getChildAtIndex (BONOBO_OBJREF (desktop),
+ index, &ev);
+ /* FIXME
+ spi_init_any_object (&e.any_data, a);
+ */
+ spi_init_any_nil (&e.any_data);
+ Accessibility_Registry_notifyEvent (BONOBO_OBJREF (registry),
+ &e, &ev);
+ bonobo_object_release_unref (a, &ev);
+ CORBA_exception_free (&ev);
+}
+
-/* static function prototypes */
-static void registry_notify_listeners ( GList *listeners,
- const Accessibility_Event *e,
- CORBA_Environment *ev);
-/*
- * Implemented GObject::finalize
- */
static void
-registry_object_finalize (GObject *object)
+desktop_remove_application (SpiDesktop *desktop,
+ guint index, gpointer data)
{
-/* Registry *registry = REGISTRY (object); */
- GObjectClass *object_class = G_OBJECT_GET_CLASS( object);
+ BonoboObject *registry = BONOBO_OBJECT (data);
+ Accessibility_Event e;
+ Accessibility_Accessible a;
+ CORBA_Environment ev;
+
+ CORBA_exception_init (&ev);
+
+ e.type = "object:children-changed:remove";
+ e.source = BONOBO_OBJREF (desktop);
+ e.detail1 = index;
+ e.detail2 = 0;
+ a = Accessibility_Accessible_getChildAtIndex (BONOBO_OBJREF (desktop),
+ index, &ev);
+ /* FIXME
+ spi_init_any_object (&e.any_data, a);
+ */
+ spi_init_any_nil (&e.any_data);
+ Accessibility_Accessible_unref (a, &ev);
+ Accessibility_Registry_notifyEvent (BONOBO_OBJREF (registry),
+ &e, &ev);
+ Accessibility_Desktop_unref (e.source, &ev);
+ CORBA_exception_free (&ev);
+}
- printf("registry_object_finalize called\n");
- object_class->finalize (object);
+static void
+spi_registry_object_finalize (GObject *object)
+{
+ DBG (1, g_warning ("spi_registry_object_finalize called\n"));
+
+ /* TODO: unref deviceeventcontroller, which disconnects key listener */
+ G_OBJECT_CLASS (spi_registry_parent_class)->finalize (object);
+}
+
+static long
+_get_unique_id (void)
+{
+ static long id = 0;
+
+ return ++id;
}
/**
const Accessibility_Application application,
CORBA_Environment * ev)
{
- Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
+ SpiRegistry *registry = SPI_REGISTRY (bonobo_object_from_servant (servant));
#ifdef SPI_DEBUG
fprintf (stderr, "registering app %p\n", application);
#endif
- registry->desktop->applications = g_list_append (registry->desktop->applications,
- CORBA_Object_duplicate (application, ev));
+ spi_desktop_add_application (registry->desktop, application);
- /* TODO: create unique string here (with libuuid call ?) */
- Accessibility_Application__set_id (application, "test-some-unique-string", ev);
+ Accessibility_Application__set_id (application, _get_unique_id (), ev);
/*
* TODO: change the implementation below to a WM-aware one;
- * e.g. don't add all apps to the Desktop
+ * e.g. don't add all apps to the SpiDesktop
*/
}
+#ifdef USE_A_HASH_IN_FUTURE
static gint
-compare_object_hash (gconstpointer p1, gconstpointer p2)
+compare_corba_objects (gconstpointer p1, gconstpointer p2)
{
CORBA_Environment ev;
- long long diff = ((CORBA_Object_hash ((CORBA_Object) p2, (CORBA_unsigned_long) 0, &ev)) -
- (CORBA_Object_hash ((CORBA_Object) p1, (CORBA_unsigned_long) 0, &ev)));
- return ((diff < 0) ? -1 : ((diff > 0) ? 1 : 0));
+ 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;
}
+#endif
static void
-register_with_toolkits (Registry *registry_bonobo_object, EventTypeStruct *etype, CORBA_Environment *ev)
+register_with_toolkits (SpiRegistry *spi_registry_bonobo_object, EventTypeStruct *etype, CORBA_Environment *ev)
{
gint n_desktops;
gint n_apps;
Accessibility_Desktop desktop;
Accessibility_Application app;
Accessibility_Registry registry;
- registry = bonobo_object_corba_objref (bonobo_object (registry_bonobo_object));
+ registry = BONOBO_OBJREF (spi_registry_bonobo_object);
/* for each app in each desktop, call ...Application_registerToolkitEventListener */
app = (Accessibility_Application) Accessibility_Desktop_getChildAtIndex (desktop,
j,
ev);
- /* TODO: should we be ref-ing the registry object before each call ? */
- Accessibility_Application_registerToolkitEventListener (app,
- registry,
- CORBA_string_dup (etype->event_name),
- ev);
+ Accessibility_Application_registerToolkitEventListener (app,
+ registry,
+ CORBA_string_dup (etype->event_name),
+ ev);
}
}
}
+#ifdef USE_A_HASH_IN_FUTURE
+
static gint
-compare_listener_hash (gconstpointer p1, gconstpointer p2)
+compare_listener_quarks (gconstpointer p1, gconstpointer p2)
{
- return (((ListenerStruct *)p2)->event_type_hash - ((ListenerStruct *)p1)->event_type_hash);
+ return (((SpiListenerStruct *)p2)->event_type_quark !=
+ ((SpiListenerStruct *)p1)->event_type_quark);
}
+static gint
+compare_listener_corbaref (gconstpointer p1, gconstpointer p2)
+{
+ return compare_corba_objects (((SpiListenerStruct *)p2)->listener,
+ ((SpiListenerStruct *)p1)->listener);
+}
+#endif
+
static void
-parse_event_type (EventTypeStruct *etype, char *event_name)
+parse_event_type (EventTypeStruct *etype, const char *event_name)
{
- guint nbytes = 0;
gchar **split_string;
+ gchar *s;
- split_string = g_strsplit(event_name, ":", 4);
- etype->event_name = g_strndup(event_name, 255);
+ split_string = g_strsplit (event_name, ":", 4);
+ etype->event_name = event_name;
if (!g_ascii_strncasecmp (event_name, "focus:", 6))
{
etype->type_cat = ETYPE_FOCUS;
}
+ else if (!g_ascii_strncasecmp (event_name, "mouse:", 6))
+ {
+ etype->type_cat = ETYPE_MOUSE;
+ }
+ 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 if (!g_ascii_strncasecmp (event_name, "keyboard:", 9))
+ {
+ etype->type_cat = ETYPE_KEYBOARD;
+ }
else
{
etype->type_cat = ETYPE_TOOLKIT;
if (split_string[1])
{
- etype->major = split_string[1];
+ etype->major = g_quark_from_string (split_string[1]);
if (split_string[2])
{
- etype->minor = split_string[2];
+ etype->minor = g_quark_from_string (s = g_strconcat (split_string[1], split_string[2], NULL));
+ g_free (s);
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));
+ etype->detail = g_quark_from_string (split_string[3]);
}
else
{
- etype->detail = g_strdup ("");
- etype->hash = g_str_hash ( g_strconcat (split_string[1], split_string[2], NULL));
+ etype->detail = g_quark_from_static_string ("");
}
}
else
{
- etype->minor = g_strdup ("");
- etype->hash = g_str_hash ( split_string[1]);
+ etype->minor = etype->major;
+ etype->detail = g_quark_from_static_string (""); //etype->major;
}
}
else
{
- etype->major = g_strdup ("");
- etype->minor = g_strdup ("");
- etype->detail = g_strdup ("");
- etype->hash = g_str_hash ("");
+ etype->major = g_quark_from_static_string ("");
+ etype->minor = etype->major;
+ etype->detail = etype->major;
}
- /* TODO: don't forget to free the strings from caller when done ! */
+ g_strfreev (split_string);
}
/**
const Accessibility_Application application,
CORBA_Environment * ev)
{
- Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
- GList *list = g_list_find_custom (registry->applications, application, compare_object_hash);
- if (list)
+ SpiRegistry *registry = SPI_REGISTRY (bonobo_object_from_servant (servant));
+
+ spi_desktop_remove_application (registry->desktop, application);
+
+#ifdef SPI_DEBUG
+ fprintf (stderr, "de-registered app %p\n", application);
+#endif
+}
+
+static GList **
+get_listener_list (SpiRegistry *registry,
+ EventTypeCategory cat)
+{
+ GList **ret;
+
+ switch (cat)
{
- fprintf (stderr, "deregistering application\n");
- registry->applications = g_list_delete_link (registry->applications, list);
+ case ETYPE_OBJECT:
+ case ETYPE_PROPERTY:
+ case ETYPE_FOCUS:
+ case ETYPE_KEYBOARD:
+ ret = ®istry->object_listeners;
+ break;
+ case ETYPE_WINDOW:
+ ret = ®istry->window_listeners;
+ break;
+ case ETYPE_MOUSE:
+ case ETYPE_TOOLKIT:
+ ret = ®istry->toolkit_listeners;
+ break;
+ default:
+ ret = NULL;
+ break;
}
+ return ret;
}
/*
* 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)
+impl_accessibility_registry_register_global_event_listener (
+ PortableServer_Servant servant,
+ Accessibility_EventListener listener,
+ const CORBA_char *event_name,
+ CORBA_Environment *ev)
{
- Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
- ListenerStruct *ls = g_malloc (sizeof (ListenerStruct));
+ SpiRegistry *registry = SPI_REGISTRY (bonobo_object_from_servant (servant));
+ SpiListenerStruct *ls = spi_listener_struct_new (listener, ev);
EventTypeStruct etype;
+ GList **list;
- fprintf(stderr, "registering for events of type %s\n", event_name);
+#ifdef SPI_LISTENER_DEBUG
+ fprintf (stderr, "registering for events of type %s\n", event_name);
+#endif
/* parse, check major event type and add listener accordingly */
parse_event_type (&etype, event_name);
- ls->event_type_hash = etype.hash;
+ ls->event_type_quark = etype.minor;
ls->event_type_cat = etype.type_cat;
- switch (etype.type_cat)
+ list = get_listener_list (registry, etype.type_cat);
+
+ if (list)
{
- case (ETYPE_FOCUS) :
- ls->listener = CORBA_Object_duplicate (listener, ev);
- registry->focus_listeners =
- g_list_append (registry->focus_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;
+ *list = g_list_prepend (*list, ls);
+
+ if (etype.type_cat == ETYPE_TOOLKIT)
+ {
+ register_with_toolkits (registry, &etype, ev);
+ }
+ }
+ else
+ {
+ spi_listener_struct_free (ls, ev);
}
}
+static SpiReEntrantContinue
+remove_listener_cb (GList * const *list, gpointer user_data)
+{
+ SpiListenerStruct *ls = (SpiListenerStruct *) (*list)->data;
+ CORBA_Environment ev;
+ Accessibility_EventListener listener = user_data;
+
+ CORBA_exception_init (&ev);
+
+ if (CORBA_Object_is_equivalent (ls->listener, listener, &ev))
+ {
+ spi_re_entrant_list_delete_link (list);
+ spi_listener_struct_free (ls, &ev);
+ }
+
+ CORBA_exception_free (&ev);
+
+ return SPI_RE_ENTRANT_CONTINUE;
+}
+
/*
* 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)
+impl_accessibility_registry_deregister_global_event_listener_all (
+ PortableServer_Servant servant,
+ Accessibility_EventListener listener,
+ CORBA_Environment *ev)
{
- Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
- GList *list = g_list_find_custom (registry->focus_listeners, listener, compare_object_hash);
+ int i;
+ GList **lists[3];
+ SpiRegistry *registry = SPI_REGISTRY (bonobo_object_from_servant (servant));
- /*
- * TODO : de-register with toolkit if the last instance of a listener
- * to a particular toolkit event type has been deregistered.
- */
+ lists[0] = ®istry->object_listeners;
+ lists[1] = ®istry->window_listeners;
+ lists[2] = ®istry->toolkit_listeners;
- while (list)
- {
- fprintf (stderr, "deregistering listener\n");
- registry->focus_listeners = g_list_delete_link (registry->focus_listeners, list);
- list = g_list_find_custom (registry->focus_listeners, listener, compare_object_hash);
- }
- list = g_list_find_custom (registry->toolkit_listeners, listener, compare_object_hash);
- while (list)
+ for (i = 0; i < sizeof (lists) / sizeof (lists[0]); i++)
{
- fprintf (stderr, "deregistering listener\n");
- registry->toolkit_listeners = g_list_delete_link (registry->toolkit_listeners, list);
- list = g_list_find_custom (registry->toolkit_listeners, listener, compare_object_hash);
+ spi_re_entrant_list_foreach (lists [i], remove_listener_cb, listener);
}
}
+
/*
* 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)
+impl_accessibility_registry_deregister_global_event_listener (
+ PortableServer_Servant servant,
+ Accessibility_EventListener listener,
+ const CORBA_char *event_name,
+ CORBA_Environment *ev)
{
- Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
- ListenerStruct ls;
+ SpiRegistry *registry;
EventTypeStruct etype;
- GList *list;
- GList **listeners;
- parse_event_type (&etype, event_name);
- switch (etype.type_cat)
- {
- case (ETYPE_FOCUS) :
- listeners = ®istry->focus_listeners;
- break;
- case (ETYPE_WINDOW) :
- /* Support for Window Manager Events is not yet implemented */
- break;
- case (ETYPE_TOOLKIT) :
- listeners = ®istry->toolkit_listeners;
- break;
- default:
- break;
- }
+ registry = SPI_REGISTRY (bonobo_object_from_servant (servant));
- ls.event_type_hash = etype.hash;
- list = g_list_find_custom (*listeners, &ls, compare_listener_hash);
+ parse_event_type (&etype, (char *) event_name);
- while (list)
- {
- fprintf (stderr, "deregistering listener\n");
- *listeners = g_list_delete_link (*listeners, list);
- list = g_list_find_custom (*listeners, &ls, compare_listener_hash);
- }
+ spi_re_entrant_list_foreach (get_listener_list (registry, etype.type_cat),
+ remove_listener_cb, listener);
}
return n_desktops;
}
+
/**
* getDesktop:
* @n: the index of the requested @Desktop.
const CORBA_short n,
CORBA_Environment * ev)
{
- Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
+ SpiRegistry *registry = SPI_REGISTRY (bonobo_object_from_servant (servant));
/* TODO: implement support for multiple virtual desktops */
if (n == 0)
{
return (Accessibility_Desktop)
- CORBA_Object_duplicate (
- bonobo_object_corba_objref (bonobo_object (registry->desktop)), ev);
+ bonobo_object_dup_ref (BONOBO_OBJREF (registry->desktop), ev);
}
else
{
}
}
+
/**
* getDesktopList:
* return values: a sequence containing references to
impl_accessibility_registry_get_desktop_list (PortableServer_Servant servant,
CORBA_Environment * ev)
{
- /* TODO: implement support for multiple virtual desktops */
- return (Accessibility_DesktopSeq *) NULL;
+ SpiRegistry *registry = SPI_REGISTRY (bonobo_object_from_servant (servant));
+ Accessibility_DesktopSeq *desktops;
+
+ desktops = Accessibility_DesktopSeq__alloc ();
+ desktops->_length = desktops->_maximum = 1;
+ desktops->_buffer = Accessibility_DesktopSeq_allocbuf (desktops->_length);
+ desktops->_buffer [0] = bonobo_object_dup_ref (BONOBO_OBJREF (registry->desktop), ev);
+
+ return desktops;
}
-static CORBA_Object
+
+static Accessibility_DeviceEventController
impl_accessibility_registry_get_device_event_controller (PortableServer_Servant servant,
- CORBA_Environment * ev)
+ CORBA_Environment *ev)
{
- /* TODO: not yet implemented! */
- return CORBA_OBJECT_NIL;
+ SpiRegistry *registry = SPI_REGISTRY (bonobo_object_from_servant (servant));
+
+ if (!registry->de_controller)
+ {
+ registry->de_controller = spi_device_event_controller_new (registry);
+ }
+
+ return bonobo_object_dup_ref (BONOBO_OBJREF (registry->de_controller), ev);
}
-static void
-impl_registry_notify_event (PortableServer_Servant servant,
- const Accessibility_Event *e,
- CORBA_Environment *ev)
+typedef struct {
+ CORBA_Environment *ev;
+ Bonobo_Unknown source;
+ EventTypeStruct etype;
+ Accessibility_Event e_out;
+} NotifyContext;
+
+static SpiReEntrantContinue
+notify_listeners_cb (GList * const *list, gpointer user_data)
{
- Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
- EventTypeStruct etype;
+ SpiListenerStruct *ls;
+ NotifyContext *ctx = user_data;
- parse_event_type (&etype, e->type);
+ ls = (*list)->data;
- switch (etype.type_cat)
+#ifdef SPI_LISTENER_DEBUG
+ fprintf (stderr, "event quarks: %lx %lx %lx\n", ls->event_type_quark, ctx->etype.major, ctx->etype.minor);
+ fprintf (stderr, "event name: %s\n", ctx->etype.event_name);
+#endif
+ if ((ls->event_type_quark == ctx->etype.major) ||
+ (ls->event_type_quark == ctx->etype.minor))
{
- case (ETYPE_FOCUS) :
- registry_notify_listeners (registry->focus_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;
- default:
- break;
- }
- bonobo_object_release_unref (e->target, ev);
+#ifdef SPI_DEBUG
+ CORBA_string s;
+ fprintf (stderr, "notifying listener %d\n", 0);
+/* g_list_index (list, l->data)); */
+ s = Accessibility_Accessible__get_name (ctx->source, ctx->ev);
+ fprintf (stderr, "event source name %s\n", s);
+ CORBA_free (s);
+ if (BONOBO_EX (ctx->ev))
+ {
+ CORBA_exception_free (ctx->ev);
+ return SPI_RE_ENTRANT_CONTINUE;
+ }
+#endif
+
+ ctx->e_out.source = ctx->source;
+
+ if ((*list) && (*list)->data == ls)
+ {
+ Accessibility_EventListener_notifyEvent (
+ (Accessibility_EventListener) ls->listener, &ctx->e_out, ctx->ev);
+ if (ctx->ev->_major != CORBA_NO_EXCEPTION)
+ {
+ DBG (1, g_warning ("Accessibility app error: exception during "
+ "event notification: %s\n",
+ CORBA_exception_id (ctx->ev)));
+ CORBA_exception_free (ctx->ev);
+ /* FIXME: check that this item is removed from the list
+ * on system exception by a 'broken' listener */
+ }
+ }
+ }
+
+ return SPI_RE_ENTRANT_CONTINUE;
}
static void
-registry_notify_listeners ( GList *listeners,
+impl_registry_notify_event (PortableServer_Servant servant,
const Accessibility_Event *e,
- CORBA_Environment *ev)
+ CORBA_Environment *ev)
{
- int n;
- int len;
- ListenerStruct *ls;
- EventTypeStruct etype;
- guint minor_hash;
- parse_event_type (&etype, e->type);
- minor_hash = g_str_hash (g_strconcat (etype.major, etype.minor, NULL));
- len = g_list_length (listeners);
+ SpiRegistry *registry;
+ GList **list;
+ NotifyContext ctx;
- for (n=0; n<len; ++n)
+ registry = SPI_REGISTRY (bonobo_object_from_servant (servant));
+
+ parse_event_type (&ctx.etype, e->type);
+
+ list = get_listener_list (registry, ctx.etype.type_cat);
+
+ if (list && *list)
{
- ls = (ListenerStruct *) g_list_nth_data (listeners, n);
-#ifdef SPI_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 name %s\n", Accessibility_Accessible__get_name(e->target, ev));
-#endif
- bonobo_object_dup_ref ( e->target, ev);
- Accessibility_EventListener_notifyEvent ((Accessibility_EventListener) ls->listener,
- e,
- ev);
- if (ev->_major != CORBA_NO_EXCEPTION) {
- fprintf(stderr,
- ("Accessibility app error: exception during event notification: %s\n"),
- CORBA_exception_id(ev));
- exit(-1);
- }
- }
+ ctx.ev = ev;
+ ctx.e_out = *e;
+ ctx.source = e->source;
+ spi_re_entrant_list_foreach (list, notify_listeners_cb, &ctx);
}
}
static void
-registry_class_init (RegistryClass *klass)
+spi_registry_class_init (SpiRegistryClass *klass)
{
- GObjectClass * object_class = (GObjectClass *) klass;
- POA_Accessibility_Registry__epv *epv = &klass->epv;
-
- registry_parent_class = g_type_class_ref (LISTENER_TYPE);
-
- object_class->finalize = registry_object_finalize;
-
- 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->getDesktopCount = impl_accessibility_registry_get_desktop_count;
- epv->getDesktop = impl_accessibility_registry_get_desktop;
- epv->getDesktopList = impl_accessibility_registry_get_desktop_list;
- epv->getDeviceEventController = impl_accessibility_registry_get_device_event_controller;
- ((ListenerClass *) klass)->epv.notifyEvent = impl_registry_notify_event;
+ 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;
+
+ klass->parent_class.epv.notifyEvent = impl_registry_notify_event;
+
+ 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;
}
static void
-registry_init (Registry *registry)
+spi_registry_init (SpiRegistry *registry)
{
- registry->focus_listeners = NULL;
+ 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->object_listeners = NULL;
registry->window_listeners = NULL;
registry->toolkit_listeners = NULL;
- registry->applications = NULL;
- registry->desktop = desktop_new();
+ 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);
}
-GType
-registry_get_type (void)
-{
- static GType type = 0;
-
- if (!type) {
- static const GTypeInfo tinfo = {
- sizeof (RegistryClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) registry_class_init,
- (GClassFinalizeFunc) NULL,
- NULL, /* class data */
- sizeof (Registry),
- 0, /* n preallocs */
- (GInstanceInitFunc) registry_init,
- NULL /* value table */
- };
- /*
- * Here we use bonobo_type_unique instead of
- * gtk_type_unique, this auto-generates a load of
- * CORBA structures for us. All derived types must
- * use bonobo_type_unique.
- */
- type = bonobo_type_unique (
- PARENT_TYPE,
- POA_Accessibility_Registry__init,
- NULL,
- G_STRUCT_OFFSET (RegistryClass, epv),
- &tinfo,
- "Registry");
- }
-
- return type;
-}
+BONOBO_TYPE_FUNC_FULL (SpiRegistry,
+ Accessibility_Registry,
+ PARENT_TYPE,
+ spi_registry);
-Registry *
-registry_new (void)
+SpiRegistry *
+spi_registry_new (void)
{
- Registry *retval =
- REGISTRY (g_object_new (registry_get_type (), NULL));
- return retval;
+ SpiRegistry *retval = g_object_new (SPI_REGISTRY_TYPE, NULL);
+ bonobo_object_set_immortal (BONOBO_OBJECT (retval), TRUE);
+ return retval;
}