3 * Basic SPI initialization and event loop function prototypes
8 #include <cspi/spi-private.h>
12 static CORBA_Environment ev = { 0 };
13 static Accessibility_Registry registry = CORBA_OBJECT_NIL;
14 static GHashTable *live_refs = NULL;
17 spi_object_hash (gconstpointer key)
19 CORBA_Object object = (CORBA_Object) key;
22 retval = CORBA_Object_hash (object, 0, &ev);
28 spi_object_equal (gconstpointer a, gconstpointer b)
30 CORBA_Object objecta = (CORBA_Object) a;
31 CORBA_Object objectb = (CORBA_Object) b;
34 retval = CORBA_Object_is_equivalent (objecta, objectb, &ev);
40 spi_object_release (gpointer value)
42 Accessible *a = (Accessible *) value;
45 g_print ("releasing %p => %p\n", a, a->objref);
48 cspi_release_unref (a->objref);
50 memset (a, 0xaa, sizeof (Accessible));
59 cspi_accessible_is_a (Accessible *obj,
60 const char *interface_name)
63 Bonobo_Unknown unknown;
70 unknown = Bonobo_Unknown_queryInterface (CSPI_OBJREF (obj),
71 interface_name, cspi_ev ());
73 if (ev._major != CORBA_NO_EXCEPTION)
75 g_error ("Exception '%s' checking if is '%s'",
76 cspi_exception_get_text (),
80 if (unknown != CORBA_OBJECT_NIL)
83 cspi_release_unref (unknown);
98 live_refs = g_hash_table_new_full (spi_object_hash,
109 /* This method is an ugly hack */
113 Accessibility_Registry
120 cspi_exception (void)
124 if (ev._major != CORBA_NO_EXCEPTION)
126 CORBA_exception_free (&ev);
138 cspi_object_add (CORBA_Object corba_object)
142 if (corba_object == CORBA_OBJECT_NIL)
146 else if (!cspi_check_ev ("pre method check"))
152 if ((ref = g_hash_table_lookup (get_live_refs (), corba_object)))
154 g_assert (ref->ref_count > 0);
156 cspi_release_unref (corba_object);
158 g_print ("returning cached %p => %p\n", ref, ref->objref);
163 ref = malloc (sizeof (Accessible));
166 g_print ("allocating %p => %p\n", ref, corba_object);
169 ref->objref = corba_object;
172 g_hash_table_insert (get_live_refs (), ref->objref, ref);
180 cspi_object_ref (Accessible *accessible)
182 g_return_if_fail (accessible != NULL);
184 accessible->ref_count++;
188 cspi_object_unref (Accessible *accessible)
190 if (accessible == NULL)
195 if (--accessible->ref_count == 0)
197 g_hash_table_remove (get_live_refs (), accessible->objref);
210 g_hash_table_destroy (refs);
213 if (registry != CORBA_OBJECT_NIL)
215 cspi_release_unref (registry);
216 registry = CORBA_OBJECT_NIL;
220 static gboolean SPI_inited = FALSE;
225 * Connects to the accessibility registry and initializes the SPI.
227 * Returns: 0 on success, otherwise an integer error code.
239 CORBA_exception_init (&ev);
241 registry = cspi_init ();
243 g_atexit (cspi_cleanup);
251 * Starts/enters the main event loop for the SPI services.
253 * (NOTE: This method does not return control, it is exited via a call to
254 * SPI_event_quit () from within an event handler).
258 SPI_event_main (void)
266 * Quits the last main event loop for the SPI services,
270 SPI_event_quit (void)
278 * Checks to see if an SPI event is waiting in the event queue.
279 * Used by clients that don't wish to use SPI_event_main().
281 * Not Yet Implemented.
283 * Returns: #TRUE if an event is waiting, otherwise #FALSE.
294 * @waitForEvent: a #SPIBoolean indicating whether to block or not.
296 * Gets the next event in the SPI event queue; blocks if no event
297 * is pending and @waitForEvent is #TRUE.
298 * Used by clients that don't wish to use SPI_event_main().
300 * Not Yet Implemented.
302 * Returns: the next #AccessibleEvent in the SPI event queue.
305 SPI_nextEvent (SPIBoolean waitForEvent)
313 * Disconnects from the Accessibility Registry and releases
314 * any floating resources. Call only once at exit.
316 * Returns: 0 if there were no leaks, otherwise non zero.
332 leaked = g_hash_table_size (live_refs);
342 fprintf (stderr, "Leaked %d SPI handles\n", leaked);
348 fprintf (stderr, "bye-bye!\n");
355 * @s: a character string returned from another at-spi call.
357 * Free a character string returned from an at-spi call. Clients of
358 * at-spi should use this function instead of free () or g_free().
359 * This API should not be used to free strings
360 * from other libraries or allocated by the client.
363 SPI_freeString (char *s)