2008-08-18 Mark Doffman <mark.doffman@codethink.co.uk>
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / tree.c
index 5c12747..64258ba 100644 (file)
@@ -39,18 +39,27 @@ append_update (DBusMessageIter * iter_array, AtkObject * obj,
   const char *name, *desc;
   int i;
   dbus_uint32_t role;
+  AtkObject *parent = NULL;
 
   gint childcount;
   GSList *l;
 
   g_assert(data != NULL);
 
+  parent = atk_object_get_parent(obj);
+  if (parent == NULL)
+    {
+      path_parent = g_strdup("/");
+    }
+  else
+    {
+      path_parent = spi_dbus_get_path (parent);
+    }
+
   dbus_message_iter_open_container (iter_array, DBUS_TYPE_STRUCT, NULL,
                                    &iter_struct);
   path = spi_dbus_get_path (obj);
   dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH, &path);
-  path_parent = spi_dbus_get_path (atk_object_get_parent(obj));
-  if (!path_parent) path_parent = g_strdup("/");
   dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH, &path_parent);
   g_free(path_parent);
   dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "o",
@@ -183,7 +192,7 @@ impl_introspect (DBusConnection *bus, DBusMessage *message, void *user_data)
   
   g_string_append_printf(output, spi_introspection_node_element, path);
 
-  spi_append_interface(output, "org.freedesktop.atspi.Tree");
+  spi_append_interface(output, SPI_DBUS_INTERFACE_TREE);
 
   g_string_append(output, spi_introspection_footer);
   final = g_string_free(output, FALSE);
@@ -207,7 +216,7 @@ message_handler (DBusConnection *bus, DBusMessage *message, void *user_data)
 
   g_return_val_if_fail(iface != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
   
-  if (!strcmp(iface, "org.freedesktop.atspi.Tree"))
+  if (!strcmp(iface, SPI_DBUS_INTERFACE_TREE))
     {
       if (!strcmp(member, "getRoot"))
        {
@@ -293,23 +302,27 @@ static void handle_cache_item(char *path, guint action, CacheIterData *d)
   g_hash_table_remove(cache_list, path);
 }
 
-gboolean spi_dbus_update_cache(DRouteData *data)
+gboolean
+spi_dbus_update_cache(DRouteData *data)
 {
   DBusMessage *message;
   DBusMessageIter iter;
   CacheIterData d;
+  static gboolean in_update_cache = FALSE;
 
+  if (in_update_cache) return TRUE;
   g_assert(data != NULL);
 
   if (update_pending == 0) return FALSE;
 //printf("Sending cache\n");
-  message = dbus_message_new_signal("/org/freedesktop/atspi/tree", "org.freedesktop.atspi.Tree", "UpdateTree");
+  message = dbus_message_new_signal ("/org/freedesktop/atspi/tree", SPI_DBUS_INTERFACE_TREE, "updateTree");
   if (!message) goto done;
   dbus_message_iter_init_append (message, &iter);
   dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "(ooaoassus)",
                                    &d.iter);
   d.droute = data;
   d.removing = FALSE;
+  in_update_cache = TRUE;
   do
   {
     /* This loop is needed because appending an item may cause new children
@@ -322,6 +335,7 @@ gboolean spi_dbus_update_cache(DRouteData *data)
   dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "o", &d.iter);
   d.removing = TRUE;
   g_hash_table_foreach(cache_list, (GHFunc)handle_cache_item, &d);
+  in_update_cache = FALSE;
   dbus_message_iter_close_container(&iter, &d.iter);
   dbus_connection_send(data->bus, message, NULL);
 done: