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 bonobo_object_release_unref (a->objref, NULL);
50 memset (a, 0xaa, sizeof (Accessible));
60 cspi_accessible_is_a (Accessible *obj,
61 const char *interface_name)
64 Bonobo_Unknown unknown;
71 unknown = Bonobo_Unknown_queryInterface (CSPI_OBJREF (obj),
72 interface_name, cspi_ev ());
74 if (BONOBO_EX (cspi_ev ()))
76 g_error ("Exception '%s' checking if is '%s'",
77 bonobo_exception_get_text (cspi_ev ()),
81 if (unknown != CORBA_OBJECT_NIL)
84 bonobo_object_release_unref (unknown, NULL);
99 live_refs = g_hash_table_new_full (spi_object_hash,
110 /* This method is an ugly hack */
114 Accessibility_Registry
121 cspi_exception (void)
127 CORBA_exception_free (&ev);
139 cspi_object_add (CORBA_Object corba_object)
143 if (corba_object == CORBA_OBJECT_NIL)
147 else if (!cspi_check_ev ("pre method check"))
153 if ((ref = g_hash_table_lookup (get_live_refs (), corba_object)))
155 g_assert (ref->ref_count > 0);
157 bonobo_object_release_unref (corba_object, NULL);
159 g_print ("returning cached %p => %p\n", ref, ref->objref);
164 ref = g_new (Accessible, 1);
167 g_print ("allocating %p => %p\n", ref, corba_object);
170 ref->objref = corba_object;
173 g_hash_table_insert (get_live_refs (), ref->objref, ref);
181 cspi_object_ref (Accessible *accessible)
183 g_return_if_fail (accessible != NULL);
185 accessible->ref_count++;
189 cspi_object_unref (Accessible *accessible)
191 if (accessible == NULL)
196 if (--accessible->ref_count == 0)
198 g_hash_table_remove (get_live_refs (), accessible->objref);
211 g_hash_table_destroy (refs);
214 if (registry != CORBA_OBJECT_NIL)
216 bonobo_object_release_unref (registry, NULL);
217 registry = CORBA_OBJECT_NIL;
221 static gboolean SPI_inited = FALSE;
226 * Connects to the accessibility registry and initializes the SPI.
228 * Returns: 0 on success, otherwise an integer error code.
243 CORBA_exception_init (&ev);
245 if (!bonobo_init (&argc, NULL))
247 g_error ("Could not initialize Bonobo");
250 obj_id = "OAFIID:Accessibility_Registry:proto0.1";
252 registry = bonobo_activation_activate_from_id (
253 obj_id, 0, NULL, cspi_ev ());
255 if (ev._major != CORBA_NO_EXCEPTION)
257 g_error ("AT-SPI error: during registry activation: %s\n",
258 bonobo_exception_get_text (cspi_ev ()));
261 if (registry == CORBA_OBJECT_NIL)
263 g_error ("Could not locate registry");
268 g_atexit (cspi_cleanup);
276 * Starts/enters the main event loop for the SPI services.
278 * (NOTE: This method does not return control, it is exited via a call to
279 * SPI_event_quit () from within an event handler).
283 SPI_event_main (void)
291 * Quits the last main event loop for the SPI services,
295 SPI_event_quit (void)
303 * Checks to see if an SPI event is waiting in the event queue.
304 * Used by clients that don't wish to use SPI_event_main().
306 * Not Yet Implemented.
308 * Returns: #TRUE if an event is waiting, otherwise #FALSE.
319 * @waitForEvent: a #SPIBoolean indicating whether to block or not.
321 * Gets the next event in the SPI event queue; blocks if no event
322 * is pending and @waitForEvent is #TRUE.
323 * Used by clients that don't wish to use SPI_event_main().
325 * Not Yet Implemented.
327 * Returns: the next #AccessibleEvent in the SPI event queue.
330 SPI_nextEvent (SPIBoolean waitForEvent)
338 * Disconnects from the Accessibility Registry and releases
339 * any floating resources. Call only once at exit.
341 * Returns: 0 if there were no leaks, otherwise non zero.
357 leaked = g_hash_table_size (live_refs);
367 fprintf (stderr, "Leaked %d SPI handles\n", leaked);
373 fprintf (stderr, "bye-bye!\n");