Add Action interface.
authorMike Gorse <mgorse@boston.site>
Thu, 17 Apr 2008 21:17:53 +0000 (17:17 -0400)
committerMike Gorse <mgorse@boston.site>
Thu, 17 Apr 2008 21:17:53 +0000 (17:17 -0400)
Add Action interface

libspi/accessible.h
libspi/action.c
xml/Accessibility_Action.xml

index 62279806827a0f31dc1739d2c2104700c1325d9a..dbc5d54f5dab0be78dfaeb6c9deddd3d130e8669 100644 (file)
@@ -34,6 +34,7 @@ G_BEGIN_DECLS
 Accessibility_Role spi_accessible_role_from_atk_role (AtkRole role);
 
 void spi_initialize_accessible(DRouteData *data);
+void spi_initialize_action(DRouteData *data);
 void spi_initialize_application(DRouteData *data);
 void spi_initialize_component(DRouteData *data);
 void spi_initialize_document(DRouteData *data);
index a60af4276e7d76975e6bdd5bb6c557475e4b9d7e..4641086f75c53b22392fb36dbb9b5961dfc96306 100644 (file)
@@ -1,7 +1,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.
  *
  * Boston, MA 02111-1307, USA.
  */
 
-/* component.c : bonobo wrapper for accessible component implementation */
-
-#include <config.h>
-#include <stdio.h>
-#include <libspi/action.h>
-#include <atk/atkaction.h>
-
-/*
- * Static function declarations
- */
-
-static void
-spi_action_class_init (SpiActionClass *klass);
-static void
-spi_action_init (SpiAction *action);
-static CORBA_long
-impl__get_nActions(PortableServer_Servant servant,
-                CORBA_Environment * ev);
-static CORBA_string
-impl_getDescription (PortableServer_Servant servant,
-                    const CORBA_long index,
-                    CORBA_Environment * ev);
-static CORBA_boolean 
-impl_doAction (PortableServer_Servant servant,
-              const CORBA_long index, CORBA_Environment * ev);
-static CORBA_string
-impl_getName (PortableServer_Servant servant,
-             const CORBA_long index,
-             CORBA_Environment * ev);
-static CORBA_string
-impl_getKeyBinding (PortableServer_Servant servant,
-                   const CORBA_long index,
-                   CORBA_Environment * ev);
-
-BONOBO_TYPE_FUNC_FULL (SpiAction,
-                      Accessibility_Action,
-                      SPI_TYPE_BASE,
-                      spi_action)
-
-static void
-spi_action_class_init (SpiActionClass *klass)
-{
-  POA_Accessibility_Action__epv *epv = &klass->epv;
-
-  /* Initialize epv table */
-
-  epv->_get_nActions = impl__get_nActions;
-  epv->doAction = impl_doAction;
-  epv->getDescription = impl_getDescription;
-  epv->getName = impl_getName;
-  epv->getKeyBinding = impl_getKeyBinding;
-}
-
-static void
-spi_action_init (SpiAction *action)
-{
-}
-
-SpiAction *
-spi_action_interface_new (AtkObject *obj)
-{
-  SpiAction *new_action = g_object_new (SPI_ACTION_TYPE, NULL);
-
-  spi_base_construct (SPI_BASE (new_action), G_OBJECT(obj));
-
-  return new_action;
-}
+#include "accessible.h"
 
 static AtkAction *
-get_action_from_servant (PortableServer_Servant servant)
+get_action (DBusMessage * message)
 {
-  SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
-  g_return_val_if_fail (object != NULL, NULL);
-  /* the convention of making hyperlinks actionable breaks the assertion below */
-  /* g_return_val_if_fail (ATK_IS_OBJECT(object->gobj), NULL); */
-  return ATK_ACTION (object->gobj);
+  AtkObject *obj = spi_dbus_get_object (dbus_message_get_path (message));
+  if (!obj)
+    return NULL;
+  return ATK_ACTION (obj);
 }
 
-static CORBA_long
-impl__get_nActions (PortableServer_Servant servant,
-                   CORBA_Environment     *ev)
+static AtkAction *
+get_action_from_path (const char *path, void *user_data)
 {
-  AtkAction *action = get_action_from_servant (servant);
-  return atk_action_get_n_actions (action);
+  AtkObject *obj = spi_dbus_get_object (path);
+  if (!obj)
+    return NULL;
+  return ATK_ACTION (obj);
 }
 
