Removed po directory from Makefile.am for now.
[platform/core/uifw/at-spi2-atk.git] / libspi / registry.c
index 782beaa..f2fabf5 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
-/*
- * registry.c: the main accessibility service registry implementation
- */
+/* registry.c: the main accessibility service registry implementation */
 
+#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::SpiRegistry" server
- */
-#include <libspi/Accessibility.h>
+#include <libspi/registry.h>
 
-/*
- * 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/gdkx.h>
-
-/*
- * This pulls the definition for the BonoboObject (GType)
- */
-#include "registry.h"
-
-/*
- * Our parent GObject type
- */
+/* Our parent GObject type  */
 #define PARENT_TYPE SPI_LISTENER_TYPE
 
-/*
- * A pointer to our parent object class
- */
+/* A pointer to our parent object class */
 static SpiListenerClass *spi_registry_parent_class;
 
 typedef enum {
@@ -64,6 +41,8 @@ typedef enum {
   ETYPE_PROPERTY,
   ETYPE_WINDOW,
   ETYPE_TOOLKIT,
+  ETYPE_KEYBOARD,
+  
   ETYPE_LAST_DEFINED
 } EventTypeCategory;
 
@@ -83,39 +62,51 @@ typedef struct {
 } SpiListenerStruct;
 
 /* static function prototypes */
-static void _spi_registry_notify_listeners ( GList *listeners,
+static void _registry_notify_listeners (GList *listeners,
                                         const Accessibility_Event *e,
                                         CORBA_Environment *ev);
 
 static long _get_unique_id();
 
-static gboolean _spi_device_event_controller_hook (gpointer source);
+static gboolean _device_event_controller_hook (gpointer source);
 
-/*
- * Implemented GObject::finalize
- */
+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);
+}
+
+/* GObject::finalize */
 static void
 spi_registry_object_finalize (GObject *object)
 {
-/*        SpiRegistry *registry = SPI_REGISTRY (object); */
-        GObjectClass *object_class = G_OBJECT_GET_CLASS( object);
+        SpiRegistry *registry = SPI_REGISTRY (object);
 
         printf("spi_registry_object_finalize called\n");
-
-        object_class->finalize (object);
+       /* TODO: unref deviceeventcontroller, which disconnects key listener */
+        G_OBJECT_CLASS (spi_registry_parent_class)->finalize (object);
 }
 
 /**
- * registerSpiApplication:
- * @application: a reference to the requesting @SpiApplication
+ * registerApplication:
+ * @application: a reference to the requesting @Application
  * return values: void
  *
  * Register a new application with the accessibility broker.
  *
  **/
 static void
