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)
149 if ((ref = g_hash_table_lookup (get_live_refs (), corba_object)))
151 g_assert (ref->ref_count > 0);
153 bonobo_object_release_unref (corba_object, NULL);
155 g_print ("returning cached %p => %p\n", ref, ref->objref);
160 ref = g_new (Accessible, 1);
163 g_print ("allocating %p => %p\n", ref, corba_object);
166 ref->objref = corba_object;
169 g_hash_table_insert (get_live_refs (), ref->objref, ref);
177 cspi_object_add_check (CORBA_Object corba_object)
181 if (ev._major == CORBA_USER_EXCEPTION &&
182 !strcmp (ev._id, ex_Accessibility_ChildGone))
186 else if (ev._major != CORBA_NO_EXCEPTION)
188 cspi_check_ev (cspi_ev (), "pre method check");
193 retval = cspi_object_add (corba_object);
195 cspi_check_ev (cspi_ev (), "post method check");
202 cspi_object_ref (Accessible *accessible)
204 g_return_if_fail (accessible != NULL);
206 accessible->ref_count++;
210 cspi_object_unref (Accessible *accessible)
212 if (accessible == NULL)
217 if (--accessible->ref_count == 0)
219 g_hash_table_remove (get_live_refs (), accessible->objref);
232 g_hash_table_destroy (refs);
235 if (registry != CORBA_OBJECT_NIL)
237 bonobo_object_release_unref (registry, NULL);
238 registry = CORBA_OBJECT_NIL;
242 static gboolean SPI_inited = FALSE;
247 * Connects to the accessibility registry and initializes the SPI.
249 * Returns: 0 on success, otherwise an integer error code.
264 CORBA_exception_init (&ev);
266 if (!bonobo_init (&argc, NULL))
268 g_error ("Could not initialize Bonobo");
271 obj_id = "OAFIID:Accessibility_Registry:proto0.1";
273 registry = bonobo_activation_activate_from_id (
274 obj_id, 0, NULL, cspi_ev ());
276 if (ev._major != CORBA_NO_EXCEPTION)
278 g_error ("AT-SPI error: during registry activation: %s\n",
279 bonobo_exception_get_text (cspi_ev ()));
282 if (registry == CORBA_OBJECT_NIL)
284 g_error ("Could not locate registry");
289 g_atexit (cspi_cleanup);
297 * Starts/enters the main event loop for the SPI services.
299 * (NOTE: This method does not return control, it is exited via a call to
300 * SPI_event_quit () from within an event handler).
304 SPI_event_main (void)
312 * Quits the last main event loop for the SPI services,
316 SPI_event_quit (void)
324 * Checks to see if an SPI event is waiting in the event queue.
325 * Used by clients that don't wish to use SPI_event_main().
327 * Not Yet Implemented.
329 * Returns: #TRUE if an event is waiting, otherwise #FALSE.
340 * @waitForEvent: a #SPIBoolean indicating whether to block or not.
342 * Gets the next event in the SPI event queue; blocks if no event
343 * is pending and @waitForEvent is #TRUE.
344 * Used by clients that don't wish to use SPI_event_main().
346 * Not Yet Implemented.
348 * Returns: the next #AccessibleEvent in the SPI event queue.
351 SPI_nextEvent (SPIBoolean waitForEvent)
359 * Disconnects from the Accessibility Registry and releases
360 * any floating resources. Call only once at exit.
362 * Returns: 0 if there were no leaks, otherwise non zero.
378 leaked = g_hash_table_size (live_refs);
388 fprintf (stderr, "Leaked %d SPI handles\n", leaked);
394 fprintf (stderr, "bye-bye!\n");