-static CORBA_boolean
-impl_doAction (PortableServer_Servant servant,
-              const CORBA_long index, CORBA_Environment * ev)
+static DBusMessage *impl_getActions(DBusConnection *bus, DBusMessage *message, void *user_data)
 {
-  AtkAction *action = get_action_from_servant (servant);
-  return atk_action_do_action (action, (gint) index);
+  AtkAction *action = get_action(message);
+  DBusMessage *reply;
+  gint count;
+  gint i;
+  DBusMessageIter iter, iter_array, iter_struct;
+
+  if (!action)
+    return spi_dbus_general_error (message);
+  count = atk_action_get_n_actions(action);
+  reply = dbus_message_new_method_return (message);
+  if (!reply) goto oom;
+  dbus_message_iter_init_append (reply, &iter);
+  if (!dbus_message_iter_open_container
+      (&iter, DBUS_TYPE_ARRAY, "(sss)", &iter_array))
+    goto oom;
+  for (i = 0; i < count; i++)
+    {
+      const char *name = atk_action_get_name(action, i);
+      const char *desc = atk_action_get_description(action, i);
+      const char *kb = atk_action_get_keybinding(action, i);
+      if (!name) name = "";
+      if (!desc) desc = "";
+      if (!kb) kb = "";
+      if (!dbus_message_iter_open_container(&iter_array, DBUS_TYPE_STRUCT, NULL, &iter_struct)) goto oom;
+      dbus_message_iter_append_basic(&iter_struct, DBUS_TYPE_STRING, &name);
+      dbus_message_iter_append_basic(&iter_struct, DBUS_TYPE_STRING, &desc);
+      dbus_message_iter_append_basic(&iter_struct, DBUS_TYPE_STRING, &kb);
+      if (!dbus_message_iter_close_container(&iter_array, &iter_struct)) goto oom;
+    }
+  if (!dbus_message_iter_close_container (&iter, &iter_array))
+    goto oom;
+  return reply;
+oom:
+  // TODO: handle out-of-memory
+  return reply;
 }
 
-static CORBA_string
-impl_getDescription (PortableServer_Servant servant,
-               const CORBA_long index,
-               CORBA_Environment * ev)
+static DBusMessage *impl_doAction(DBusConnection *bus, DBusMessage *message, void *user_data)
 {
-  AtkAction *action = get_action_from_servant (servant);
-  const gchar *rv;
-  
-  rv = atk_action_get_description (action, index);
-  if (rv)
-    return CORBA_string_dup (rv);
-  else
-    return CORBA_string_dup ("");
+  AtkAction *action = get_action(message);
+  DBusError error;
+  dbus_int32_t index;
+  dbus_bool_t rv;
+  DBusMessage *reply;
+
+  if (!action)
+    return spi_dbus_general_error (message);
+  dbus_error_init (&error);
+  if (!dbus_message_get_args
+      (message, &error, DBUS_TYPE_INT32, &index, DBUS_TYPE_INVALID))
+    {
+      return SPI_DBUS_RETURN_ERROR (message, &error);
+    }
+  rv = atk_action_do_action(action, index);
+  reply = dbus_message_new_method_return (message);
+  if (reply)
+    {
+      dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv, DBUS_TYPE_INVALID);
+    }
+  return reply;
 }
 
-static CORBA_string
-impl_getName (PortableServer_Servant servant,
-               const CORBA_long index,
-               CORBA_Environment * ev)
+DRouteMethod methods[] =
 {
-  AtkAction *action = get_action_from_servant (servant);
-  const gchar *rv;
-  
-  rv = atk_action_get_name (action, index);
-  if (rv)
-    return CORBA_string_dup (rv);
-  else
-    return CORBA_string_dup ("");
-}
+  { DROUTE_METHOD, impl_getActions, "getActions", "a(sss),,o" },
+  { DROUTE_METHOD, impl_doAction, "doAction", "i,index,i:b,,o" },
+  { 0, NULL, NULL, NULL }
+};
 
