2009-03-10 Mark Doffman <mark.doffman@codethink.co.uk>
[platform/core/uifw/at-spi2-atk.git] / cspi / spi-main.c
index 4b0dd93..aeda398 100644 (file)
@@ -93,6 +93,7 @@ static const char *interfaces[] =
   SPI_DBUS_INTERFACE_ACCESSIBLE,
   SPI_DBUS_INTERFACE_ACTION,
   SPI_DBUS_INTERFACE_APPLICATION,
+  SPI_DBUS_INTERFACE_COLLECTION,
   SPI_DBUS_INTERFACE_COMPONENT,
   SPI_DBUS_INTERFACE_DOCUMENT,
   SPI_DBUS_INTERFACE_EDITABLE_TEXT,
@@ -218,6 +219,10 @@ cspi_object_unref_internal (Accessible *accessible, gboolean defunct)
     {
       g_free (accessible->v.path);
     }
+    if (accessible->states)
+      spi_state_set_cache_unref (accessible->states);
+    g_free (accessible->description);
+    g_free (accessible->name);
     g_free(accessible);
   }
 }
@@ -319,6 +324,7 @@ typedef struct
   char *name;
   dbus_uint32_t role;
   char *description;
+  GArray *state_bitflags;
 } CACHE_ADDITION;
 
 /* Update the cache with added/modified objects and free the array */
@@ -370,8 +376,10 @@ handle_additions (CSpiApplication*app, GArray *additions)
     a->role = ca->role;
     if (a->description) g_free (a->description);
     a->description = ca->description;
+    a->states = spi_state_set_cache_new (ca->state_bitflags);
     g_array_free (ca->interfaces, TRUE);
     g_array_free (ca->children, TRUE);
+    /* spi_state_set_cache_new frees state_bitflags */
     /* This is a bit of a hack since ref_accessible sets ref_count to 2
      * for a new object, one of the refs being for the cache */
     cspi_object_unref (a);
@@ -407,7 +415,7 @@ add_app_to_desktop (Accessible *a, const char *bus_name)
   char *root_path;
 
   dbus_error_init (&error);
-  if (dbind_connection_method_call (bus, bus_name, "/org/freedesktop/atspi/tree", spi_interface_tree, "getRoot", &error, "=>o", &root_path))
+  if (dbind_method_call_reentrant (bus, bus_name, "/org/freedesktop/atspi/tree", spi_interface_tree, "getRoot", &error, "=>o", &root_path))
   {
     Accessible *obj = cspi_ref_accessible (bus_name, root_path);
     if (obj)
@@ -499,7 +507,7 @@ ref_accessible_desktop (CSpiApplication *app)
   desktop->ref_count = 2;      /* one for the caller, one for the hash */
   desktop->name = g_strdup ("");
   dbus_error_init (&error);
-  if (!dbind_connection_method_call (bus, spi_bus_registry, spi_path_registry, spi_interface_registry, "getApplications", &error, "=>as", &apps))
+  if (!dbind_method_call_reentrant (bus, spi_bus_registry, spi_path_registry, spi_interface_registry, "getApplications", &error, "=>as", &apps))
   {
     g_error ("Couldn't get application list: %s", error.message);
   }
@@ -514,7 +522,7 @@ ref_accessible_desktop (CSpiApplication *app)
     CSpiApplication *app = cspi_get_application (app_name);
     additions = NULL;
     dbus_error_init (&error);
-    dbind_connection_method_call (bus, app_name, "/org/freedesktop/atspi/tree", spi_interface_tree, "getTree", &error, "=>a(ooaoassus)", &additions);
+    dbind_method_call_reentrant (bus, app_name, "/org/freedesktop/atspi/tree", spi_interface_tree, "getTree", &error, "=>a(ooaoassusau)", &additions);
     if (error.message)
     {
       g_warning ("getTree (%s): %s", app_name, error.message);
@@ -550,7 +558,7 @@ typedef struct
   GArray *removals;
 } CacheSignalData;
 
-static const char *cacheSignalType = "a(ooaoassus)ao";
+static const char *cacheSignalType = "a(ooaoassusau)ao";
 
 static DBusHandlerResult
 cspi_dbus_handle_update_tree (DBusConnection *bus, DBusMessage *message, void *user_data)
@@ -625,7 +633,7 @@ cspi_dbus_filter (DBusConnection *bus, DBusMessage *message, void *data)
   char *bus_name;
 
   if (type == DBUS_MESSAGE_TYPE_SIGNAL &&
-      !strcmp (interface, SPI_DBUS_INTERFACE_ACCESSIBLE))
+      !strncmp (interface, "org.freedesktop.atspi.Event.", 28))
   {
     return cspi_dbus_handle_event (bus, message, data);
   }
@@ -637,17 +645,28 @@ cspi_dbus_filter (DBusConnection *bus, DBusMessage *message, void *data)
   {
     return cspi_dbus_handle_update_tree (bus, message, data);
   }
-  if (dbus_message_is_signal (message, spi_interface_tree, "registerApplication"))
+  if (dbus_message_is_method_call (message, spi_interface_registry, "registerApplication"))
   {
     return cspi_dbus_handle_register_application (bus, message, data);
   }
-  if (dbus_message_is_signal (message, spi_interface_registry, "deregisterApplication"))
+  if (dbus_message_is_method_call (message, spi_interface_registry, "deregisterApplication"))
   {
     return cspi_dbus_handle_deregister_application (bus, message, data);
   }
   return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
 
+static const char *signal_interfaces[] =
+{
+  "org.freedesktop.atspi.Event.Object",
+  "org.freedesktop.atspi.Event.Window",
+  "org.freedesktop.atspi.Event.Mouse",
+  "org.freedesktop.atspi.Event.Terminal",
+  "org.freedesktop.atspi.Event.Document",
+  "org.freedesktop.atspi.Event.Focus",
+  NULL
+};
+
 /**
  * SPI_init:
  *
@@ -660,6 +679,7 @@ SPI_init (void)
 {
   DBusError error;
   char *match;
+  int i;
 
   if (SPI_inited)
     {
@@ -687,9 +707,15 @@ SPI_init (void)
   dbus_error_init (&error);
   dbus_bus_add_match (bus, match, &error);
   g_free (match);
-  match = g_strdup_printf ("type='signal',interface='%s'", spi_interface_tree);
+  match = g_strdup_printf ("type='method_call',interface='%s'", spi_interface_registry);
   dbus_bus_add_match (bus, match, &error);
   g_free (match);
+  for (i = 0; signal_interfaces[i]; i++)
+  {
+    match = g_strdup_printf ("type='signal',interface='%s'", signal_interfaces[i]);
+    dbus_bus_add_match (bus, match, &error);
+    g_free (match);
+  }
   return 0;
 }
 
@@ -1013,7 +1039,7 @@ cspi_dbus_call (Accessible *obj, const char *interface, const char *method, DBus
   if (!error) error = &err;
   dbus_error_init (error);
   va_start (args, type);
-  retval = dbind_connection_method_call_va (SPI_bus(), obj->app->bus_name, path, interface, method, error, type, args);
+  retval = dbind_method_call_reentrant_va (SPI_bus(), obj->app->bus_name, path, interface, method, error, type, args);
   va_end (args);
   g_free (path);
   if (dbus_error_is_set (error))