2008-05-16 Mark Doffman <mark.doffman@codethink.co.uk>
[platform/core/uifw/at-spi2-atk.git] / spi-common / spi-dbus.c
similarity index 62%
rename from libspi/dbus.c
rename to spi-common/spi-dbus.c
index 2263a6d..4e176e1 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
-#include "accessible.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <glib.h>
+#include <glib-object.h>
+#include <dbus/dbus.h>
 
-static GHashTable *path2ptr;
+#include "spi-types.h"
+
+GHashTable *path2ptr;
 static guint objindex;
 
 static void
@@ -36,7 +40,7 @@ deregister_object (gpointer data, GObject *obj)
 }
 
 static guint
-register_object (AtkObject * obj)
+register_object (GObject * obj)
 {
   gint *new_int;
 
@@ -66,35 +70,6 @@ register_object (AtkObject * obj)
   return objindex;
 }
 
-AtkObject *
-spi_dbus_get_object (const char *path)
-{
-  guint index;
-  void *data;
-
-  g_assert (path);
-  if (strncmp(path, "/org/freedesktop/atspi/accessible", 33) != 0) return NULL;
-  path += 33;  /* skip over preamble */
-  if (path[0] == '\0') return atk_get_root();
-  if (path[0] != '/') return NULL;
-  path++;
-  index = atoi (path);
-  data = g_hash_table_lookup (path2ptr, &index);
-  if (data)
-    return ATK_OBJECT (data);
-  return NULL;
-}
-
-gchar *
-spi_dbus_get_path (AtkObject * obj)
-{
-  if (!obj) return NULL;
-  guint index = (guint) g_object_get_data (G_OBJECT (obj), "dbus-id");
-  if (!index)
-    index = register_object (obj);
-  return g_strdup_printf ("/org/freedesktop/atspi/accessible/%d", index);
-}
-
 DBusMessage *
 spi_dbus_general_error (DBusMessage * message)
 {
@@ -103,27 +78,6 @@ spi_dbus_general_error (DBusMessage * message)
                                 "General error");
 }
 
-/* Reply with the given object and dereference it if unref is TRUE */
-DBusMessage *
-spi_dbus_return_object (DBusMessage * message, AtkObject * obj, int unref)
-{
-  DBusMessage *reply;
-  const char *path = spi_dbus_get_path (obj);
-  if (unref)
-    g_object_unref (obj);
-  if (!path)
-    {
-      /* Should we have a more specific error for this? */
-      return spi_dbus_general_error (message);
-    }
-  reply = dbus_message_new_method_return (message);
-  if (reply)
-    {
-      dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, path,
-                               DBUS_TYPE_INVALID);
-    }
-  return reply;
-}
 
 DBusMessage *
 spi_dbus_return_rect (DBusMessage * message, gint ix, gint iy, gint iwidth,
@@ -157,36 +111,6 @@ oom:
   return reply;
 }
 
-dbus_bool_t
-spi_dbus_return_v_object (DBusMessageIter * iter, AtkObject * obj, int unref)
-{
-  const char *path = spi_dbus_get_path (obj);
-  if (unref)
-    g_object_unref (obj);
-  if (!path)
-    return FALSE;
-  return droute_return_v_object (iter, path);
-}
-
-
-void
-spi_dbus_initialize (DRouteData * data)
-{
-  spi_initialize_accessible (data);
-  spi_initialize_action(data);
-  spi_initialize_component (data);
-  spi_initialize_document (data);
-  spi_initialize_editabletext (data);
-  spi_initialize_hyperlink (data);
-  spi_initialize_hypertext (data);
-  spi_initialize_image (data);
-  spi_initialize_selection (data);
-  spi_initialize_table (data);
-  spi_initialize_text (data);
-  spi_initialize_value (data);
-  spi_initialize_introspectable(data);
-}
-
 void spi_dbus_emit_valist(DBusConnection *bus, const char *path, const char *interface, const char *name, int first_arg_type, va_list args)
 {
   DBusMessage *sig;
@@ -200,51 +124,6 @@ void spi_dbus_emit_valist(DBusConnection *bus, const char *path, const char *int
   dbus_message_unref(sig);
 }
 
-static GString *
-spi_get_tree (AtkObject * obj, GString * str, DRouteData * data)
-{
-  int role;
-  const char *name;
-  gchar *path;
-  GSList *l;
-  gint childcount;
-  gint i;
-
-  if (!obj)
-    return NULL;
-  role = spi_accessible_role_from_atk_role (atk_object_get_role (obj));;
-  name = atk_object_get_name (obj);
-  if (!name)
-    name = "";
-  path = spi_dbus_get_path (obj);
-  g_string_append_printf (str,
-                         "<object path=\"%s\" name=\"%s\" role=\"%d\">\n",
-                         path, name, role);
-  for (l = data->interfaces; l; l = g_slist_next (l))
-    {
-      DRouteInterface *iface_def = (DRouteInterface *) l->data;
-      void *datum = NULL;
-      if (iface_def->get_datum)
-       datum = (*iface_def->get_datum) (path, data->user_data);
-      if (datum)
-       {
-         g_string_append_printf (str, "<interface name=\"%s\"/>\n",
-                                 iface_def->name);
-         if (iface_def->free_datum)
-           (*iface_def->free_datum) (datum);
-       }
-    }
-  childcount = atk_object_get_n_accessible_children (obj);
-  for (i = 0; i < childcount; i++)
-    {
-      AtkObject *child = atk_object_ref_accessible_child (obj, i);
-      str = spi_get_tree (child, str, data);
-      g_object_unref (child);
-    }
-  str = g_string_append (str, "</object>\n");
-  return str;
-}
-
 dbus_bool_t spi_dbus_message_iter_get_struct(DBusMessageIter *iter, ...)
 {
   va_list args;