Improve introspection
authorMike Gorse <mgorse@novell.com>
Tue, 20 Jul 2010 13:10:36 +0000 (09:10 -0400)
committerMike Gorse <mgorse@novell.com>
Tue, 20 Jul 2010 13:10:36 +0000 (09:10 -0400)
atk-adaptor/bridge.c
droute/droute.c
droute/droute.h

index a33a509..9183a8e 100644 (file)
@@ -417,6 +417,17 @@ static GOptionEntry atspi_option_entries[] = {
   {NULL}
 };
 
+static gchar *
+introspect_children_cb (char *path, void *data)
+{
+  if (!strcmp (path, "/org/a11y/atspi/accessible"))
+    {
+      return g_strdup ("<node name=\"root\"/>\n");
+      /* TODO: Should we place the whole hierarchy here? */
+    }
+  return NULL;
+}
+
 /*
  * spi_app_init
  *
@@ -516,6 +527,8 @@ adaptor_init (gint * argc, gchar ** argv[])
   accpath = droute_add_many (spi_global_app_data->droute,
                              "/org/a11y/atspi/accessible",
                              NULL,
+                             introspect_children_cb,
+                             NULL,
                              (DRouteGetDatumFunction)
                              spi_global_register_path_to_object);
 
index 24ccea4..643ab11 100644 (file)
@@ -54,6 +54,8 @@ struct _DRoutePath
     GHashTable           *methods;
     GHashTable           *properties;
 
+    DRouteIntrospectChildrenFunction introspect_children_cb;
+    void *introspect_children_data;
     void                   *user_data;
     DRouteGetDatumFunction  get_datum;
 };
@@ -79,6 +81,8 @@ droute_object_does_not_exist_error (DBusMessage *message);
 static DRoutePath *
 path_new (DRouteContext *cnx,
           void    *user_data,
+          DRouteIntrospectChildrenFunction introspect_children_cb,
+          void *introspect_children_data,
           DRouteGetDatumFunction get_datum)
 {
     DRoutePath *new_path;
@@ -99,6 +103,8 @@ path_new (DRouteContext *cnx,
                                                   g_free,
                                                   NULL);
 
+    new_path->introspect_children_cb = introspect_children_cb;
+    new_path->introspect_children_data = introspect_children_data;
     new_path->user_data = user_data;
     new_path->get_datum = get_datum;
 
@@ -170,7 +176,7 @@ droute_add_one (DRouteContext *cnx,
     DRoutePath *new_path;
     gboolean registered;
 
-    new_path = path_new (cnx, (void *) data, NULL);
+    new_path = path_new (cnx, NULL, NULL, (void *) data, NULL);
 
     registered = dbus_connection_register_object_path (cnx->bus, path, &droute_vtable, new_path);
     if (!registered)
@@ -187,11 +193,13 @@ DRoutePath *
 droute_add_many (DRouteContext *cnx,
                  const char    *path,
                  const void    *data,
+                 DRouteIntrospectChildrenFunction introspect_children_cb,
+                 void *introspect_children_data,
                  const DRouteGetDatumFunction get_datum)
 {
     DRoutePath *new_path;
 
-    new_path = path_new (cnx, (void *) data, get_datum);
+    new_path = path_new (cnx, (void *) data, introspect_children_cb, introspect_children_data, get_datum);
 
     if (!dbus_connection_register_fallback (cnx->bus, path, &droute_vtable, new_path))
         oom();
@@ -432,10 +440,23 @@ handle_introspection (DBusConnection *bus,
 
     g_string_append_printf(output, introspection_node_element, pathstr);
 
-    for (i=0; i < path->introspection->len; i++)
+    if (!path->get_datum || path_get_datum (path, pathstr))
       {
-        gchar *introspect = (gchar *) g_ptr_array_index (path->introspection, i);
-        g_string_append (output, introspect);
+        for (i=0; i < path->introspection->len; i++)
+          {
+            gchar *introspect = (gchar *) g_ptr_array_index (path->introspection, i);
+            g_string_append (output, introspect);
+          }
+      }
+
+    if (path->introspect_children_cb)
+      {
+        gchar *children = (*path->introspect_children_cb) (pathstr, path->introspect_children_data);
+        if (children)
+          {
+            g_string_append (output, children);
+            g_free (children);
+          }
       }
 
     g_string_append(output, introspection_footer);
index d1d845f..3fdfacb 100644 (file)
@@ -31,6 +31,7 @@
 
 typedef DBusMessage *(*DRouteFunction)         (DBusConnection *, DBusMessage *, void *);
 typedef dbus_bool_t  (*DRoutePropertyFunction) (DBusMessageIter *, void *);
+typedef gchar *(*DRouteIntrospectChildrenFunction) (const char *, void *);
 
 typedef void        *(*DRouteGetDatumFunction) (const char *, void *);
 
@@ -72,6 +73,8 @@ DRoutePath *
 droute_add_many (DRouteContext *cnx,
                  const char    *path,
                  const void    *data,
+                 DRouteIntrospectChildrenFunction introspect_children_cb,
+                 void *introspect_children_data,
                  const DRouteGetDatumFunction get_datum);
 
 void