From d003bb5eaf76db6e3206425ccbfa4593c6c496eb Mon Sep 17 00:00:00 2001 From: Mark Doffman Date: Tue, 13 May 2008 15:42:25 +0100 Subject: [PATCH] Changes to enable new introspection format. Add one introspection XML file, and update bridge to register modified tree object that uses the introspection. --- atk-bridge/bridge.c | 3 +- libspi/Makefile.am | 18 +++--- libspi/accessible.h | 4 +- libspi/dbus.c | 2 +- libspi/introspectable.c | 90 ++++++---------------------- libspi/tree.c | 89 ++++++++++++++++++++++++--- xml/Accessibility_Tree.xml | 1 + xml/introspection/org.freedesktop.atspi.Tree | 12 ++++ 8 files changed, 130 insertions(+), 89 deletions(-) create mode 100644 xml/introspection/org.freedesktop.atspi.Tree diff --git a/atk-bridge/bridge.c b/atk-bridge/bridge.c index 3ccfc9e..ec6ddd0 100644 --- a/atk-bridge/bridge.c +++ b/atk-bridge/bridge.c @@ -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"); } diff --git a/libspi/Makefile.am b/libspi/Makefile.am index 5154baa..b0a8045 100644 --- a/libspi/Makefile.am +++ b/libspi/Makefile.am @@ -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 $< >$@ diff --git a/libspi/accessible.h b/libspi/accessible.h index b624317..a8cfdbc 100644 --- a/libspi/accessible.h +++ b/libspi/accessible.h @@ -44,9 +44,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); diff --git a/libspi/dbus.c b/libspi/dbus.c index a2cfbce..922a93a 100644 --- a/libspi/dbus.c +++ b/libspi/dbus.c @@ -183,9 +183,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 * diff --git a/libspi/introspectable.c b/libspi/introspectable.c index eb6d7d9..fdd8ae1 100644 --- a/libspi/introspectable.c +++ b/libspi/introspectable.c @@ -24,6 +24,7 @@ #include #include "droute.h" +#include "introspect-loader.h" /* * This file contains an implementation of the D-Bus introspectable interface. @@ -31,61 +32,8 @@ */ /* - * 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 = -"\n"; - -static const char *introspection_node_element = -"\n"; - -static const char *introspection_footer = -""; - -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); }; diff --git a/libspi/tree.c b/libspi/tree.c index 92f7f89..fe26fbe 100644 --- a/libspi/tree.c +++ b/libspi/tree.c @@ -22,7 +22,10 @@ * Boston, MA 02111-1307, USA. */ +#include + #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; diff --git a/xml/Accessibility_Tree.xml b/xml/Accessibility_Tree.xml index 2a10fb5..f0164a9 100644 --- a/xml/Accessibility_Tree.xml +++ b/xml/Accessibility_Tree.xml @@ -112,6 +112,7 @@

Array of Accessible Object proxy structures to be added.

+

Array of Accessible Object proxy structures to be removed.

diff --git a/xml/introspection/org.freedesktop.atspi.Tree b/xml/introspection/org.freedesktop.atspi.Tree new file mode 100644 index 0000000..7171efb --- /dev/null +++ b/xml/introspection/org.freedesktop.atspi.Tree @@ -0,0 +1,12 @@ + + + + + + + + + + + + -- 2.7.4