Changes to enable new introspection format.
authorMark Doffman <mdoff@silver-wind.(none)>
Tue, 13 May 2008 14:42:25 +0000 (15:42 +0100)
committerMark Doffman <mdoff@silver-wind.(none)>
Fri, 16 May 2008 15:09:27 +0000 (16:09 +0100)
Add one introspection XML file, and update bridge
to register modified tree object that uses the introspection.

atk-bridge/bridge.c
libspi/Makefile.am
libspi/accessible.h
libspi/dbus.c
libspi/introspectable.c
libspi/tree.c
xml/Accessibility_Tree.xml
xml/introspection/org.freedesktop.atspi.Tree [new file with mode: 0644]

index 3ccfc9e..ec6ddd0 100644 (file)
@@ -199,7 +199,8 @@ spi_app_init (AtkObject *root)
   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->droute.bus, "test.atspi.tree", 0, &error)) printf("Got test name.\n");
-  if (!dbus_connection_try_register_fallback (ad->droute.bus, "/org/freedesktop/atspi", &droute_vtable, &ad->droute, &error))
+  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))
   {
     g_warning("Couldn't register droute.\n");
   }
index 5154baa..b0a8045 100644 (file)
@@ -10,6 +10,7 @@ INCLUDES = -I$(top_srcdir)    \
            $(X_CFLAGS)
 
 libspi_la_LDFLAGS = @LT_VERSION_INFO@ -no-undefined
+libspi_la_CFLAGS = -DATSPI_DBUS_INTROSPECTION_DIRECTORY="\"$(datadir)/at-spi/dbus\""
 libspi_la_LIBADD = $(LIBSPI_LIBS) $(XTST_LIBS)
 
 libspiincludedir = $(includedir)/at-spi-1.0/libspi
@@ -19,20 +20,21 @@ libspiinclude_HEADERS =             \
        accessible.h \
        bitarray.h \
        dbus.h \
-       droute.h
+       droute.h \
+       introspect-loader.h
 
 BUILT_SOURCES = Accessibility.h
 CLEANFILES = Accessibility.h
 
 libspi_la_SOURCES =            \
-       Accessibility.h \
+       Accessibility.h         \
        accessible.c            \
-       action.c \
+       action.c                \
        application.c           \
        component.c             \
-       dbus.c \
+       dbus.c                  \
        document.c              \
-       droute.c \
+       droute.c                \
        editabletext.c          \
        hyperlink.c             \
        hypertext.c             \
@@ -40,8 +42,10 @@ libspi_la_SOURCES =          \
        selection.c             \
        table.c                 \
        text.c                  \
-       tree.c \
-       value.c
+       tree.c                  \
+       value.c                 \
+       introspect-loader.c     \
+       introspectable.c 
 
 Accessibility.h: ../xml/spec.xml ../tools/c-constants-generator.xsl
        xsltproc --stringparam mixed-case-prefix Accessibility_ ../tools/c-constants-generator.xsl $< >$@
index 55df3b3..fbaf9e4 100644 (file)
@@ -43,9 +43,11 @@ void spi_initialize_hypertext(DRouteData *data);
 void spi_initialize_image(DRouteData *data);
 void spi_initialize_selection(DRouteData *data);
 void spi_initialize_table(DRouteData *data);
-void spi_initialize_tree(DRouteData *data);
 void spi_initialize_text(DRouteData *data);
 void spi_initialize_value(DRouteData *data);
+void spi_initialize_introspectable(DRouteData *data);
+
+void spi_register_tree_object(DBusConnection *bus, const char *path);
 
 dbus_bool_t spi_dbus_append_tree (DBusMessage * message, AtkObject * obj, DRouteData * data);
 
index a8e12d1..5690eee 100644 (file)
@@ -182,9 +182,9 @@ spi_dbus_initialize (DRouteData * data)
   spi_initialize_image (data);
   spi_initialize_selection (data);
   spi_initialize_table (data);
-  spi_initialize_tree (data);
   spi_initialize_text (data);
   spi_initialize_value (data);
+  spi_initialize_introspectable(data);
 }
 
 static GString *
index eb6d7d9..fdd8ae1 100644 (file)
@@ -24,6 +24,7 @@
 #include <dbus.h>
 
 #include "droute.h"
