3 * Basic SPI initialization and event loop function prototypes
8 #include <cspi/spi-private.h>
10 static CORBA_Environment ev = { 0 };
11 static Accessibility_Registry registry = CORBA_OBJECT_NIL;
12 static SPIBoolean is_gnome_app = FALSE;
13 static GSList *live_refs = NULL;
18 /* This method is an ugly hack */
22 Accessibility_Registry
29 cspi_is_gnome_app (void)
41 CORBA_exception_free (&ev);
53 cspi_object_add (CORBA_Object corba_object)
57 if (corba_object != CORBA_OBJECT_NIL)
59 ref = g_new (Accessible, 1);
61 ref->objref = CORBA_Object_duplicate (corba_object, cspi_ev());
64 live_refs = g_slist_prepend (live_refs, ref);
75 cspi_object_ref (Accessible *accessible)
77 g_return_if_fail (accessible != NULL);
79 accessible->ref_count++;
83 cspi_object_unref (Accessible *accessible)
85 g_return_if_fail (accessible != NULL);
87 if (--accessible->ref_count == 0)
89 live_refs = g_slist_remove (live_refs, accessible);
91 bonobo_object_release_unref (accessible->objref, cspi_ev ());
93 cspi_check_ev (cspi_ev (), "unref");
95 memset (accessible, 0xaa, sizeof (Accessible));
109 for (l = refs; l; l = l->next)
111 Accessible *a = l->data;
113 g_print ("releasing %p\n", l->data);
114 bonobo_object_release_unref (a->objref, NULL);
121 if (registry != CORBA_OBJECT_NIL)
123 bonobo_object_release_unref (registry, NULL);
124 registry = CORBA_OBJECT_NIL;
131 * Connects to the accessibility registry and initializes the SPI.
133 * Returns: 0 on success, otherwise an integer error code.
140 static gboolean inited = FALSE;
149 CORBA_exception_init (&ev);
151 if (!bonobo_init (&argc, NULL))
153 g_error ("Could not initialize Bonobo");
156 obj_id = "OAFIID:Accessibility_Registry:proto0.1";
158 registry = bonobo_activation_activate_from_id (
159 obj_id, 0, NULL, cspi_ev ());
161 if (ev._major != CORBA_NO_EXCEPTION)
163 g_error ("AT-SPI error: during registry activation: %s\n",
164 bonobo_exception_get_text (cspi_ev ()));
167 if (registry == CORBA_OBJECT_NIL)
169 g_error ("Could not locate registry");
172 Accessibility_Registry_ref (registry, &ev);
181 * @isGNOMEApp: a #SPIBoolean indicating whether the client of the SPI
182 * will use the Gnome event loop or not. Clients that have
183 * their own GUIS will usually specify #TRUE here, and must
184 * do so if they use Gnome GUI components.
186 * Starts/enters the main event loop for the SPI services.
188 * (NOTE: This method does not return control, it is exited via a call to SPI_exit()
189 * from within an event handler).
193 SPI_event_main (SPIBoolean isGNOMEApp)
195 is_gnome_app = isGNOMEApp;
198 g_atexit (cspi_cleanup);
203 /* TODO: install signal handlers to do cleanup */
204 CORBA_ORB_run (bonobo_orb (), cspi_ev ());
205 fprintf (stderr, "orb loop exited...\n");
212 * Checks to see if an SPI event is waiting in the event queue.
213 * Used by clients that don't wish to use SPI_event_main().
215 * Not Yet Implemented.
217 * Returns: #TRUE if an event is waiting, otherwise #FALSE.
228 * @waitForEvent: a #SPIBoolean indicating whether to block or not.
230 * Gets the next event in the SPI event queue; blocks if no event
231 * is pending and @waitForEvent is #TRUE.
232 * Used by clients that don't wish to use SPI_event_main().
234 * Not Yet Implemented.
236 * Returns: the next #AccessibleEvent in the SPI event queue.
239 SPI_nextEvent (SPIBoolean waitForEvent)
247 * Disconnects from the Accessibility Registry and releases
248 * any floating resources.
254 if (cspi_is_gnome_app ())
260 CORBA_ORB_shutdown (bonobo_orb (), TRUE, cspi_ev ());
262 fprintf (stderr, "bye-bye!\n");