Changes to introspection generation to remove DOCTYPE and XML
[platform/core/uifw/at-spi2-atk.git] / atk-bridge / bridge.c
index 4067baf..755310b 100644 (file)
@@ -22,7 +22,7 @@
  */
 
 #include "config.h"
-#include "dbus/dbus-glib.h"
+#include "dbus/dbus-glib-lowlevel.h"
 
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
@@ -48,7 +48,6 @@
 typedef struct _SpiAppData SpiAppData;
 struct _SpiAppData
 {
-  DBusConnection *bus;
   AtkObject *root;
   DRouteData droute;
 };
@@ -122,7 +121,7 @@ static gboolean spi_atk_bridge_signal_listener         (GSignalInvocationHint *s
 static gint     spi_atk_bridge_key_listener            (AtkKeyEventStruct     *event,
                                                        gpointer               data);
 static void     spi_atk_tidy_windows                   (void);
-static void     deregister_application                 ();
+static void     deregister_application                 (SpiAppData *app);
 static void reinit_register_vars (void);
 
 /* For automatic libgnome init */
@@ -167,7 +166,7 @@ spi_atk_bridge_init_event_type_consts ()
 }
 
 static gboolean
-post_init (void)
+post_init (gpointer data)
 {
   during_init_shutdown = FALSE;
   return FALSE;
@@ -188,23 +187,24 @@ spi_app_init (AtkObject *root)
   SpiAppData *ad = (SpiAppData *)calloc(sizeof(SpiAppData), 1);
   if (!ad) return NULL;
   ad->root = root;
-  ad->bus = dbus_bus_get(DBUS_BUS_SESSION, &error);
-  if (!ad->bus)
+  ad->droute.bus = dbus_bus_get(DBUS_BUS_SESSION, &error);
+  if (!ad->droute.bus)
   {
     g_warning("Couldn't connect to dbus: %s\n", error.message);
     free(ad);
     return NULL;
   }
-  //dbus_connection_set_exit_on_disconnect(ad->bus, FALSE);
-  //dbus_bus_register(ad->bus, &error);
+  //dbus_connection_set_exit_on_disconnect(ad->droute.bus, FALSE);
+  //dbus_bus_register(ad->droute.bus, &error);
   spi_dbus_initialize (&ad->droute);
   /* Below line for testing -- it should be removed once at-spi-registryd is working */
-  if (dbus_bus_request_name(ad->bus, "org.freedesktop.at-spi.test", 0, &error)) printf("Got test name.\n");
-  if (!dbus_connection_try_register_fallback (ad->bus, "/org/freedesktop/atspi", &droute_vtable, &ad->droute, &error))
+  if (dbus_bus_request_name(ad->droute.bus, "test.atspi.tree", 0, &error)) printf("Got test name.\n");
+  spi_register_tree_object(ad->droute.bus, "/org/freedesktop/atspi/tree");
+  if (!dbus_connection_try_register_fallback (ad->droute.bus, "/org/freedesktop/atspi/accessible/", &droute_vtable, &ad->droute, &error))
   {
-    printf("Couldn't register droute.\n");
+    g_warning("Couldn't register droute.\n");
   }
-  dbus_connection_setup_with_g_main(ad->bus, g_main_context_default());
+  dbus_connection_setup_with_g_main(ad->droute.bus, g_main_context_default());
   return ad;
 }
 
@@ -421,7 +421,7 @@ spi_atk_bridge_get_registry (void)
 }
 
 static const char *
-spi_atk_bridget_get_dec (void)
+spi_atk_bridge_get_dec (void)
 {
   return "/dec";
 }
@@ -637,6 +637,7 @@ static void emit(AtkObject *object, const char *name, int first_arg_type, ...)
   DBusMessage *sig;
   char *path = spi_dbus_get_path(object);
 
+  spi_dbus_update_cache(&this_app->droute);
   sig = dbus_message_new_signal(path, "org.freedesktop.atspi.Accessible", name);
   va_start(args, first_arg_type);
   if (first_arg_type != DBUS_TYPE_INVALID)
@@ -644,7 +645,7 @@ static void emit(AtkObject *object, const char *name, int first_arg_type, ...)
     dbus_message_append_args_valist(sig, first_arg_type, args);
   }
   va_end(args);
-  dbus_connection_send(this_app->bus, sig, NULL);
+  dbus_connection_send(this_app->droute.bus, sig, NULL);
   g_free(path);
   dbus_message_unref(sig);
 }
