Started fixing IDL docs.
[platform/core/uifw/at-spi2-atk.git] / libspi / registry.c
index a607020..51a3cb4 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::Registry" server
- */
-#include <libspi/Accessibility.h>
 
 /*
  * We'd like to replace the dependance on X-isms with a wrapper layer,
  * Anyone want to help?
  */
 #include <X11/Xlib.h>
+#include <gdk/gdk.h>
 #include <gdk/gdkx.h>
 
-/*
- * This pulls the definition for the BonoboObject (GType)
- */
-#include "registry.h"
+#include <libspi/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 +50,8 @@ typedef enum {
   ETYPE_PROPERTY,
   ETYPE_WINDOW,
   ETYPE_TOOLKIT,
+  ETYPE_KEYBOARD,
+  
   ETYPE_LAST_DEFINED
 } EventTypeCategory;
 
@@ -83,7 +71,7 @@ typedef struct {
 } SpiListenerStruct;
 
 /* static function prototypes */
-static void _registry_notify_listeners ( GList *listeners,
+static void _registry_notify_listeners (GList *listeners,
                                         const Accessibility_Event *e,
                                         CORBA_Environment *ev);
 
@@ -199,7 +187,6 @@ compare_listener_corbaref (gconstpointer p1, gconstpointer p2)
 static void
 parse_event_type (EventTypeStruct *etype, char *event_name)
 {
-  guint nbytes = 0;
   gchar **split_string;
 
   split_string = g_strsplit(event_name, ":", 4);
@@ -271,7 +258,7 @@ impl_accessibility_registry_deregister_application (PortableServer_Servant serva
                                                     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);
+  GList *list = g_list_find_custom (registry->desktop->applications, application, compare_corba_objects);
 
 #ifdef SPI_DEBUG
   gint i;
@@ -285,15 +272,18 @@ impl_accessibility_registry_deregister_application (PortableServer_Servant serva
       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) {
+      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));
-      }
+                      g_list_nth_data (registry->desktop->applications, i));
+        }
 #endif      
     }
   else
-    fprintf (stderr, "could not deregister application\n");
+    {
+      fprintf (stderr, "could not deregister application %p\n", application);
+    }
 }
 
 /*
@@ -309,7 +299,6 @@ impl_accessibility_registry_register_global_event_listener (
   SpiRegistry *registry = SPI_REGISTRY (bonobo_object_from_servant (servant));
   SpiListenerStruct *ls = g_malloc (sizeof (SpiListenerStruct));
   EventTypeStruct etype;
-  gboolean is_toolkit_specific = TRUE;
 
   fprintf(stderr, "registering for events of type %s\n", event_name);
 
@@ -408,9 +397,13 @@ impl_accessibility_registry_deregister_global_event_listener (
       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_listener_hash);
 
@@ -518,6 +511,7 @@ impl_registry_notify_event (PortableServer_Servant servant,
     case (ETYPE_TOOLKIT) :
       _registry_notify_listeners (registry->toolkit_listeners, e, ev); 
       break;
+    case (ETYPE_KEYBOARD) :
     default:
       break;
     }
@@ -532,16 +526,17 @@ _get_unique_id ()
 }
 
 static void
-_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;
+  Accessibility_Event *e_out;
   guint minor_hash;
-  parse_event_type (&etype, e->type);
+  parse_event_type (&etype, e_in->type);
   minor_hash = g_str_hash (g_strconcat (etype.major, etype.minor, NULL));
   len = g_list_length (listeners);
 
@@ -556,13 +551,16 @@ _registry_notify_listeners ( GList *listeners,
         {
 #ifdef SPI_DEBUG
           fprintf(stderr, "notifying listener #%d\n", n);
-          fprintf(stderr, "event source name %s\n", Accessibility_Accessible__get_name(e->source, ev));
+          fprintf(stderr, "event source name %s\n", Accessibility_Accessible__get_name(e_in->source, ev));
 #endif
-         e->source = CORBA_Object_duplicate (e->source, ev);
-          Accessibility_Accessible_ref ( e->source, ev);
+         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,
+                                                   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"),
@@ -573,7 +571,8 @@ _registry_notify_listeners ( GList *listeners,
     }
 }
 
-static gboolean _device_event_controller_hook (gpointer p)
+static gboolean
+_device_event_controller_hook (gpointer p)
 {
     SpiRegistry *registry = (SpiRegistry *)p;
     SpiDeviceEventController *controller = registry->device_event_controller;
@@ -617,46 +616,14 @@ spi_registry_init (SpiRegistry *registry)
   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_Registry__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);
     return retval;
 }