summaryrefslogtreecommitdiff
path: root/droute
diff options
context:
space:
mode:
authorMark Doffman <mdoff@silver-wind.(none)>2008-05-16 16:11:40 +0100
committerMark Doffman <mdoff@silver-wind.(none)>2008-05-16 16:16:19 +0100
commitff143bfb6c3ca9e1a7362bd7f9c7c5eba31eb135 (patch)
tree3661a3149da6031c5a0e74463fdd428738e2bf1b /droute
parent5d01be6ec7d2cb2e662c695bd4c28c50ac3f2dab (diff)
downloadat-spi2-atk-ff143bfb6c3ca9e1a7362bd7f9c7c5eba31eb135.tar.gz
2008-05-16 Mark Doffman <mark.doffman@codethink.co.uk>
Re-organize the directories. The main purpose of this change is to remove CORBA code and references that are no longer used. * atk-adaptor/ Code here used to live in libspi and atk-bridge. * droute/ The droute module has been moved from libspi to its own directory. * spi-common Code and definitions common to registryd and the atk-adaptor. Mostly moved from libspi/dbus.c and accessible.h. * cspi/ Removed for the moment. Will have to be mostly rewritten for D-Bus.
Diffstat (limited to 'droute')
-rw-r--r--droute/Makefile.am12
-rw-r--r--droute/droute.c334
-rw-r--r--droute/droute.h82
-rw-r--r--droute/introspect-loader.c79
-rw-r--r--droute/introspect-loader.h37
5 files changed, 544 insertions, 0 deletions
diff --git a/droute/Makefile.am b/droute/Makefile.am
new file mode 100644
index 0000000..39dccbc
--- /dev/null
+++ b/droute/Makefile.am
@@ -0,0 +1,12 @@
+noinst_LTLIBRARIES = libdroute.la
+
+libdroute_la_CFLAGS = $(DBUS_GLIB_CFLAGS) $(ATK_CFLAGS)\
+ -DATSPI_INTROSPECTION_PATH=\"$(DEFAULT_ATSPI_INTROSPECTION_PATH)\"\
+ -I$(top_builddir)\
+ -I$(top_srcdir)
+
+libdroute_la_SOURCES = \
+ droute.c \
+ droute.h \
+ introspect-loader.c \
+ introspect-loader.h
diff --git a/droute/droute.c b/droute/droute.c
new file mode 100644
index 0000000..e4c1f91
--- /dev/null
+++ b/droute/droute.c
@@ -0,0 +1,334 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2008 Novell, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "droute.h"
+
+static DRouteInterface *
+find_iface (DRouteData * data, const char *name)
+{
+ GSList *l;
+
+ for (l = data->interfaces; l; l = g_slist_next (l))
+ {
+ DRouteInterface *iface = (DRouteInterface *) l->data;
+ if (iface && iface->name && !strcmp (iface->name, name))
+ return iface;
+ }
+ return NULL;
+}
+
+static DBusHandlerResult
+prop_get_all (DBusConnection * bus, DBusMessage * message, DRouteData * data)
+{
+ DRouteInterface *iface_def;
+ DRouteProperty *prop;
+ DBusError error;
+ const char *iface;
+ const char *path = dbus_message_get_path (message);
+ DBusMessage *reply;
+ DBusMessageIter iter, iter_dict, iter_dict_entry;
+
+ dbus_error_init (&error);
+ if (!dbus_message_get_args
+ (message, &error, DBUS_TYPE_STRING, &iface, DBUS_TYPE_INVALID))
+ {
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+ reply = dbus_message_new_method_return (message);
+ /* tbd: replace tbd with todo? */
+ if (!reply)
+ goto oom;
+ dbus_message_iter_init_append (reply, &iter);
+ if (!dbus_message_iter_open_container
+ (&iter, DBUS_TYPE_ARRAY, "{sv}", &iter_dict))
+ goto oom;
+ iface_def = find_iface (data, iface);
+ if (!iface_def)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ if (iface_def->properties)
+ for (prop = iface_def->properties; prop->name; prop++)
+ {
+ if (!prop->get)
+ continue;
+ if (!dbus_message_iter_open_container
+ (&iter_dict, DBUS_TYPE_DICT_ENTRY, NULL, &iter_dict_entry))
+ goto oom;
+ dbus_message_iter_append_basic (&iter_dict_entry, DBUS_TYPE_STRING,
+ &prop->name);
+ (*prop->get) (path, &iter_dict_entry, data->user_data);
+ if (!dbus_message_iter_close_container (&iter_dict, &iter_dict_entry))
+ goto oom;
+ }
+ if (!dbus_message_iter_close_container (&iter, &iter_dict))
+ goto oom;
+ dbus_connection_send (bus, reply, NULL);
+ dbus_message_unref (reply);
+ return DBUS_HANDLER_RESULT_HANDLED;
+oom:
+ /* tbd: return a standard out-of-memory error */
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static DBusHandlerResult
+prop (DBusConnection * bus, DBusMessage * message, DRouteData * data)
+{
+ const char *mode = dbus_message_get_member (message);
+ const char *iface, *member;
+ const char *path = dbus_message_get_path (message);
+ int set;
+ DBusMessage *reply;
+ DBusMessageIter iter;
+ DRouteInterface *iface_def;
+ DRouteProperty *prop = NULL;
+
+ if (!strcmp (mode, "Set"))
+ set = 1;
+ else if (!strcmp (mode, "Get"))
+ set = 0;
+ else
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ reply = dbus_message_new_method_return (message);
+ dbus_message_iter_init (message, &iter);
+ dbus_message_iter_get_basic (&iter, &iface);
+ dbus_message_iter_next (&iter);
+ dbus_message_iter_get_basic (&iter, &member);
+ if (!set)
+ dbus_message_iter_init_append (reply, &iter);
+ iface_def = find_iface (data, iface);
+ if (!iface_def)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ if (iface_def->properties)
+ for (prop = iface_def->properties;
+ prop->name && strcmp (prop->name, member); prop++)
+ if (!prop || !prop->name)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ if (set)
+ {
+ if (!prop->set)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ (*prop->set) (path, &iter, data->user_data);
+ }
+ else
+ {
+ if (!prop->get)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ (*prop->get) (path, &iter, data->user_data);
+ }
+ dbus_connection_send (bus, reply, NULL);
+ dbus_message_unref (reply);
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+DBusHandlerResult
+droute_message (DBusConnection * bus, DBusMessage * message, void *user_data)
+{
+ DRouteData *data = (DRouteData *) user_data;
+ DRouteInterface *iface_def;
+ DRouteMethod *method;
+ const char *iface = dbus_message_get_interface (message);
+ const char *member = dbus_message_get_member (message);
+ int type;
+ DBusError error;
+ DBusMessage *reply;
+
+ dbus_error_init (&error);
+ if (!member)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ if (iface && !strcmp (iface, "org.freedesktop.DBus.Properties"))
+ {
+ if (!strcmp (member, "GetAll"))
+ return prop_get_all (bus, message, data);
+ return prop (bus, message, data);
+ }
+ if (iface)
+ {
+ iface_def = find_iface (data, iface);
+ if (!iface_def)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ if (iface_def->methods)
+ for (method = iface_def->methods; method->func; method++)
+ {
+ if (!strcmp (method->name, member))
+ {
+ reply =
+ (*method->func) (bus, message,
+ (method->wants_droute_data ? data : data->
+ user_data));
+ if (reply)
+ {
+ dbus_connection_send (bus, reply, NULL);
+ dbus_message_unref (reply);
+ }
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+ }
+ }
+ else
+ {
+ GSList *l;
+ if (type == DBUS_MESSAGE_TYPE_SIGNAL)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ for (l = data->interfaces; l; l = g_slist_next (l))
+ {
+ iface_def = (DRouteInterface *) l->data;
+ if (iface_def->methods)
+ for (method = iface_def->methods; method->func; method++)
+ {
+ if (!strcmp (method->name, member))
+ {
+ reply = (*method->func) (bus, message, data->user_data);
+ if (reply)
+ {
+ dbus_connection_send (bus, reply, NULL);
+ dbus_message_unref (reply);
+ }
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+ }
+ }
+ }
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+dbus_bool_t
+droute_return_v_int32 (DBusMessageIter * iter, dbus_int32_t val)
+{
+ DBusMessageIter sub;
+
+ if (!dbus_message_iter_open_container
+ (iter, DBUS_TYPE_VARIANT, DBUS_TYPE_INT32_AS_STRING, &sub))
+ {
+ return FALSE;
+ }
+ dbus_message_iter_append_basic (&sub, DBUS_TYPE_INT32, &val);
+ dbus_message_iter_close_container (iter, &sub);
+ return TRUE;
+}
+
+dbus_bool_t
+droute_return_v_double (DBusMessageIter * iter, double val)
+{
+ DBusMessageIter sub;
+
+ if (!dbus_message_iter_open_container
+ (iter, DBUS_TYPE_VARIANT, DBUS_TYPE_DOUBLE_AS_STRING, &sub))
+ {
+ return FALSE;
+ }
+ dbus_message_iter_append_basic (&sub, DBUS_TYPE_DOUBLE, &val);
+ dbus_message_iter_close_container (iter, &sub);
+ return TRUE;
+}
+
+/* Return a string in a variant
+ * will return an empty string if passed a NULL value */
+dbus_bool_t
+droute_return_v_string (DBusMessageIter * iter, const char *val)
+{
+ DBusMessageIter sub;
+
+ if (!val)
+ val = "";
+ if (!dbus_message_iter_open_container
+ (iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &sub))
+ {
+ return FALSE;
+ }
+ dbus_message_iter_append_basic (&sub, DBUS_TYPE_STRING, &val);
+ dbus_message_iter_close_container (iter, &sub);
+ return TRUE;
+}
+
+dbus_int32_t
+droute_get_v_int32 (DBusMessageIter * iter)
+{
+ DBusMessageIter sub;
+ dbus_int32_t rv;
+
+ // TODO- ensure we have the correct type
+ dbus_message_iter_recurse (iter, &sub);
+ dbus_message_iter_get_basic (&sub, &rv);
+ return rv;
+}
+
+const char *
+droute_get_v_string (DBusMessageIter * iter)
+{
+ DBusMessageIter sub;
+ char *rv;
+
+ // TODO- ensure we have the correct type
+ dbus_message_iter_recurse (iter, &sub);
+ dbus_message_iter_get_basic (&sub, &rv);
+ return rv;
+}
+
+dbus_bool_t
+droute_return_v_object (DBusMessageIter * iter, const char *path)
+{
+ DBusMessageIter sub;
+
+ if (!dbus_message_iter_open_container
+ (iter, DBUS_TYPE_VARIANT, DBUS_TYPE_OBJECT_PATH_AS_STRING, &sub))
+ {
+ return FALSE;
+ }
+ dbus_message_iter_append_basic (&sub, DBUS_TYPE_OBJECT_PATH, &path);
+ dbus_message_iter_close_container (iter, &sub);
+ return TRUE;
+}
+
+dbus_bool_t
+droute_add_interface (DRouteData * data, const char *name,
+ DRouteMethod * methods, DRouteProperty * properties,
+ DRouteGetDatumFunction get_datum,
+ DRouteFreeDatumFunction free_datum)
+{
+ DRouteInterface *iface =
+ (DRouteInterface *) malloc (sizeof (DRouteInterface));
+ GSList *new_list;
+
+ if (!iface)
+ return FALSE;
+ iface->name = strdup (name);
+ if (!iface->name)
+ {
+ free (iface);
+ return FALSE;
+ }
+ iface->methods = methods;
+ iface->properties = properties;
+ iface->get_datum = get_datum;
+ iface->free_datum = free_datum;
+ new_list = g_slist_append (data->interfaces, iface);
+ if (!new_list)
+ {
+ free (iface->name);
+ free (iface);
+ return FALSE;
+ }
+ data->interfaces = new_list;
+ return TRUE;
+}
diff --git a/droute/droute.h b/droute/droute.h
new file mode 100644
index 0000000..c3006cc
--- /dev/null
+++ b/droute/droute.h
@@ -0,0 +1,82 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2008 Novell, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#ifndef _DROUTE_H
+#define _DROUTE_H
+
+#include <dbus/dbus.h>
+#include "glib.h" /* needed for GString */
+
+#define DROUTE_METHOD 0
+#define DROUTE_SIGNAL 1
+
+typedef DBusMessage *(*DRouteFunction)(DBusConnection *, DBusMessage *, void *);
+typedef dbus_bool_t (*DRoutePropertyFunction)(const char *, DBusMessageIter *, void *);
+
+typedef struct _DRouteMethod DRouteMethod;
+struct _DRouteMethod
+{
+ DRouteFunction func;
+ const char *name;
+ dbus_bool_t wants_droute_data;
+};
+
+typedef struct _DRouteProperty DRouteProperty;
+struct _DRouteProperty
+{
+ DRoutePropertyFunction get;
+ DRoutePropertyFunction set;
+ const char *name;
+};
+
+ typedef void *(*DRouteGetDatumFunction)(const char *, void *);
+ typedef void (*DRouteFreeDatumFunction)(void *);
+
+typedef struct _DRouteInterface DRouteInterface;
+struct _DRouteInterface
+{
+ DRouteMethod *methods;
+ DRouteProperty *properties;
+ DRouteGetDatumFunction get_datum;
+ DRouteFreeDatumFunction free_datum;
+ char *name;
+};
+
+typedef struct _DRouteData DRouteData;
+struct _DRouteData
+{
+ DBusConnection *bus;
+ GSList *interfaces;
+ char (*introspect_children)(const char *, GString *, void *);
+ void *user_data;
+};
+
+DBusHandlerResult droute_message(DBusConnection *bus, DBusMessage *message, void *user_data);
+
+dbus_bool_t droute_return_v_int32(DBusMessageIter *iter, dbus_int32_t val);
+dbus_bool_t droute_return_v_double(DBusMessageIter *iter, double val);
+dbus_bool_t droute_return_v_string(DBusMessageIter *iter, const char *val);
+dbus_int32_t droute_get_v_int32(DBusMessageIter *iter);
+const char *droute_get_v_string(DBusMessageIter *iter);
+dbus_bool_t droute_return_v_object(DBusMessageIter *iter, const char *path);
+
+dbus_bool_t droute_add_interface(DRouteData *data, const char *name, DRouteMethod *methods, DRouteProperty *properties, DRouteGetDatumFunction get_datum, DRouteFreeDatumFunction free_datum);
+#endif /* _DROUTE_H */
diff --git a/droute/introspect-loader.c b/droute/introspect-loader.c
new file mode 100644
index 0000000..723d3d6
--- /dev/null
+++ b/droute/introspect-loader.c
@@ -0,0 +1,79 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2008 Codethink Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <glib.h>
+
+/*
+ * This file contains utilities for loading introspection XML
+ * from the local file system.
+ *
+ * There is an installation directory with files containing introspection xml.
+ * Each file is named after the interface it describes.
+ */
+
+/*
+ * Provides the path for the introspection directory.
+ */
+#if !defined ATSPI_INTROSPECTION_PATH
+ #error "No introspection XML directory defined"
+#endif
+
+const char *spi_introspection_header =
+"<?xml version=\"1.0\"?>\n";
+
+const char *spi_introspection_node_element =
+"<node name=\"%s\">\n";
+
+const char *spi_introspection_footer =
+"</node>";
+
+void
+spi_append_interface (GString *str, const char *interface)
+{
+ char *filename;
+ char *contents;
+ char *introspection_directory;
+ gsize len;
+
+ GError *err = NULL;
+
+ introspection_directory = (char *) g_getenv("ATSPI_INTROSPECTION_PATH");
+ if (introspection_directory == NULL)
+ introspection_directory = ATSPI_INTROSPECTION_PATH;
+
+ filename = g_build_filename(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);
+}
diff --git a/droute/introspect-loader.h b/droute/introspect-loader.h
new file mode 100644
index 0000000..bfea0b7
--- /dev/null
+++ b/droute/introspect-loader.h
@@ -0,0 +1,37 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2008 Codethink Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef SPI_INTROSPECT_LOADER_H_
+#define SPI_INTROSPECT_LOADER_H_
+
+#include <glib.h>
+
+extern const char *spi_introspection_header;
+
+extern const char *spi_introspection_node_element;
+
+extern const char *spi_introspection_footer;
+
+void
+spi_append_interface (GString *str, const char *interface);
+
+#endif /* SPI_INTROSPECT_LOADER_H_ */