@@ -662,6 +663,7 @@ static void emit_property_change(AtkObject *object, const char *name, int type,
   DBusMessageIter iter, sub;
   const char *type_as_string = NULL;
 
+  spi_dbus_update_cache(&this_app->droute);
   if (type == DBUS_TYPE_OBJECT_PATH)
   {
     type_as_string = "o";
@@ -680,7 +682,7 @@ static void emit_property_change(AtkObject *object, const char *name, int type,
   dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, type_as_string, &sub);
   dbus_message_iter_append_basic(&sub, type, val);
   dbus_message_iter_close_container(&iter, &sub);
-  dbus_connection_send(this_app->bus, sig, NULL);
+  dbus_connection_send(this_app->droute.bus, sig, NULL);
   g_free(path);
   dbus_message_unref(sig);
 }
@@ -692,6 +694,7 @@ static void emit_rect(AtkObject *object, const char *name, AtkRectangle *rect)
   DBusMessageIter iter, sub;
   dbus_uint32_t x, y, width, height;
 
+  spi_dbus_update_cache(&this_app->droute);
   x = rect->x;
   y = rect->y;
   width = rect->width;
@@ -711,17 +714,12 @@ static void emit_rect(AtkObject *object, const char *name, AtkRectangle *rect)
       if (!dbus_message_iter_close_container (&iter, &sub))
        goto oom;
     }
-  dbus_connection_send(this_app->bus, sig, NULL);
+  dbus_connection_send(this_app->droute.bus, sig, NULL);
 oom:
   g_free(path);
   dbus_message_unref(sig);
 }
 
