Move adaptor_*() functions into their own header
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / event.c
index 6add6e7..22f817d 100644 (file)
@@ -53,8 +53,10 @@ static gint atk_bridge_focus_tracker_id;
 
 typedef struct _SpiReentrantCallClosure 
 {
+  DBusConnection *bus;
   GMainLoop   *loop;
   DBusMessage *reply;
+  guint timeout;
 } SpiReentrantCallClosure;
 
 static void
@@ -81,25 +83,45 @@ set_reply (DBusPendingCall * pending, void *user_data)
   g_main_loop_quit (closure->loop);
 }
 
+static gboolean
+timeout_reply (void *data)
+{
+  SpiReentrantCallClosure *closure = data;
+
+  if (!dbus_connection_get_is_connected (closure->bus))
+    g_main_loop_quit (closure->loop);
+  closure->timeout = -1;
+  return FALSE;
+}
+
 static DBusMessage *
 send_and_allow_reentry (DBusConnection * bus, DBusMessage * message)
 {
   DBusPendingCall *pending;
   SpiReentrantCallClosure closure;
   GMainContext *main_context;
+  GSource *source;
 
   main_context = (g_getenv ("AT_SPI_CLIENT") ? NULL :
                   spi_global_app_data->main_context);
+  closure.bus = bus;
   closure.loop = g_main_loop_new (main_context, FALSE);
+  closure.reply = NULL;
   switch_main_context (main_context);
 
-  if (!dbus_connection_send_with_reply (bus, message, &pending, -1) || !pending)
+  if (!dbus_connection_send_with_reply (bus, message, &pending, 9000) || !pending)
     {
       switch_main_context (NULL);
       return NULL;
     }
   dbus_pending_call_set_notify (pending, set_reply, (void *) &closure, NULL);
+  source = g_timeout_source_new (500);
+  g_source_set_callback (source, timeout_reply, &closure, NULL);
+  closure.timeout = g_source_attach (source, main_context);
+  g_source_unref (source);
   g_main_loop_run  (closure.loop);
+  if (closure.timeout != -1)
+    g_source_destroy (source);
   
   g_main_loop_unref (closure.loop);
   return closure.reply;
@@ -399,6 +421,18 @@ signal_is_needed (const gchar *klass, const gchar *major, const gchar *minor)
   return ret;
 }
 
+/* Convert a : to a / so that listeners can use arg0path to match only
+ *  * the prefix */
+static char *
+adapt_minor_for_dbus (const char *source)
+{
+  gchar *ret = g_strdup (source);
+  int i = strcspn (ret, ":");
+  if (ret[i] == ':')
+    ret[i] = '/';
+  return ret;
+}
+
 /*
  * Emits an AT-SPI event.
  * AT-SPI events names are split into three parts:
@@ -422,6 +456,7 @@ emit_event (AtkObject  *obj,
 {
   DBusConnection *bus = spi_global_app_data->bus;
   const char *path;
+  char *minor_dbus;
 
   gchar *cname, *t;
   DBusMessage *sig;
@@ -436,6 +471,7 @@ emit_event (AtkObject  *obj,
     return;
 
   path =  spi_register_object_to_path (spi_global_register, G_OBJECT (obj));
+  g_return_if_fail (path != NULL);
 
   /*
    * This is very annoying, but as '-' isn't a legal signal
@@ -447,7 +483,9 @@ emit_event (AtkObject  *obj,
 
   dbus_message_iter_init_append(sig, &iter);
 
-  dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &minor);
+  minor_dbus = adapt_minor_for_dbus (minor);
+  dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &minor_dbus);
+  g_free (minor_dbus);
   dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &detail1);
   dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &detail2);
   append_variant (&iter, type, val);
@@ -613,7 +651,7 @@ state_event_listener (GSignalInvocationHint * signal_hint,
   emit_event (accessible, ITF_EVENT_OBJECT, STATE_CHANGED, pname, detail1, 0,
               DBUS_TYPE_INT32_AS_STRING, 0, append_basic);
 
-  if (!g_strcmp0 (pname, "defunct"))
+  if (!g_strcmp0 (pname, "defunct") && detail1)
     spi_register_deregister_object (spi_global_register, G_OBJECT (accessible),
                                     TRUE);
   return TRUE;