* Basic SPI initialization and event loop function prototypes
*
*/
+#include <string.h>
#include <stdlib.h>
-#include <libbonobo.h>
#include <cspi/spi-private.h>
static CORBA_Environment ev = { 0 };
-static AccessibilityRegistry registry = CORBA_OBJECT_NIL;
+static Accessibility_Registry registry = CORBA_OBJECT_NIL;
+static boolean is_gnome_app = FALSE;
+static GSList *live_refs = NULL;
CORBA_Environment *
-spi_ev (void)
+cspi_ev (void)
{
/* This method is an ugly hack */
return &ev;
}
-AccessibilityRegistry
-spi_registry (void)
+Accessibility_Registry
+cspi_registry (void)
{
- /* This method is an ugly hack */
return registry;
}
boolean
-spi_exception (void)
+cspi_is_gnome_app (void)
+{
+ return is_gnome_app;
+}
+
+boolean
+cspi_exception (void)
{
boolean retval;
}
Accessible *
-spi_object_add (Accessible corba_object)
+cspi_object_add (CORBA_Object corba_object)
{
- /* TODO: keep list of live object refs */
- Accessible *oref = NULL;
+ Accessible *ref;
if (corba_object != CORBA_OBJECT_NIL)
{
- oref = g_malloc (sizeof (Accessible));
- *oref = corba_object;
+ ref = g_new (Accessible, 1);
+
+ 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;
+}
+
+void
+cspi_object_ref (Accessible *accessible)
+{
+ g_return_if_fail (accessible != NULL);
+
+ accessible->ref_count++;
+}
+
+void
+cspi_object_unref (Accessible *accessible)
+{
+ g_return_if_fail (accessible != NULL);
+
+ if (--accessible->ref_count == 0)
+ {
+ live_refs = g_slist_remove (live_refs, accessible);
+
+ bonobo_object_release_unref (accessible->objref, cspi_ev ());
+
+ cspi_check_ev (cspi_ev (), "unref");
+
+ memset (accessible, 0xaa, sizeof (Accessible));
+
+ g_free (accessible);
+ }
+}
+
+static void
+cspi_cleanup (void)
+{
+ GSList *l, *refs;
+
+ refs = live_refs;
+ live_refs = NULL;
+
+ for (l = refs; l; l = l->next)
+ {
+ Accessible *a = l->data;
+
+ g_print ("releasing %p\n", l->data);
+ bonobo_object_release_unref (a->objref, NULL);
+
+ g_free (a);
+ }
+
+ g_slist_free (refs);
+
+ if (registry != CORBA_OBJECT_NIL)
+ {
+ bonobo_object_release_unref (registry, NULL);
+ registry = CORBA_OBJECT_NIL;
}
-
- return oref;
}
/**
{
int argc = 0;
char *obj_id;
- CORBA_Object oclient;
static gboolean inited = FALSE;
if (inited)
obj_id = "OAFIID:Accessibility_Registry:proto0.1";
- oclient = bonobo_activation_activate_from_id (
- obj_id, 0, NULL, spi_ev ());
+ registry = bonobo_activation_activate_from_id (
+ obj_id, 0, NULL, cspi_ev ());
if (ev._major != CORBA_NO_EXCEPTION)
{
g_error ("AT-SPI error: during registry activation: %s\n",
- bonobo_exception_get_text (spi_ev ()));
+ bonobo_exception_get_text (cspi_ev ()));
}
- if (CORBA_Object_is_nil (oclient, spi_ev ()))
+ if (registry == CORBA_OBJECT_NIL)
{
g_error ("Could not locate registry");
}
- registry = (Accessibility_Registry) oclient;
-
+ Accessibility_Registry_ref (registry, &ev);
+
bonobo_activate ();
-
+
return 0;
}
*
* Starts/enters the main event loop for the SPI services.
*
- * (NOTE: This method does not return control, it is exited via a call to exit()
+ * (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)
{
+ is_gnome_app = isGNOMEApp;
if (isGNOMEApp)
{
- g_atexit (SPI_exit);
+ g_atexit (cspi_cleanup);
bonobo_main ();
}
else
{
/* TODO: install signal handlers to do cleanup */
- CORBA_ORB_run (bonobo_orb(), spi_ev ());
+ CORBA_ORB_run (bonobo_orb (), cspi_ev ());
fprintf (stderr, "orb loop exited...\n");
}
}
* Not Yet Implemented.
*
* Returns: the next #AccessibleEvent in the SPI event queue.
- *
**/
AccessibleEvent *
SPI_nextEvent (boolean waitForEvent)
/**
* SPI_exit:
*
- * Disconnects from the Accessibility Registry and releases resources.
- *
+ * Disconnects from the Accessibility Registry and releases
+ * any floating resources.
**/
void
SPI_exit (void)
{
- fprintf (stderr, "bye-bye!\n");
- exit(0);
+ cspi_cleanup();
+ if (cspi_is_gnome_app ())
+ {
+ bonobo_main_quit ();
+ }
+ else
+ {
+ CORBA_ORB_shutdown (bonobo_orb (), TRUE, cspi_ev ());
+ }
+ fprintf (stderr, "bye-bye!\n");
}