* registryd/Makefile: Add CLEANFILES so that .server file is removed
[platform/core/uifw/at-spi2-atk.git] / registryd / registry.c
index 17682c2..417847a 100644 (file)
@@ -2,7 +2,8 @@
  * 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
@@ -47,12 +48,12 @@ typedef enum {
   ETYPE_WINDOW,
   ETYPE_TOOLKIT,
   ETYPE_KEYBOARD,
-  
+  ETYPE_MOUSE,
   ETYPE_LAST_DEFINED
 } EventTypeCategory;
 
 typedef struct {
-  char *event_name;
+  const char *event_name;
   EventTypeCategory type_cat;
   GQuark major;  /* from string segment[1] */
   GQuark minor;  /* from string segment[1]+segment[2] */
@@ -65,7 +66,6 @@ typedef struct {
   EventTypeCategory event_type_cat;
 } SpiListenerStruct;
 
-
 SpiListenerStruct *
 spi_listener_struct_new (Accessibility_EventListener listener, CORBA_Environment *ev)
 {
@@ -82,7 +82,6 @@ spi_listener_struct_free (SpiListenerStruct *ls, CORBA_Environment *ev)
   g_free (ls);
 }
 
-
 static void
 desktop_add_application (SpiDesktop *desktop,
                         guint index, gpointer data)
@@ -91,13 +90,14 @@ desktop_add_application (SpiDesktop *desktop,
   Accessibility_Event e;
   CORBA_Environment ev;
   
-  e.type = g_strdup ("object:children-changed:add");
+  e.type = "object:children-changed:add";
   e.source = BONOBO_OBJREF (desktop);
   e.detail1 = index;
   e.detail2 = 0;
   CORBA_exception_init (&ev);
   Accessibility_Registry_notifyEvent (BONOBO_OBJREF (registry),
                                      &e, &ev);
+  Accessibility_Desktop_unref (e.source, &ev);
   CORBA_exception_free (&ev);
 }
 
@@ -111,13 +111,14 @@ desktop_remove_application (SpiDesktop *desktop,
   Accessibility_Event e;
   CORBA_Environment ev;
   
-  e.type = g_strdup ("object:children-changed:remove");
+  e.type = "object:children-changed:remove";
   e.source = BONOBO_OBJREF (desktop);
   e.detail1 = index;
   e.detail2 = 0;
   CORBA_exception_init (&ev);
   Accessibility_Registry_notifyEvent (BONOBO_OBJREF (registry),
                                      &e, &ev);
+  Accessibility_Desktop_unref (e.source, &ev);
   CORBA_exception_free (&ev);
 }
 
@@ -240,12 +241,16 @@ parse_event_type (EventTypeStruct *etype, const char *event_name)
   gchar *s;
 
   split_string = g_strsplit (event_name, ":", 4);
-  etype->event_name = g_strdup (event_name);
+  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;
@@ -330,6 +335,7 @@ get_listener_list (SpiRegistry      *registry,
       case ETYPE_WINDOW:
        ret = &registry->window_listeners;
        break;
+      case ETYPE_MOUSE:
       case ETYPE_TOOLKIT:
        ret = &registry->toolkit_listeners;
        break;
@@ -356,14 +362,14 @@ impl_accessibility_registry_register_global_event_listener (
   EventTypeStruct etype;
   GList          **list;
 
-#ifdef SPI_DEBUG
+#ifdef SPI_LISTENER_DEBUG
   fprintf (stderr, "registering");
   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_quark = etype.major;
+  ls->event_type_quark = etype.minor;
   ls->event_type_cat = etype.type_cat;
 
   list = get_listener_list (registry, etype.type_cat);
@@ -568,26 +574,31 @@ notify_listeners_cb (GList * const *list, gpointer user_data)
       CORBA_free (s);
 #endif
       
-      ctx->e_out.source = bonobo_object_dup_ref (ctx->source, ctx->ev);
+      ctx->e_out.source = CORBA_Object_duplicate (ctx->source, ctx->ev);
+
       if (BONOBO_EX (ctx->ev))
         {
-          return SPI_RE_ENTRANT_CONTINUE;;
+          return SPI_RE_ENTRANT_CONTINUE;
        }
-
+      
       if ((*list) && (*list)->data == ls)
         {
           Accessibility_EventListener_notifyEvent (
             (Accessibility_EventListener) ls->listener, &ctx->e_out, ctx->ev);
-        if (ctx->ev->_major != CORBA_NO_EXCEPTION)
-          {
-            g_warning ("Accessibility app error: exception during "
-                      "event notification: %s\n",
-                      CORBA_exception_id (ctx->ev));
-         }
+          if (ctx->ev->_major != CORBA_NO_EXCEPTION)
+            {
+              g_warning ("Accessibility app error: exception during "
+                       "event notification: %s\n",
+                       CORBA_exception_id (ctx->ev));
+             if (ctx->ev->_major == CORBA_SYSTEM_EXCEPTION)
+                     CORBA_exception_init (ctx->ev);
+             /* clear system exception on notify, it means listener is dead but
+              * that's no concern of the event source :-) */
+           }
        }
       else /* dup re-entered */
         {
-          bonobo_object_release_unref (ctx->e_out.source, ctx->ev);
+          CORBA_Object_release (ctx->e_out.source, ctx->ev);
        }
     }  
 
@@ -614,15 +625,10 @@ impl_registry_notify_event (PortableServer_Servant     servant,
       ctx.ev = ev;
       ctx.e_out = *e;
       ctx.source = e->source;
-      parse_event_type (&ctx.etype, e->type);
 
       spi_re_entrant_list_foreach (list, notify_listeners_cb, &ctx);
     }
 
-  if (e->source != CORBA_OBJECT_NIL)
-    {
-      Accessibility_Accessible_unref (e->source, ev);
-    }
 }
 
 
@@ -667,7 +673,7 @@ spi_registry_init (SpiRegistry *registry)
                    G_CALLBACK (desktop_remove_application),
                    registry);
 
-  registry->de_controller = NULL;
+  registry->de_controller = spi_device_event_controller_new (registry);
 }
 
 BONOBO_TYPE_FUNC_FULL (SpiRegistry,