-#include <libbonobo.h>
-#include <stdio.h>
-#include "spi.h"
-
-static CORBA_Environment ev;
-static AccessibilityRegistry registry;
-
-Accessible *
-Obj_Add (Accessible object)
-{
- /* TODO: keep list of live object refs */
- Accessible *oref = g_malloc (sizeof (Accessible));
- *oref = object;
- return oref;
-}
-
/*
*
* Basic SPI initialization and event loop function prototypes
*
*/
+#include <string.h>
+#include <stdlib.h>
+#include <cspi/spi-private.h>
-int
-SPI_init (void)
-{
- int argc = 0;
- CORBA_Object oclient;
- char *obj_id;
-
- CORBA_exception_init(&ev);
-
- if (!bonobo_init (&argc, NULL))
- {
- g_error ("Could not initialize Bonobo");
- }
-
- obj_id = "OAFIID:Accessibility_Registry:proto0.1";
-
- oclient = bonobo_activation_activate_from_id (obj_id, 0, NULL, &ev);
- if (ev._major != CORBA_NO_EXCEPTION) {
- fprintf (stderr,
- ("AT-SPI error: during registry activation: %s\n"),
- CORBA_exception_id(&ev));
- CORBA_exception_free(&ev);
- exit(-1);
- }
-
- if (CORBA_Object_is_nil (oclient, &ev))
- {
- g_error ("Could not locate registry");
- exit(-1);
- }
-
- registry = (Accessibility_Registry) oclient;
-
- bonobo_activate ();
-
- return 0;
-}
-
-void
-SPI_event_main (boolean isGNOMEApp)
-{
- if (isGNOMEApp) bonobo_main();
- else CORBA_ORB_run (bonobo_orb(), &ev);
-}
-
-/* Not Yet Implemented */
-boolean
-SPI_eventIsReady ()
-{
- return FALSE;
-}
-
-/* Not Yet Implemented */
-AccessibleEvent *
-SPI_nextEvent (boolean waitForEvent)
-{
- return NULL;
-}
-
-void
-SPI_exit (void)
-{
- exit(0);
-}
+static CORBA_Environment ev = { 0 };
+static Accessibility_Registry registry = CORBA_OBJECT_NIL;
+static boolean is_gnome_app = FALSE;
+static GSList *live_refs = NULL;
-AccessibleEventListener *
-CreateEventListener (AccessibleEventListenerCB callback)
+CORBA_Environment *
+cspi_ev (void)
{
- AccessibleEventListener *listener = accessible_event_listener_new ();
- if (callback)
- {
- accessible_event_listener_add_callback (listener, callback);
- }
- return listener;
+ /* This method is an ugly hack */
+ return &ev;
}
-boolean
-EventListener_addCallback (AccessibleEventListener *listener,
- AccessibleEventListenerCB callback)
+Accessibility_Registry
+cspi_registry (void)
{
- accessible_event_listener_add_callback (listener, callback);
- return TRUE;
+ return registry;
}
boolean
-EventListener_removeCallback (AccessibleEventListener *listener,
- AccessibleEventListenerCB callback)
+cspi_is_gnome_app (void)
{
- accessible_event_listener_remove_callback (listener, callback);
- return TRUE;
+ return is_gnome_app;
}
-/*
- *
- * Global functions serviced by the registry
- *
- */
-
boolean
-RegisterGlobalEventListener (AccessibleEventListener *listener,
- char *eventType)
+cspi_exception (void)
{
- Accessibility_Registry_registerGlobalEventListener (
- registry,
- (Accessibility_EventListener)
- bonobo_object_corba_objref (bonobo_object (listener)),
- eventType,
- &ev);
+ boolean retval;
- if (ev._major != CORBA_NO_EXCEPTION)
+ if (BONOBO_EX (&ev))
{
- return FALSE;
+ CORBA_exception_free (&ev);
+ retval = TRUE;
}
else
{
- return TRUE;
+ retval = FALSE;
}
-}
-int
-GetDesktopCount ()
-{
- return Accessibility_Registry_getDesktopCount (registry, &ev);
+ return retval;
}
-Accessible
-*getDesktop (int n)
+Accessible *
+cspi_object_add (CORBA_Object corba_object)
{
- return Obj_Add (Accessibility_Registry_getDesktop (registry, (CORBA_short) n, &ev));
-}
+ Accessible *ref;
-int
-getDesktopList (Accessible **list)
-{
- *list = NULL;
- return 0;
-}
+ if (corba_object != CORBA_OBJECT_NIL)
+ {
+ ref = g_new (Accessible, 1);
-/* Not Yet Implemented */
-void
-registerKeystrokeListener (KeystrokeListener *listener)
-{
- ;
+ ref->objref = CORBA_Object_duplicate (corba_object, cspi_ev());
+ ref->ref_count = 1;
+
+ live_refs = g_slist_prepend (live_refs, ref);
+ }
+ else
+ {
+ ref = NULL;
+ }
+
+ return ref;
}
-/* Not Yet Implemented */
void
-generateKeyEvent (long keyCode, long meta)
+cspi_object_ref (Accessible *accessible)
{
- ;
+ g_return_if_fail (accessible != NULL);
+
+ accessible->ref_count++;
}
-/* Not Yet Implemented */
void
-generateMouseEvent (long x, long y, char *name)
+cspi_object_unref (Accessible *accessible)
{
- ;
-}
+ g_return_if_fail (accessible != NULL);
+
+ if (--accessible->ref_count == 0)
+ {
+ live_refs = g_slist_remove (live_refs, accessible);
-/*
- *
- * Accessible function prototypes
- *
- */
+ bonobo_object_release_unref (accessible->objref, cspi_ev ());
-int
-Accessible_ref (Accessible *obj)
-{
- Accessibility_Accessible_ref (*obj, &ev);
- return 0;
-}
+ cspi_check_ev (cspi_ev (), "unref");
+ memset (accessible, 0xaa, sizeof (Accessible));
-int
-Accessible_unref (Accessible *obj)
-{
- Accessibility_Accessible_unref (*obj, &ev);
- return 0;
+ g_free (accessible);
+ }
}
-char *
-Accessible_getName (Accessible *obj)
+static void
+cspi_cleanup (void)
{
- return Accessibility_Accessible__get_name (*obj, &ev);
-}
+ GSList *l, *refs;
-char *
-Accessible_getDescription (Accessible *obj)
-{
- return Accessibility_Accessible__get_description (*obj, &ev);
-}
+ refs = live_refs;
+ live_refs = NULL;
-Accessible *
-Accessible_getParent (Accessible *obj)
-{
- return Obj_Add (Accessibility_Accessible__get_parent (*obj, &ev));
-}
+ for (l = refs; l; l = l->next)
+ {
+ Accessible *a = l->data;
-long
-Accessible_getChildCount (Accessible *obj)
-{
- return Accessibility_Accessible__get_childCount (*obj, &ev);
-}
+ g_print ("releasing %p\n", l->data);
+ bonobo_object_release_unref (a->objref, NULL);
-Accessible *
-Accessible_getChildAtIndex (Accessible *obj,
- long childIndex)
-{
- return Obj_Add (Accessibility_Accessible_getChildAtIndex (*obj, childIndex, &ev));
-}
+ g_free (a);
+ }
-long
-Accessible_getIndexInParent (Accessible *obj)
-{
- return Accessibility_Accessible_getIndexInParent (*obj, &ev);
-}
+ g_slist_free (refs);
-/* Not Yet Implemented */
-AccessibleRelation **
-Accessible_getRelationSet (Accessible *obj)
-{
- return NULL;
+ if (registry != CORBA_OBJECT_NIL)
+ {
+ bonobo_object_release_unref (registry, NULL);
+ registry = CORBA_OBJECT_NIL;
+ }
}
-/* Not Yet Implemented */
-char *
-Accessible_getRole (Accessible *obj)
+/**
+ * SPI_init:
+ *
+ * Connects to the accessibility registry and initializes the SPI.
+ *
+ * Returns: 0 on success, otherwise an integer error code.
+ **/
+int
+SPI_init (void)
{
- return "";
-}
+ int argc = 0;
+ char *obj_id;
+ static gboolean inited = FALSE;
-/* Not Yet Implemented */
-AccessibleStateSet *
-Accessible_getStateSet (Accessible *obj)
-{
- return NULL;
-}
+ if (inited)
+ {
+ return 1;
+ }
+ inited = TRUE;
-/*
- *
- * AccessibleApplication function prototypes
- *
- */
+ CORBA_exception_init (&ev);
-int
-AccessibleApplication_ref (AccessibleApplication *obj)
-{
- Accessibility_Application_ref (*obj, &ev);
- return 0;
-}
+ if (!bonobo_init (&argc, NULL))
+ {
+ g_error ("Could not initialize Bonobo");
+ }
-int
-AccessibleApplication_unref (AccessibleApplication *obj)
-{
- Accessibility_Application_unref (*obj, &ev);
- return 0;
-}
+ obj_id = "OAFIID:Accessibility_Registry:proto0.1";
-char *
-AccessibleApplication_getToolkitName (AccessibleApplication *obj)
-{
- return Accessibility_Application__get_toolkitName (*obj, &ev);
-}
+ registry = bonobo_activation_activate_from_id (
+ obj_id, 0, NULL, cspi_ev ());
-char *
-AccessibleApplication_getVersion (AccessibleApplication *obj)
-{
- return Accessibility_Application__get_version (*obj, &ev);
+ if (ev._major != CORBA_NO_EXCEPTION)
+ {
+ g_error ("AT-SPI error: during registry activation: %s\n",
+ bonobo_exception_get_text (cspi_ev ()));
+ }
+
+ if (registry == CORBA_OBJECT_NIL)
+ {
+ g_error ("Could not locate registry");
+ }
+
+ Accessibility_Registry_ref (registry, &ev);
+
+ bonobo_activate ();
+
+ return 0;
}
-long
-AccessibleApplication_getID (AccessibleApplication *obj)
+/**
+ * SPI_event_main:
+ * @isGNOMEApp: a #boolean indicating whether the client of the SPI
+ * will use the Gnome event loop or not. Clients that have
+ * their own GUIS will usually specify #TRUE here, and must
+ * do so if they use Gnome GUI components.
+ *
+ * Starts/enters the main event loop for the SPI services.
+ *
+ * (NOTE: This method does not return control, it is exited via a call to SPI_exit()
+ * from within an event handler).
+ *
+ **/
+void
+SPI_event_main (boolean isGNOMEApp)
{
- return Accessibility_Application__get_id (*obj, &ev);
+ is_gnome_app = isGNOMEApp;
+ if (isGNOMEApp)
+ {
+ g_atexit (cspi_cleanup);
+ bonobo_main ();
+ }
+ else
+ {
+ /* TODO: install signal handlers to do cleanup */
+ CORBA_ORB_run (bonobo_orb (), cspi_ev ());
+ fprintf (stderr, "orb loop exited...\n");
+ }
}
-/* Not Yet Implemented */
+/**
+ * SPI_eventIsReady:
+ *
+ * Checks to see if an SPI event is waiting in the event queue.
+ * Used by clients that don't wish to use SPI_event_main().
+ *
+ * Not Yet Implemented.
+ *
+ * Returns: #TRUE if an event is waiting, otherwise #FALSE.
+ *
+ **/
boolean
-AccessibleApplication_pause (AccessibleApplication *obj)
+SPI_eventIsReady ()
{
return FALSE;
}
-/* Not Yet Implemented */
-boolean
-AccessibleApplication_resume (AccessibleApplication *obj)
+/**
+ * SPI_nextEvent:
+ * @waitForEvent: a #boolean indicating whether to block or not.
+ *
+ * Gets the next event in the SPI event queue; blocks if no event
+ * is pending and @waitForEvent is #TRUE.
+ * Used by clients that don't wish to use SPI_event_main().
+ *
+ * Not Yet Implemented.
+ *
+ * Returns: the next #AccessibleEvent in the SPI event queue.
+ **/
+AccessibleEvent *
+SPI_nextEvent (boolean waitForEvent)
{
- return FALSE;
+ return NULL;
+}
+
+/**
+ * SPI_exit:
+ *
+ * Disconnects from the Accessibility Registry and releases
+ * any floating resources.
+ **/
+void
+SPI_exit (void)
+{
+ cspi_cleanup();
+ if (cspi_is_gnome_app ())
+ {
+ bonobo_main_quit ();
+ }
+ else
+ {
+ CORBA_ORB_shutdown (bonobo_orb (), TRUE, cspi_ev ());
+ }
+ fprintf (stderr, "bye-bye!\n");
}