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 SPIBoolean is_gnome_app = TRUE;
15 static GHashTable *live_refs = NULL;
18 spi_object_hash (gconstpointer key)
20 CORBA_Object object = (CORBA_Object) key;
23 retval = CORBA_Object_hash (object, 0, &ev);
29 spi_object_equal (gconstpointer a, gconstpointer b)
31 CORBA_Object objecta = (CORBA_Object) a;
32 CORBA_Object objectb = (CORBA_Object) b;
35 retval = CORBA_Object_is_equivalent (objecta, objectb, &ev);
41 spi_object_release (gpointer value)
43 Accessible *a = (Accessible *) value;
46 g_print ("releasing %p => %p\n", a, a->objref);
49 bonobo_object_release_unref (a->objref, NULL);
51 memset (a, 0xaa, sizeof (Accessible));
61 cspi_accessible_is_a (Accessible *obj,
62 const char *interface_name)
65 Bonobo_Unknown unknown;
72 unknown = Bonobo_Unknown_queryInterface (CSPI_OBJREF (obj),
73 interface_name, cspi_ev ());
75 if (BONOBO_EX (cspi_ev ()))
77 g_error ("Exception '%s' checking if is '%s'",
78 bonobo_exception_get_text (cspi_ev ()),
82 if (unknown != CORBA_OBJECT_NIL)
85 bonobo_object_release_unref (unknown, NULL);
100 live_refs = g_hash_table_new_full (spi_object_hash,
111 /* This method is an ugly hack */
115 Accessibility_Registry
122 cspi_is_gnome_app (void)
128 cspi_exception (void)
134 CORBA_exception_free (&ev);
146 cspi_object_add (CORBA_Object corba_object)
150 if (corba_object == CORBA_OBJECT_NIL)
156 if ((ref = g_hash_table_lookup (get_live_refs (), corba_object)))
158 g_assert (ref->ref_count > 0);
160 bonobo_object_release_unref (corba_object, NULL);
162 g_print ("returning cached %p => %p\n", ref, ref->objref);
167 ref = g_new (Accessible, 1);
170 g_print ("allocating %p => %p\n", ref, corba_object);
173 ref->objref = corba_object;
176 g_hash_table_insert (get_live_refs (), ref->objref, ref);
184 cspi_object_add_check (CORBA_Object corba_object)
188 if (ev._major == CORBA_USER_EXCEPTION &&
189 !strcmp (ev._id, ex_Accessibility_ChildGone))
193 else if (ev._major != CORBA_NO_EXCEPTION)
195 cspi_check_ev (cspi_ev (), "pre method check");
200 retval = cspi_object_add (corba_object);
202 cspi_check_ev (cspi_ev (), "post method check");
209 cspi_object_ref (Accessible *accessible)
211 g_return_if_fail (accessible != NULL);
213 accessible->ref_count++;
217 cspi_object_unref (Accessible *accessible)
219 if (accessible == NULL)
224 if (--accessible->ref_count == 0)
226 g_hash_table_remove (get_live_refs (), accessible->objref);
239 g_hash_table_destroy (refs);
242 if (registry != CORBA_OBJECT_NIL)
244 bonobo_object_release_unref (registry, NULL);
245 registry = CORBA_OBJECT_NIL;
249 static gboolean SPI_inited = FALSE;
253 * @isGNOMEApp: a #SPIBoolean indicating whether the client of the SPI
254 * will use the Gnome event loop or not. Clients that have
255 * their own GUIS will usually specify #TRUE here, and must
256 * do so if they use Gnome GUI components.
258 * Connects to the accessibility registry and initializes the SPI.
260 * Returns: 0 on success, otherwise an integer error code.
263 SPI_init (SPIBoolean isGNOMEApp)
267 is_gnome_app = isGNOMEApp;
276 CORBA_exception_init (&ev);
278 if (!bonobo_init (&argc, NULL))
280 g_error ("Could not initialize Bonobo");
283 obj_id = "OAFIID:Accessibility_Registry:proto0.1";
285 registry = bonobo_activation_activate_from_id (
286 obj_id, 0, NULL, cspi_ev ());
288 if (ev._major != CORBA_NO_EXCEPTION)
290 g_error ("AT-SPI error: during registry activation: %s\n",
291 bonobo_exception_get_text (cspi_ev ()));
294 if (registry == CORBA_OBJECT_NIL)
296 g_error ("Could not locate registry");
303 g_atexit (cspi_cleanup);
312 * Starts/enters the main event loop for the SPI services.
314 * (NOTE: This method does not return control, it is exited via a call
315 * to SPI_exit() from within an event handler).
321 if (cspi_is_gnome_app ())
327 /* TODO: install signal handlers to do cleanup */
328 CORBA_ORB_run (bonobo_orb (), cspi_ev ());
329 fprintf (stderr, "orb loop exited...\n");
336 * Checks to see if an SPI event is waiting in the event queue.
337 * Used by clients that don't wish to use SPI_event_main().
339 * Not Yet Implemented.
341 * Returns: #TRUE if an event is waiting, otherwise #FALSE.
352 * @waitForEvent: a #SPIBoolean indicating whether to block or not.
354 * Gets the next event in the SPI event queue; blocks if no event
355 * is pending and @waitForEvent is #TRUE.
356 * Used by clients that don't wish to use SPI_event_main().
358 * Not Yet Implemented.
360 * Returns: the next #AccessibleEvent in the SPI event queue.
363 SPI_nextEvent (SPIBoolean waitForEvent)
371 * Disconnects from the Accessibility Registry and releases
372 * any floating resources.
386 if (cspi_is_gnome_app ())
392 CORBA_ORB_shutdown (bonobo_orb (), TRUE, cspi_ev ());
394 fprintf (stderr, "bye-bye!\n");