-impl_accessibility_spi_registry_register_application (PortableServer_Servant servant,
-                                                  const Accessibility_SpiApplication application,
+impl_accessibility_registry_register_application (PortableServer_Servant servant,
+                                                  const Accessibility_Application application,
                                                   CORBA_Environment * ev)
 {
   SpiRegistry *registry = SPI_REGISTRY (bonobo_object_from_servant (servant));
@@ -123,11 +114,9 @@ impl_accessibility_spi_registry_register_application (PortableServer_Servant ser
 #ifdef SPI_DEBUG
   fprintf (stderr, "registering app %p\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_SpiApplication__set_id (application, _get_unique_id(), ev);
+  Accessibility_Application__set_id (application, _get_unique_id(), ev);
 
   /*
    * TODO: change the implementation below to a WM-aware one;
@@ -156,25 +145,25 @@ register_with_toolkits (SpiRegistry *spi_registry_bonobo_object, EventTypeStruct
   gint n_desktops;
   gint n_apps;
   gint i, j;
-  Accessibility_SpiDesktop desktop;
-  Accessibility_SpiApplication app;
-  Accessibility_SpiRegistry registry;
+  Accessibility_Desktop desktop;
+  Accessibility_Application app;
+  Accessibility_Registry registry;
   registry  = BONOBO_OBJREF (spi_registry_bonobo_object);
 
-  /* for each app in each desktop, call ...SpiApplication_registerToolkitEventListener */
+  /* for each app in each desktop, call ...Application_registerToolkitEventListener */
 
-  n_desktops = Accessibility_SpiRegistry_getDesktopCount (registry, ev);
+  n_desktops = Accessibility_Registry_getDesktopCount (registry, ev);
 
   for (i=0; i<n_desktops; ++i)
     {
-      desktop = Accessibility_SpiRegistry_getDesktop (registry, i, ev);
-      n_apps = Accessibility_SpiDesktop__get_childCount (desktop, ev);
+      desktop = Accessibility_Registry_getDesktop (registry, i, ev);
+      n_apps = Accessibility_Desktop__get_childCount (desktop, ev);
       for (j=0; j<n_apps; ++j)
         {
-          app = (Accessibility_SpiApplication) Accessibility_SpiDesktop_getChildAtIndex (desktop,
+          app = (Accessibility_Application) Accessibility_Desktop_getChildAtIndex (desktop,
                                                                                    j,
                                                                                    ev);
-         Accessibility_SpiApplication_registerToolkitEventListener (app,
+         Accessibility_Application_registerToolkitEventListener (app,
                                                                  registry,
                                                                  CORBA_string_dup (etype->event_name),
                                                                  
@@ -184,13 +173,13 @@ register_with_toolkits (SpiRegistry *spi_registry_bonobo_object, EventTypeStruct
 }
 
 static gint
-compare_spi_listener_hash (gconstpointer p1, gconstpointer p2)
+compare_listener_hash (gconstpointer p1, gconstpointer p2)
 {
   return (((SpiListenerStruct *)p2)->event_type_hash - ((SpiListenerStruct *)p1)->event_type_hash);
 }
 
 static gint
-compare_spi_listener_corbaref (gconstpointer p1, gconstpointer p2)
+compare_listener_corbaref (gconstpointer p1, gconstpointer p2)
 {
   return compare_corba_objects (((SpiListenerStruct *)p2)->listener,
                                 ((SpiListenerStruct *)p1)->listener);
@@ -199,8 +188,8 @@ compare_spi_listener_corbaref (gconstpointer p1, gconstpointer p2)
 static void
 parse_event_type (EventTypeStruct *etype, 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);
@@ -224,19 +213,23 @@ parse_event_type (EventTypeStruct *etype, char *event_name)
 
   if (split_string[1])
     {
-      etype->major = split_string[1];
+      etype->major = g_strdup (split_string[1]);
       if (split_string[2])
         {
-          etype->minor = split_string[2];
+          etype->minor = g_strdup (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));
+              etype->detail = g_strdup (split_string[3]);
+             s = g_strconcat (split_string[1], split_string[2], split_string[3], NULL);
+              etype->hash = g_str_hash (s);
+             g_free (s);
             }
           else
             {
               etype->detail = g_strdup ("");
-              etype->hash = g_str_hash ( g_strconcat (split_string[1], split_string[2], NULL));
+             s = g_strconcat (split_string[1], split_string[2], NULL);
+             etype->hash = g_str_hash (s);
+             g_free (s);
             }
         }
       else
@@ -253,12 +246,12 @@ parse_event_type (EventTypeStruct *etype, char *event_name)
       etype->hash = g_str_hash ("");
     }
 
-  /* TODO: don't forget to free the strings from caller when done ! */
+  g_strfreev (split_string);
 }
 
 /**
- * deregisterSpiApplication:
- * @application: a reference to the @SpiApplication
+ * deregisterApplication:
+ * @application: a reference to the @Application
  * to be deregistered.
  * return values: void
  *
@@ -266,55 +259,37 @@ parse_event_type (EventTypeStruct *etype, char *event_name)
  *
  **/
 static void
-impl_accessibility_spi_registry_deregister_application (PortableServer_Servant servant,
-                                                    const Accessibility_SpiApplication application,
+impl_accessibility_registry_deregister_application (PortableServer_Servant servant,
+                                                    const Accessibility_Application application,
                                                     CORBA_Environment * ev)
 {
   SpiRegistry *registry = SPI_REGISTRY (bonobo_object_from_servant (servant));
-  GList *list = g_list_find_custom (registry->desktop->applications, &application, compare_corba_objects);
 
-#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 %p\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\n");
 }
 
 /*
- * CORBA Accessibility::SpiRegistry::registerGlobalEventListener method implementation
+ * CORBA Accessibility::Registry::registerGlobalEventListener method implementation
  */
 static void
-impl_accessibility_spi_registry_register_global_event_listener (
+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));
+  SpiListenerStruct *ls = spi_listener_struct_new (listener, ev);
   EventTypeStruct etype;
-  gboolean is_toolkit_specific = TRUE;
 
   fprintf(stderr, "registering for events of type %s\n", event_name);
 
   /* parse, check major event type and add listener accordingly */
-  parse_event_type (&etype, event_name);
+  parse_event_type (&etype, (char*) event_name);
   ls->event_type_hash = etype.hash;
   ls->event_type_cat = etype.type_cat;
 
@@ -323,39 +298,38 @@ impl_accessibility_spi_registry_register_global_event_listener (
     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 */
+      spi_listener_struct_free (ls, ev);
       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:
+      spi_listener_struct_free (ls, ev);
       break;
     }
 }
 
 /*
- * CORBA Accessibility::SpiRegistry::deregisterGlobalEventListenerAll method implementation
+ * CORBA Accessibility::Registry::deregisterGlobalEventListenerAll method implementation
  */
 static void
-impl_accessibility_spi_registry_deregister_global_event_spi_listener_all (
+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));
+  SpiListenerStruct *ls = spi_listener_struct_new (listener, ev);
   GList *list;
-  ls->listener = listener;  
   list = g_list_find_custom (registry->object_listeners, ls,
-                            compare_spi_listener_corbaref);
+                            compare_listener_corbaref);
 
   /*
    * TODO : de-register with toolkit if the last instance of a listener
@@ -364,24 +338,25 @@ impl_accessibility_spi_registry_deregister_global_event_spi_listener_all (
 
   while (list)
     {
-      fprintf (stderr, "deregistering listener\n");
+      spi_listener_struct_free ((SpiListenerStruct *) list->data, ev);
       registry->object_listeners = g_list_delete_link (registry->object_listeners, list);
-      list = g_list_find_custom (registry->object_listeners, ls, compare_spi_listener_corbaref);
+      list = g_list_find_custom (registry->object_listeners, ls, compare_listener_corbaref);
     }
-  list = g_list_find_custom (registry->toolkit_listeners, ls, compare_spi_listener_corbaref);
+  list = g_list_find_custom (registry->toolkit_listeners, ls, compare_listener_corbaref);
   while (list)
     {
-      fprintf (stderr, "deregistering listener\n");
+      spi_listener_struct_free ((SpiListenerStruct *) list->data, ev);
       registry->toolkit_listeners = g_list_delete_link (registry->toolkit_listeners, list);
-      list = g_list_find_custom (registry->toolkit_listeners, ls, compare_spi_listener_corbaref);
+      list = g_list_find_custom (registry->toolkit_listeners, ls, compare_listener_corbaref);
     }
+  spi_listener_struct_free (ls, ev);
 }
 
 /*
- * CORBA Accessibility::SpiRegistry::deregisterGlobalEventListener method implementation
+ * CORBA Accessibility::Registry::deregisterGlobalEventListener method implementation
  */
 static void
-impl_accessibility_spi_registry_deregister_global_event_listener (
+impl_accessibility_registry_deregister_global_event_listener (
                                                     PortableServer_Servant  servant,
                                                     Accessibility_EventListener listener,
                                                     const CORBA_char * event_name,
@@ -393,7 +368,7 @@ impl_accessibility_spi_registry_deregister_global_event_listener (
   GList *list;
   GList **listeners;
 
-  parse_event_type (&etype, event_name);
+  parse_event_type (&etype, (char *) event_name);
   switch (etype.type_cat)
     {
     case (ETYPE_OBJECT) :
@@ -403,22 +378,27 @@ impl_accessibility_spi_registry_deregister_global_event_listener (
       break;
     case (ETYPE_WINDOW) :
       /* Support for Window Manager Events is not yet implemented */
+      listeners = NULL;
       break;
     case (ETYPE_TOOLKIT) :
       listeners = &registry->toolkit_listeners;
       break;
     default:
+      listeners = NULL;
       break;
     }
 
+  if (!listeners)
+         return;
+
   ls.event_type_hash = etype.hash;
-  list = g_list_find_custom (*listeners, &ls, compare_spi_listener_hash);
+  list = g_list_find_custom (*listeners, &ls, compare_listener_hash);
 
   while (list)
     {
-      fprintf (stderr, "deregistering listener\n");
+      spi_listener_struct_free ((SpiListenerStruct *) list->data, ev);
       *listeners = g_list_delete_link (*listeners, list);
-      list = g_list_find_custom (*listeners, &ls, compare_spi_listener_hash);
+      list = g_list_find_custom (*listeners, &ls, compare_listener_hash);
     }
 }
 
@@ -426,13 +406,13 @@ impl_accessibility_spi_registry_deregister_global_event_listener (
 /**
  * getDesktopCount:
  * return values: a short integer indicating the current number of
- * @SpiDesktops.
+ * @Desktops.
  *
  * Get the current number of desktops.
  *
  **/
 static short
-impl_accessibility_spi_registry_get_spi_desktop_count (PortableServer_Servant servant,
+impl_accessibility_registry_get_desktop_count (PortableServer_Servant servant,
                                                CORBA_Environment * ev)
 {
   /* TODO: implement support for multiple virtual desktops */
@@ -443,14 +423,14 @@ impl_accessibility_spi_registry_get_spi_desktop_count (PortableServer_Servant se
 
 /**
  * getDesktop:
- * @n: the index of the requested @SpiDesktop.
- * return values: a reference to the requested @SpiDesktop.
+ * @n: the index of the requested @Desktop.
+ * return values: a reference to the requested @Desktop.
  *
  * Get the nth accessible desktop.
  *
  **/
-static Accessibility_SpiDesktop
-impl_accessibility_spi_registry_get_desktop (PortableServer_Servant servant,
+static Accessibility_Desktop
+impl_accessibility_registry_get_desktop (PortableServer_Servant servant,
                                          const CORBA_short n,
                                          CORBA_Environment * ev)
 {
@@ -459,43 +439,44 @@ impl_accessibility_spi_registry_get_desktop (PortableServer_Servant servant,
   /* TODO: implement support for multiple virtual desktops */
   if (n == 0)
     {
-      return (Accessibility_SpiDesktop)
-        CORBA_Object_duplicate (BONOBO_OBJREF (registry->desktop), ev);
+      return (Accessibility_Desktop)
+        bonobo_object_dup_ref (BONOBO_OBJREF (registry->desktop), ev);
     }
   else
     {
-      return (Accessibility_SpiDesktop) CORBA_OBJECT_NIL;
+      return (Accessibility_Desktop) CORBA_OBJECT_NIL;
     }
 }
 
 /**
  * getDesktopList:
  * return values: a sequence containing references to
- * the @SpiDesktops.
+ * the @Desktops.
  *
  * Get a list of accessible desktops.
  *
  **/
-static Accessibility_SpiDesktopSeq *
-impl_accessibility_spi_registry_get_spi_desktop_list (PortableServer_Servant servant,
+static Accessibility_DesktopSeq *
+impl_accessibility_registry_get_desktop_list (PortableServer_Servant servant,
                                               CORBA_Environment * ev)
 {
   /* TODO: implement support for multiple virtual desktops */
-  return (Accessibility_SpiDesktopSeq *) NULL;
+  return (Accessibility_DesktopSeq *) NULL;
 }
 
-static Accessibility_SpiDeviceEventController
-impl_accessibility_spi_registry_get_device_event_controller (PortableServer_Servant servant,
+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 = g_object_new (SPI_DEVICE_EVENT_CONTROLLER_TYPE, NULL);
-  return CORBA_Object_duplicate (BONOBO_OBJREF (registry->device_event_controller), ev);
+    registry->device_event_controller = spi_device_event_controller_new (registry);
+
+  return bonobo_object_dup_ref (BONOBO_OBJREF (registry->device_event_controller), ev);
 }
 
 static void
-impl_spi_registry_notify_event (PortableServer_Servant servant,
+impl_registry_notify_event (PortableServer_Servant servant,
                             const Accessibility_Event *e,
                             CORBA_Environment *ev)
 {
@@ -509,18 +490,22 @@ impl_spi_registry_notify_event (PortableServer_Servant servant,
     case (ETYPE_OBJECT) :
     case (ETYPE_PROPERTY) :
     case (ETYPE_FOCUS) :
-      _spi_registry_notify_listeners (registry->object_listeners, e, ev); 
+      _registry_notify_listeners (registry->object_listeners, e, ev); 
       break;
     case (ETYPE_WINDOW) :
-      _spi_registry_notify_listeners (registry->window_listeners, e, ev);
+      _registry_notify_listeners (registry->window_listeners, e, ev);
       break;
     case (ETYPE_TOOLKIT) :
-      _spi_registry_notify_listeners (registry->toolkit_listeners, e, ev); 
+      _registry_notify_listeners (registry->toolkit_listeners, e, ev); 
       break;
+    case (ETYPE_KEYBOARD) :
     default:
       break;
     }
-  /* Accessibility_SpiAccessible_unref (e->source, ev);*/ /* This should be here! */
+  if (e->source != CORBA_OBJECT_NIL)
+    {
+      Accessibility_Accessible_unref (e->source, ev);
+    }
 }
 
 static long
@@ -530,49 +515,59 @@ _get_unique_id ()
   return ++id;
 }
 
+#define SPI_DEBUG
+
 static void
-_spi_registry_notify_listeners ( GList *listeners,
-                            const Accessibility_Event *e,
+_registry_notify_listeners (GList *listeners,
+                            const Accessibility_Event *e_in,
                             CORBA_Environment *ev)
 {
-  int n;
-  int len;
-  SpiListenerStruct *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);
+  GList              *l;
+  Accessibility_Event e_out;
+  SpiListenerStruct  *ls;
+  EventTypeStruct     etype;
+  guint               minor_hash;
+  CORBA_string        s;
 
-  for (n=0; n<len; ++n)
+  e_out = *e_in;
+  parse_event_type (&etype, e_in->type);
+
+  s = g_strconcat (etype.major, etype.minor, NULL);
+  minor_hash = g_str_hash (s);
+  g_free (s);
+
+  for (l = listeners; l; l = l->next)
     {
-      ls =  (SpiListenerStruct *) g_list_nth_data (listeners, n);
+      ls = (SpiListenerStruct *) l->data;
+
 #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);
+      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_SpiAccessible__get_name(e->source, ev));
+          fprintf (stderr, "notifying listener %d\n", g_list_index (listeners, l->data));
+          s = Accessibility_Accessible__get_name (e_in->source, ev);
+         fprintf (stderr, "event source name %s\n", s);
+         CORBA_free (s);
 #endif
-         e->source = CORBA_Object_duplicate (e->source, ev);
-          Accessibility_SpiAccessible_ref ( e->source, ev);
+         e_out.source = bonobo_object_dup_ref (e_in->source, ev);
           Accessibility_EventListener_notifyEvent ((Accessibility_EventListener) ls->listener,
-                                                   e,
+                                                   &e_out,
                                                    ev);
-          if (ev->_major != CORBA_NO_EXCEPTION) {
-                fprintf(stderr,
-                ("Accessibility app error: exception during event notification: %s\n"),
-                        CORBA_exception_id(ev));
-                exit(-1);
-          }
+          if (ev->_major != CORBA_NO_EXCEPTION)
+            {
+              g_error ("Accessibility app error: exception during event notification: %s\n",
+                      CORBA_exception_id (ev));
+           }
         }
     }
 }
 
-static gboolean _spi_device_event_controller_hook (gpointer p)
+static gboolean
+_device_event_controller_hook (gpointer p)
 {
     SpiRegistry *registry = (SpiRegistry *)p;
     SpiDeviceEventController *controller = registry->device_event_controller;
@@ -585,23 +580,23 @@ static void
 spi_registry_class_init (SpiRegistryClass *klass)
 {
         GObjectClass * object_class = (GObjectClass *) klass;
-        POA_Accessibility_SpiRegistry__epv *epv = &klass->epv;
+        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;
 
-        epv->registerSpiApplication = impl_accessibility_spi_registry_register_application;
-        epv->deregisterSpiApplication = impl_accessibility_spi_registry_deregister_application;
-        epv->registerGlobalEventListener = impl_accessibility_spi_registry_register_global_event_listener;
-        epv->deregisterGlobalEventListener = impl_accessibility_spi_registry_deregister_global_event_listener;
-        epv->deregisterGlobalEventListenerAll = impl_accessibility_spi_registry_deregister_global_event_spi_listener_all;
-        epv->getDeviceEventController = impl_accessibility_spi_registry_get_device_event_controller;
-        epv->getDesktopCount = impl_accessibility_spi_registry_get_spi_desktop_count;
-        epv->getDesktop = impl_accessibility_spi_registry_get_desktop;
-        epv->getDesktopList = impl_accessibility_spi_registry_get_spi_desktop_list;
-
-        ((SpiListenerClass *) klass)->epv.notifyEvent = impl_spi_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;
+
+        ((SpiListenerClass *) klass)->epv.notifyEvent = impl_registry_notify_event;
 }
 
 static void
@@ -610,52 +605,20 @@ 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 = _spi_device_event_controller_hook;
+  registry->kbd_event_hook = _device_event_controller_hook;
 }
 
-GType
-spi_registry_get_type (void)
-{
-        static GType type = 0;
-
-        if (!type) {
-                static const GTypeInfo tinfo = {
-                        sizeof (SpiRegistryClass),
-                        (GBaseInitFunc) NULL,
-                        (GBaseFinalizeFunc) NULL,
-                        (GClassInitFunc) spi_registry_class_init,
-                        (GClassFinalizeFunc) NULL,
-                        NULL, /* class data */
-                        sizeof (SpiRegistry),
-                        0, /* n preallocs */
-                        (GInstanceInitFunc) spi_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_SpiRegistry__init,
-                        NULL,
-                        G_STRUCT_OFFSET (SpiRegistryClass, epv),
-                        &tinfo,
-                        "SpiRegistry");
-        }
-
-        return type;
-}
+BONOBO_TYPE_FUNC_FULL (SpiRegistry,
+                      Accessibility_Registry,
+                      PARENT_TYPE,
+                      spi_registry);
 
 SpiRegistry *
 spi_registry_new (void)
 {
-    SpiRegistry *retval =
-               SPI_REGISTRY (g_object_new (spi_registry_get_type (), NULL));
+    SpiRegistry *retval = g_object_new (SPI_REGISTRY_TYPE, NULL);
+    bonobo_object_set_immortal (BONOBO_OBJECT (retval), TRUE);
     return retval;
 }