Initial commit.
[platform/core/uifw/at-spi2-atk.git] / libspi / hypertext.c
index 7c5aae7..6152235 100644 (file)
@@ -2,8 +2,9 @@
  * AT-SPI - Assistive Technology Service Provider Interface
  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
  *
+ * Copyright 2008 Novell, Inc.
  * Copyright 2001, 2002 Sun Microsystems Inc.,
- * Copyright 2001, 2002 Ximian, Inc. Ximian Inc.
+ * Copyright 2001, 2002 Ximian, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
  * Boston, MA 02111-1307, USA.
  */
 
-/* hypertext.c : implements the HyperText interface */
+#include "accessible.h"
 
-#include <config.h>
-#include <stdio.h>
-#include <atk/atkhypertext.h>
-#include <libspi/hyperlink.h>
-#include <libspi/hypertext.h>
-
-#define PARENT_TYPE SPI_TYPE_BASE
-
-SpiHypertext *
-spi_hypertext_interface_new (AtkObject *obj)
+static AtkHypertext *
+get_hypertext (DBusMessage * message)
 {
-  SpiHypertext *new_hypertext = g_object_new (SPI_HYPERTEXT_TYPE, NULL);
-
-  spi_base_construct (SPI_BASE (new_hypertext), G_OBJECT (obj));
-
-  return new_hypertext;
+  AtkObject *obj = spi_dbus_get_object (dbus_message_get_path (message));
+  if (!obj)
+    return NULL;
+  return ATK_HYPERTEXT (obj);
 }
 
-
 static AtkHypertext *
-get_hypertext_from_servant (PortableServer_Servant servant)
+get_hypertext_from_path (const char *path, void *user_data)
 {
-  SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
-
-  g_return_val_if_fail (object, NULL);
-  g_return_val_if_fail (ATK_IS_OBJECT(object->gobj), NULL);
-  return ATK_HYPERTEXT (object->gobj);
+  AtkObject *obj = spi_dbus_get_object (path);
+  if (!obj)
+    return NULL;
+  return ATK_HYPERTEXT (obj);
 }
 
-
-static CORBA_long
-impl_getNLinks (PortableServer_Servant servant,
-               CORBA_Environment     *ev)
+static DBusMessage *
+impl_getNLinks (DBusConnection * bus, DBusMessage * message, void *user_data)
 {
-  AtkHypertext *hypertext = get_hypertext_from_servant (servant);
-
-  g_return_val_if_fail (hypertext != NULL, 0);
-
-  return atk_hypertext_get_n_links (hypertext);
+  AtkHypertext *hypertext = get_hypertext (message);
+  gint rv;
+  DBusMessage *reply;
+
+  if (!hypertext)
+    return spi_dbus_general_error (message);
+  rv = atk_hypertext_get_n_links (hypertext);
+  reply = dbus_message_new_method_return (message);
+  if (reply)
+    {
+      dbus_message_append_args (reply, DBUS_TYPE_INT32, &rv,
+                               DBUS_TYPE_INVALID);
+    }
+  return reply;
 }
 
-
-static Accessibility_Hyperlink
-impl_getLink (PortableServer_Servant servant,
-             const CORBA_long       linkIndex,
-             CORBA_Environment     *ev)
+static DBusMessage *
+impl_getLink (DBusConnection * bus, DBusMessage * message, void *user_data)
 {
+  AtkHypertext *hypertext = get_hypertext (message);
+  DBusError error;
+  dbus_int32_t linkIndex;
   AtkHyperlink *link;
-  Accessibility_Hyperlink rv;
-  AtkHypertext *hypertext = get_hypertext_from_servant (servant);
 
-  g_return_val_if_fail (hypertext != NULL, CORBA_OBJECT_NIL);
-  
+  if (!hypertext)
+    return spi_dbus_general_error (message);
+  dbus_error_init (&error);
+  if (!dbus_message_get_args
+      (message, &error, DBUS_TYPE_INT32, &linkIndex, DBUS_TYPE_INVALID))
+    {
+      return SPI_DBUS_RETURN_ERROR (message, &error);
+    }
   link = atk_hypertext_get_link (hypertext, linkIndex);
-  g_return_val_if_fail (link != NULL, CORBA_OBJECT_NIL);
-
-  rv = BONOBO_OBJREF (spi_hyperlink_new (link));
-
-  return CORBA_Object_duplicate (rv, ev);
+  return spi_dbus_return_object (message, ATK_OBJECT (link), FALSE);
 }
 
-
-static CORBA_long
-impl_getLinkIndex (PortableServer_Servant servant,
-                  const CORBA_long       characterIndex,
-                  CORBA_Environment     *ev)
-{
-  AtkHypertext *hypertext = get_hypertext_from_servant (servant);
-
-  g_return_val_if_fail (hypertext != NULL, 0);
-
-  return atk_hypertext_get_link_index (hypertext,
-                                 characterIndex);
-}
-
-
-static void
-spi_hypertext_class_init (SpiHypertextClass *klass)
+static DBusMessage *
+impl_getLinkIndex (DBusConnection * bus, DBusMessage * message,
+                  void *user_data)
 {
-  POA_Accessibility_Hypertext__epv *epv = &klass->epv;
-
-  /* Initialize epv table */
-
-  epv->getNLinks = impl_getNLinks;
-  epv->getLink = impl_getLink;
-  epv->getLinkIndex = impl_getLinkIndex;
+  AtkHypertext *hypertext = get_hypertext (message);
+  DBusError error;
+  dbus_int32_t characterIndex;
+  dbus_int32_t rv;
+  DBusMessage *reply;
+
+  if (!hypertext)
+    return spi_dbus_general_error (message);
+  dbus_error_init (&error);
+  if (!dbus_message_get_args
+      (message, &error, DBUS_TYPE_INT32, &characterIndex, DBUS_TYPE_INVALID))
+    {
+      return SPI_DBUS_RETURN_ERROR (message, &error);
+    }
+  rv = atk_hypertext_get_link_index (hypertext, characterIndex);
+  reply = dbus_message_new_method_return (message);
+  if (reply)
+    {
+      dbus_message_append_args (reply, DBUS_TYPE_INT32, &rv,
+                               DBUS_TYPE_INVALID);
+    }
+  return reply;
 }
 
+static DRouteMethod methods[] = {
+  {DROUTE_METHOD, impl_getNLinks, "getNLinks", "i,,o"},
+  {DROUTE_METHOD, impl_getLink, "getLink", "i,linkIndex,i:o,,o"},
+  {DROUTE_METHOD, impl_getLinkIndex, "getLinkIndex",
+   "i,characterIndex,i:i,,o"},
+  {0, NULL, NULL, NULL}
+};
 
-static void
-spi_hypertext_init (SpiHypertext *hypertext)
+void
+spi_initialize_hypertext (DRouteData * data)
 {
-}
-
-
-BONOBO_TYPE_FUNC_FULL (SpiHypertext,
-                      Accessibility_Hypertext,
-                      PARENT_TYPE,
-                      spi_hypertext);
+  droute_add_interface (data, "org.freedesktop.accessibility.Hypertext",
+                       methods, NULL,
+                       (DRouteGetDatumFunction) get_hypertext_from_path,
+                       NULL);
+};