-static CORBA_string
-impl_getKeyBinding (PortableServer_Servant servant,
-                   const CORBA_long index,
-                   CORBA_Environment * ev)
+void
+spi_initialize_action (DRouteData * data)
 {
-  AtkAction *action = get_action_from_servant (servant);
-  const gchar *rv;
-  
-  rv = atk_action_get_keybinding (action, index);
-  if (rv)
-    return CORBA_string_dup (rv);
-  else
-    return CORBA_string_dup ("");
-}
+  droute_add_interface (data, "org.freedesktop.accessibility.Action",
+                       methods, NULL,
+                       (DRouteGetDatumFunction) get_action_from_path,
+                       NULL);
+};
index bdb4fae11569d4772351d8a11f744885a86b0962..4d7a51ff2cc6bdd70c6078d3b7d2861e294fcfc8 100644 (file)
       buttons), &quot;menu&quot; (for objects which have context menus invokable from 
       mouse or keyboard), &quot;open&quot; for icons representing files folders, and others.</p>
   </tp:docstring>
-  <tp:property name="nActions" type="i" access="read">
-  <tp:docstring xmlns="http://www.w3.org/1999/xhtml">
-    <p>nActions: a \c long containing the number of actions this object supports.  </p>
-  </tp:docstring>
-  </tp:property>
-  <method name="getDescription">
-    <tp:docstring>
-      getDescription:
-    </tp:docstring>
-    <arg direction="in" name="index" type="i">
-    <tp:docstring>
-      the index of the action for which a description is desired.Get the description of the specified action.  The description of an actionmay provide information about the result of action invocation, unlike theaction name.@see getName.
-    </tp:docstring>
-    </arg>
-    <arg direction="out" type="s">
-    <tp:docstring>
+  <tp:struct name="Action">
+    <tp:member type="s" tp:name="name">
+      <tp:docstring>
       a \c string containing the description of the specified action.
+      </tp:docstring>
+    </tp:member>
+    <tp:member type="s" tp:name="description">
+      <tp:docstring>
+       the description of the specified action.  The description of an actionmay provide information about the result of action invocation, unlike the action name.
     </tp:docstring>
-    </arg>
-  </method>
-  <method name="getName">
-    <tp:docstring>
-      getName:
-    </tp:docstring>
-    <arg direction="in" name="index" type="i">
-    <tp:docstring>
-      the index of the action whose name is requested.Get the name of the specified action.  Action names generally describethe user action, i.e. &quot;click&quot; or &quot;press&quot;, rather then the result of invoking the action.
-    </tp:docstring>
-    </arg>
-    <arg direction="out" type="s">
+  </tp:member>
+    <tp:member type="s" tp:name="keyBinding">
+      <tp:docstring>
+        a \c string containing the key binding for the specified action,or an empty string (&quot;&quot;) if none exists.
+      </tp:docstring>
+    </tp:member>
+  </tp:struct>
+
+  <method name="getActions">
     <tp:docstring>
-      a \c string containing the name of the specified action.
+      Retrieves the actions associated with the object.
     </tp:docstring>
-    </arg>
+    <arg direction="out" name="index" type="a(sss)" tp:type="Action"/>
   </method>
   <method name="doAction">
     <tp:docstring>
-      doAction:
+      Causes the object to perform the specified action.
     </tp:docstring>
     <arg direction="in" name="index" type="i">
     <tp:docstring>
-      the 0-based index of the action to perform.Causes the object to perform the specified action.
+      the 0-based index of the action to perform.
     </tp:docstring>
     </arg>
     <arg direction="out" type="b" tp:type="boolean">
     </tp:docstring>
     </arg>
   </method>
-  <method name="getKeyBinding">
-    <tp:docstring>
-      getKeyBinding:
-    </tp:docstring>
-    <arg direction="in" name="index" type="i">
-    <tp:docstring>
-      the 0-based index of the action for which a key binding is requested.Get the key binding associated with a specific action.
-    </tp:docstring>
-    </arg>
-    <arg direction="out" type="s">
-    <tp:docstring>
-      a \c string containing the key binding for the specified action,or an empty string (&quot;&quot;) if none exists.
-    </tp:docstring>
-    </arg>
-  </method>
-  <method name="unImplemented">
-    <tp:docstring xmlns="http://www.w3.org/1999/xhtml">
-      <p>\cond
-        unImplemented:    </p>
-
-      <p>placeholders for future expansion.</p>
-    </tp:docstring>
-  </method>
-  <method name="unImplemented2">
-  </method>
-  <method name="unImplemented3">
-  </method>
-  <method name="unImplemented4">
-  </method>
 </interface>
 </node>