+#include "introspect-loader.h"
 
 /*
  * This file contains an implementation of the D-Bus introspectable interface.
  */
 
 /*
- * Provides the dist install path for the introspection directory.
- */
-#if !defined ATSPI_DBUS_INTROSPECTION_DIRECTORY
-    #error "No introspection XML directory defined"
-#endif
-
-char *spi_introspection_directory = ATSPI_DBUS_INTROSPECTION_DIRECTORY;
-
-static const char *introspection_header =
-"<?xml version=\"1.0\"?>\n";
-
-static const char *introspection_node_element =
-"<node name=\"%s\">\n";
-
-static const char *introspection_footer =
-"</node>";
-
-void
-spi_initialize_introspectable (DRouteData *data);
-
-static void
-append_interface (GString *str, const char *interface)
-{
-  char *filename;
-  char *contents;
-  gsize len;
-
-  GError *err = NULL;
-
-  filename = g_build_filename(spi_introspection_directory, interface, NULL);
-
-  if (g_file_get_contents(filename, &contents, &len, &err))
-    {
-      g_string_append_len(str, contents, len);
-    }
-  else
-    {
-      g_warning("AT-SPI: Cannot find introspection XML file %s - %s",
-               filename, err->message);
-      g_error_free(err);
-    }
-
-  g_string_append(str, "\n");
-  g_free(filename);
-  g_free(contents);
-}
-
-/*
- * There is an installation directory with files containing introspection xml.
- * Each file is named after the interface it describes.
- *
  * This function finds the names of each interface that the ATK object supports
- * and mem copies the introspection data from the file into the message.
- *
- * TODO - There could be some wicked caching here, but probably not neccessary.
+ * and appends the introspection XML for each interface.
  */
 static DBusMessage *
 impl_introspect (DBusConnection *bus, DBusMessage *message,
@@ -101,49 +49,49 @@ impl_introspect (DBusConnection *bus, DBusMessage *message,
   path = dbus_message_get_path(message);
   object = spi_dbus_get_object(path);
 
-  output = g_string_new(introspection_header);
+  output = g_string_new(spi_introspection_header);
   
-  g_string_append_printf(output, introspection_node_element, path);
+  g_string_append_printf(output, spi_introspection_node_element, path);
 
   if (ATK_IS_ACTION (object))
-      append_interface(output, "org.freedesktop.atspi.Action");
+      spi_append_interface(output, "org.freedesktop.atspi.Action");
 
   if (ATK_IS_COMPONENT (object))
-      append_interface(output, "org.freedesktop.atspi.Component");
+      spi_append_interface(output, "org.freedesktop.atspi.Component");
 
   if (ATK_IS_EDITABLE_TEXT (object))
-      append_interface(output, "org.freedesktop.atspi.EditableText");
+      spi_append_interface(output, "org.freedesktop.atspi.EditableText");
   else if (ATK_IS_TEXT (object))
-      append_interface(output, "org.freedesktop.atspi.Text");
+      spi_append_interface(output, "org.freedesktop.atspi.Text");
 
   if (ATK_IS_HYPERTEXT (object))
-      append_interface(output, "org.freedesktop.atspi.Hypertext");
+      spi_append_interface(output, "org.freedesktop.atspi.Hypertext");
 
   if (ATK_IS_IMAGE (object))
-      append_interface(output, "org.freedesktop.atspi.Image");
+      spi_append_interface(output, "org.freedesktop.atspi.Image");
 
   if (ATK_IS_SELECTION (object))
-      append_interface(output, "org.freedesktop.atspi.Selection");
+      spi_append_interface(output, "org.freedesktop.atspi.Selection");
 
   if (ATK_IS_TABLE (object))
-      append_interface(output, "org.freedesktop.atspi.Table");
+      spi_append_interface(output, "org.freedesktop.atspi.Table");
 
   if (ATK_IS_VALUE (object))
-      append_interface(output, "org.freedesktop.atspi.Value");
+      spi_append_interface(output, "org.freedesktop.atspi.Value");
 
   if (ATK_IS_STREAMABLE_CONTENT (object))
-      append_interface(output, "org.freedesktop.atspi.StreamableContent");
+      spi_append_interface(output, "org.freedesktop.atspi.StreamableContent");
 
   if (ATK_IS_DOCUMENT (object))
     {
-      append_interface(output, "org.freedesktop.atspi.Collection");
-      append_interface(output, "org.freedesktop.atspi.Document");
+      spi_append_interface(output, "org.freedesktop.atspi.Collection");
+      spi_append_interface(output, "org.freedesktop.atspi.Document");
     }
 
   if (ATK_IS_HYPERLINK_IMPL (object))
-      append_interface(output, "org.freedesktop.atspi.Hyperlink");
+      spi_append_interface(output, "org.freedesktop.atspi.Hyperlink");
 
-  g_string_append(output, introspection_footer);
+  g_string_append(output, spi_introspection_footer);
   final = g_string_free(output, FALSE);
 
   reply = dbus_message_new_method_return (message);
@@ -166,7 +114,7 @@ static DRouteMethod methods[] = {
 void
 spi_initialize_introspectable (DRouteData *data)
 {
-  droute_add_interface (data, "org.freedesktop.atspi.Accessible",
+  droute_add_interface (data, "org.freedesktop.atspi.Introspectable",
                        methods, NULL,
                        (DRouteGetDatumFunction) spi_dbus_get_path, NULL);
 };
index 92f7f89..fe26fbe 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
+#include <string.h>
+
 #include "accessible.h"
+#include "introspect-loader.h"
 
 #define get_object(message) spi_dbus_get_object(dbus_message_get_path(message))
 
@@ -161,18 +164,88 @@ impl_getTree (DBusConnection * bus, DBusMessage * message, void *user_data)
   return reply;
 }
 
-static DRouteMethod methods[] = {
-  {impl_getRoot, "getRoot"},
-  {impl_getTree, "getTree", TRUE},
-  {NULL, NULL}
+static DBusMessage *
+impl_introspect (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+  const char *path;
+  GString *output;
+  char *final;
+
+  DBusMessage *reply;
+
+  path = dbus_message_get_path(message);
+
+  output = g_string_new(spi_introspection_header);
+  
+  g_string_append_printf(output, spi_introspection_node_element, path);
+
+  spi_append_interface(output, "org.freedesktop.atspi.Tree");
+
+  g_string_append(output, spi_introspection_footer);
+  final = g_string_free(output, FALSE);
+
+  reply = dbus_message_new_method_return (message);
+  g_assert(reply != NULL);
+  dbus_message_append_args(reply, DBUS_TYPE_STRING, &final,
+                          DBUS_TYPE_INVALID);
+
+  g_free(final);
+  return reply;
+}
+
+static DBusHandlerResult
+message_handler (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+  const char *iface = dbus_message_get_interface (message);
+  const char *member = dbus_message_get_member (message);
+
+  DBusMessage *reply = NULL;
+  
+  if (!strcmp(iface, "org.freedesktop.atspi.Tree"))
+    {
+      if (!strcmp(member, "getRoot"))
+       {
+         reply = impl_getRoot(bus, message, user_data);
+       }
+
+      if (!strcmp(member, "getTree"))
+       {
+         reply = impl_getTree(bus, message, user_data);
+       }
+    }
+
+  if (!strcmp(iface, "org.freedesktop.DBus.Introspectable"))
+    {
+      if (!strcmp(member, "Introspect"))
+       {
+         reply = impl_introspect(bus, message, user_data);
+       }
+    }
+
+  if (reply)
+    {
+      dbus_connection_send (bus, reply, NULL);
+      dbus_message_unref (reply);
+    }
+
+  return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static DBusObjectPathVTable tree_vtable =
+{
+  NULL,
+  &message_handler,
+  NULL, NULL, NULL, NULL
 };
 
 void
-spi_initialize_tree (DRouteData * data)
+spi_register_tree_object(DBusConnection *bus,
+                        const char *path)
 {
-  droute_add_interface (data, "org.freedesktop.atspi.Tree",
-                       methods, NULL, NULL, NULL);
-};
+  dbus_bool_t mem = FALSE;
+  mem = dbus_connection_register_object_path(bus, path, &tree_vtable, NULL);
+  g_assert(mem == TRUE);
+}
 
 static GHashTable *cache_list;
 
index 2a10fb5..f0164a9 100644 (file)
                                <tp:docstring xmlns="http://www.w3.org/1999/xhtml">
                                        <p>Array of Accessible Object proxy structures to be added.</p>
                                </tp:docstring>
+                       </arg>
                        <arg name="nodesRemoved" type="ao">
                                <tp:docstring xmlns="http://www.w3.org/1999/xhtml">
                                        <p>Array of Accessible Object proxy structures to be removed.</p>
diff --git a/xml/introspection/org.freedesktop.atspi.Tree b/xml/introspection/org.freedesktop.atspi.Tree
new file mode 100644 (file)
index 0000000..7171efb
--- /dev/null
@@ -0,0 +1,12 @@
+  <interface name="org.freedesktop.atspi.Tree">
+    <method name="getRoot">
+      <arg name="root" type="o" direction="out"/>
+    </method>
+    <method name="getTree">
+      <arg name="nodes" type="a(ooaoassus)" direction="out"/>
+    </method>
+    <signal name="updateTree">
+      <arg name="nodesAdded" type="a(ooaoassus)"/>
+      <arg name="nodesRemoved" type="ao"/>
+    </signal>
+  </interface>