-static void cache_dirty(AtkObject *obj, gboolean include_children)
-{
-  // TODO: cache
-}
-
 static gboolean
 spi_atk_bridge_property_event_listener (GSignalInvocationHint *signal_hint,
                                        guint n_param_values,
@@ -760,15 +758,15 @@ spi_atk_bridge_property_event_listener (GSignalInvocationHint *signal_hint,
   prop_name = values->property_name;
   if (strcmp (prop_name, "accessible-name") == 0)
     {
-      cache_dirty(obj, FALSE);
+      spi_dbus_notify_change(obj, FALSE, &this_app->droute);
     }
   else if (strcmp (prop_name, "accessible-description") == 0)
     {
-      cache_dirty(obj, FALSE);
+      spi_dbus_notify_change(obj, FALSE, &this_app->droute);
     }
   else if (strcmp (prop_name, "accessible-parent") == 0)
     {
-      cache_dirty(obj, FALSE);
+      spi_dbus_notify_change(obj, FALSE, &this_app->droute);
     }
   else if (strcmp (prop_name, "accessible-table-summary") == 0)
     {
@@ -838,6 +836,15 @@ spi_atk_bridge_state_event_listener (GSignalInvocationHint *signal_hint,
 
   obj = ATK_OBJECT(g_value_get_object (param_values + 0));
   property_name = g_strdup (g_value_get_string (param_values + 1));
+  /* Ignore defunct for now; we'll send a tree update to remove it when
+     the object goes away */
+  /* Also ignore state changes for objects not yet broadcast */
+  if ((property_name && !strcmp(property_name, "defunct")) ||
+      !spi_dbus_object_is_known(obj))
+  {
+    g_free(property_name);
+    return TRUE;
+  }
   detail1 = (g_value_get_boolean (param_values + 2))
     ? 1 : 0;
   emit(obj, "StateChanged", DBUS_TYPE_STRING, &property_name, DBUS_TYPE_UINT32, &detail1, DBUS_TYPE_INVALID);
@@ -845,7 +852,6 @@ spi_atk_bridge_state_event_listener (GSignalInvocationHint *signal_hint,
   return TRUE;
 }
 
-#if 0
 static void
 spi_init_keystroke_from_atk_key_event (Accessibility_DeviceEvent  *keystroke,
                                       AtkKeyEventStruct          *event)
@@ -862,25 +868,25 @@ spi_init_keystroke_from_atk_key_event (Accessibility_DeviceEvent  *keystroke,
       g_print (_("WARNING: NULL key event reported."));
     }
   
-  keystroke->id        = (CORBA_long) event->keyval;
-  keystroke->hw_code   = (CORBA_short) event->keycode;
-  keystroke->timestamp = (CORBA_unsigned_long) event->timestamp;
-  keystroke->modifiers = (CORBA_unsigned_short) (event->state & 0xFFFF);
+  keystroke->id        = (dbus_int32_t) event->keyval;
+  keystroke->hw_code   = (dbus_int16_t) event->keycode;
+  keystroke->timestamp = (dbus_uint32_t) event->timestamp;
+  keystroke->modifiers = (dbus_uint16_t) (event->state & 0xFFFF);
   if (event->string)
     {
       gunichar c;
 
-      keystroke->event_string = CORBA_string_dup (event->string);
+      keystroke->event_string = g_strdup (event->string);
       c = g_utf8_get_char_validated (event->string, -1);
       if (c > 0 && g_unichar_isprint (c))
-        keystroke->is_text = CORBA_TRUE;
+        keystroke->is_text = TRUE;
       else
-        keystroke->is_text = CORBA_FALSE;
+        keystroke->is_text = FALSE;
     }
   else
     {
-      keystroke->event_string = CORBA_string_dup ("");
-      keystroke->is_text = CORBA_FALSE;
+      keystroke->event_string = g_strdup ("");
+      keystroke->is_text = FALSE;
     }
   switch (event->type)
     {
@@ -901,33 +907,43 @@ spi_init_keystroke_from_atk_key_event (Accessibility_DeviceEvent  *keystroke,
           keystroke->event_string, (int) keystroke->is_text, (unsigned long) keystroke->timestamp);
 #endif
 }
-#endif
+
+static gboolean Accessibility_DeviceEventController_notifyListenersSync(const Accessibility_DeviceEvent *key_event)
+{
+  DBusMessage *message = dbus_message_new_method_call(SPI_DBUS_NAME_REGISTRY, SPI_DBUS_PATH_REGISTRY, "org.freedesktop.atspi.DeviceEventController", "notifyListenersSync");
+  DBusError error;
+  dbus_bool_t consumed = FALSE;
+
+  dbus_error_init(&error);
+  if (spi_dbus_marshall_deviceEvent(message, key_event))
+  {
+    DBusMessage *reply = dbus_connection_send_with_reply_and_block(this_app->droute.bus, message, 1000, &error);
+    if (reply)
+    {
+      DBusError error;
+      dbus_error_init(&error);
+      dbus_message_get_args(reply, &error, DBUS_TYPE_BOOLEAN, &consumed, DBUS_TYPE_INVALID);
+      dbus_message_unref(reply);
+    }
+  }
+  dbus_message_unref(message);
+  return consumed;
+}
 
 static gint
 spi_atk_bridge_key_listener (AtkKeyEventStruct *event, gpointer data)
 {
   gboolean             result;
-#if 0
   Accessibility_DeviceEvent key_event;
 
-  CORBA_exception_init (&ev);
-
   spi_init_keystroke_from_atk_key_event (&key_event, event);
 
   bridge_threads_leave ();
-  result = Accessibility_DeviceEventController_notifyListenersSync (
-         spi_atk_bridget_get_dec (), &key_event, &ev);
+  result = Accessibility_DeviceEventController_notifyListenersSync (&key_event);
   bridge_threads_enter ();
 
-  if (key_event.event_string) CORBA_free (key_event.event_string);
+  if (key_event.event_string) g_free (key_event.event_string);
 
-  if (BONOBO_EX(&ev))
-    {
-      result = FALSE;
-      CORBA_exception_free (&ev);
-    }
-
-#endif
   return result;
 }
 
@@ -946,6 +962,7 @@ spi_atk_bridge_signal_listener (GSignalInvocationHint *signal_hint,
   gint detail1 = 0, detail2 = 0;
   char *s_ao = NULL;
   gchar *sig_name;
+  char *p;
 #ifdef SPI_BRIDGE_DEBUG
   const gchar *s, *s2;
 #endif 
@@ -963,6 +980,7 @@ spi_atk_bridge_signal_listener (GSignalInvocationHint *signal_hint,
     detail = NULL;
     sig_name = g_strdup_printf("object_%s", name);
   }
+  while ((p = strchr(sig_name, '-')) != NULL) *p = '_';
 
 #ifdef SPI_BRIDGE_DEBUG
   s2 = g_type_name (G_OBJECT_TYPE (g_value_get_object (param_values + 0)));
@@ -1003,7 +1021,7 @@ spi_atk_bridge_signal_listener (GSignalInvocationHint *signal_hint,
     }
   else if ((signal_query.signal_id == atk_signal_children_changed) && obj)
     {
-      cache_dirty(obj, TRUE);
+      spi_dbus_notify_change(obj, FALSE, &this_app->droute);
     }
   else
     {
@@ -1023,7 +1041,7 @@ spi_atk_bridge_signal_listener (GSignalInvocationHint *signal_hint,
           sp = atk_text_get_text (ATK_TEXT (obj),
                                  detail1,
                                  detail1+detail2);
-          emit(obj, sig_name, DBUS_TYPE_UINT32, detail1, DBUS_TYPE_UINT32, detail2, DBUS_TYPE_STRING, &sp, DBUS_TYPE_INVALID);
+          emit(obj, sig_name, DBUS_TYPE_UINT32, &detail1, DBUS_TYPE_UINT32, &detail2, DBUS_TYPE_STRING, &sp, DBUS_TYPE_INVALID);
         }
       else if (signal_query.signal_id == atk_signal_text_selection_changed)
         {