2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001 Sun Microsystems Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 * registry.c: test for accessibility implementation
32 #include <bonobo/Bonobo.h>
35 * This pulls the CORBA definitions for the "Accessibility::Registry" server
37 #include <libspi/Accessibility.h>
40 * This pulls the definition for the BonoboObject (GType)
45 * Our parent GObject type
47 #define PARENT_TYPE LISTENER_TYPE
50 * A pointer to our parent object class
52 static ListenerClass *registry_parent_class;
63 EventTypeCategory type_cat;
71 Accessibility_EventListener listener;
72 guint event_type_hash;
73 EventTypeCategory event_type_cat;
76 /* static function prototypes */
77 static void _registry_notify_listeners ( GList *listeners,
78 const Accessibility_Event *e,
79 CORBA_Environment *ev);
81 static long _get_unique_id();
84 * Implemented GObject::finalize
87 registry_object_finalize (GObject *object)
89 /* Registry *registry = REGISTRY (object); */
90 GObjectClass *object_class = G_OBJECT_GET_CLASS( object);
92 printf("registry_object_finalize called\n");
94 object_class->finalize (object);
98 * registerApplication:
99 * @application: a reference to the requesting @Application
100 * return values: void
102 * Register a new application with the accessibility broker.
106 impl_accessibility_registry_register_application (PortableServer_Servant servant,
107 const Accessibility_Application application,
108 CORBA_Environment * ev)
110 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
113 fprintf (stderr, "registering app %p\n", application);
115 registry->desktop->applications = g_list_append (registry->desktop->applications,
116 CORBA_Object_duplicate (application, ev));
118 /* TODO: create unique string here (with libuuid call ?) and hash ? */
119 Accessibility_Application__set_id (application, _get_unique_id(), ev);
122 * TODO: change the implementation below to a WM-aware one;
123 * e.g. don't add all apps to the Desktop
128 compare_object_hash (gconstpointer p1, gconstpointer p2)
130 CORBA_Environment ev;
131 long long diff = ((CORBA_Object_hash ((CORBA_Object) p2, (CORBA_unsigned_long) 0, &ev)) -
132 (CORBA_Object_hash ((CORBA_Object) p1, (CORBA_unsigned_long) 0, &ev)));
133 return ((diff < 0) ? -1 : ((diff > 0) ? 1 : 0));
137 register_with_toolkits (Registry *registry_bonobo_object, EventTypeStruct *etype, CORBA_Environment *ev)
142 Accessibility_Desktop desktop;
143 Accessibility_Application app;
144 Accessibility_Registry registry;
145 registry = bonobo_object_corba_objref (bonobo_object (registry_bonobo_object));
147 /* for each app in each desktop, call ...Application_registerToolkitEventListener */
149 n_desktops = Accessibility_Registry_getDesktopCount (registry, ev);
151 for (i=0; i<n_desktops; ++i)
153 desktop = Accessibility_Registry_getDesktop (registry, i, ev);
154 n_apps = Accessibility_Desktop__get_childCount (desktop, ev);
155 for (j=0; j<n_apps; ++j)
157 app = (Accessibility_Application) Accessibility_Desktop_getChildAtIndex (desktop,
160 /* TODO: should we be ref-ing the registry object before each call ? */
161 Accessibility_Application_registerToolkitEventListener (app,
163 CORBA_string_dup (etype->event_name),
170 compare_listener_hash (gconstpointer p1, gconstpointer p2)
172 return (((ListenerStruct *)p2)->event_type_hash - ((ListenerStruct *)p1)->event_type_hash);
176 parse_event_type (EventTypeStruct *etype, char *event_name)
179 gchar **split_string;
181 split_string = g_strsplit(event_name, ":", 4);
182 etype->event_name = g_strndup(event_name, 255);
184 if (!g_ascii_strncasecmp (event_name, "focus:", 6))
186 etype->type_cat = ETYPE_FOCUS;
188 else if (!g_ascii_strncasecmp (event_name, "window:", 7))
190 etype->type_cat = ETYPE_WINDOW;
194 etype->type_cat = ETYPE_TOOLKIT;
199 etype->major = split_string[1];
202 etype->minor = split_string[2];
205 etype->detail = split_string[3];
206 etype->hash = g_str_hash ( g_strconcat (split_string[1], split_string[2], split_string[3], NULL));
210 etype->detail = g_strdup ("");
211 etype->hash = g_str_hash ( g_strconcat (split_string[1], split_string[2], NULL));
216 etype->minor = g_strdup ("");
217 etype->hash = g_str_hash ( split_string[1]);
222 etype->major = g_strdup ("");
223 etype->minor = g_strdup ("");
224 etype->detail = g_strdup ("");
225 etype->hash = g_str_hash ("");
228 /* TODO: don't forget to free the strings from caller when done ! */
232 * deregisterApplication:
233 * @application: a reference to the @Application
234 * to be deregistered.
235 * return values: void
237 * De-register an application previously registered with the broker.
241 impl_accessibility_registry_deregister_application (PortableServer_Servant servant,
242 const Accessibility_Application application,
243 CORBA_Environment * ev)
245 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
246 GList *list = g_list_find_custom (registry->applications, application, compare_object_hash);
249 fprintf (stderr, "deregistering application\n");
250 registry->applications = g_list_delete_link (registry->applications, list);
255 * CORBA Accessibility::Registry::registerGlobalEventListener method implementation
258 impl_accessibility_registry_register_global_event_listener
259 (PortableServer_Servant servant,
260 Accessibility_EventListener listener,
261 const CORBA_char *event_name,
262 CORBA_Environment *ev)
264 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
265 ListenerStruct *ls = g_malloc (sizeof (ListenerStruct));
266 EventTypeStruct etype;
268 fprintf(stderr, "registering for events of type %s\n", event_name);
270 /* parse, check major event type and add listener accordingly */
271 parse_event_type (&etype, event_name);
272 ls->event_type_hash = etype.hash;
273 ls->event_type_cat = etype.type_cat;
275 switch (etype.type_cat)
278 ls->listener = CORBA_Object_duplicate (listener, ev);
279 registry->focus_listeners =
280 g_list_append (registry->focus_listeners, ls);
282 case (ETYPE_WINDOW) :
283 /* Support for Window Manager Events is not yet implemented */
285 case (ETYPE_TOOLKIT) :
286 ls->listener = CORBA_Object_duplicate (listener, ev);
287 registry->toolkit_listeners =
288 g_list_append (registry->toolkit_listeners, ls);
289 register_with_toolkits (registry, &etype, ev);
297 * CORBA Accessibility::Registry::deregisterGlobalEventListenerAll method implementation
300 impl_accessibility_registry_deregister_global_event_listener_all
301 (PortableServer_Servant servant,
302 Accessibility_EventListener listener,
303 CORBA_Environment *ev)
305 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
306 GList *list = g_list_find_custom (registry->focus_listeners, listener, compare_object_hash);
309 * TODO : de-register with toolkit if the last instance of a listener
310 * to a particular toolkit event type has been deregistered.
315 fprintf (stderr, "deregistering listener\n");
316 registry->focus_listeners = g_list_delete_link (registry->focus_listeners, list);
317 list = g_list_find_custom (registry->focus_listeners, listener, compare_object_hash);
319 list = g_list_find_custom (registry->toolkit_listeners, listener, compare_object_hash);
322 fprintf (stderr, "deregistering listener\n");
323 registry->toolkit_listeners = g_list_delete_link (registry->toolkit_listeners, list);
324 list = g_list_find_custom (registry->toolkit_listeners, listener, compare_object_hash);
329 * CORBA Accessibility::Registry::deregisterGlobalEventListener method implementation
332 impl_accessibility_registry_deregister_global_event_listener
333 (PortableServer_Servant servant,
334 Accessibility_EventListener listener,
335 const CORBA_char * event_name,
336 CORBA_Environment *ev)
338 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
340 EventTypeStruct etype;
344 parse_event_type (&etype, event_name);
345 switch (etype.type_cat)
348 listeners = ®istry->focus_listeners;
350 case (ETYPE_WINDOW) :
351 /* Support for Window Manager Events is not yet implemented */
353 case (ETYPE_TOOLKIT) :
354 listeners = ®istry->toolkit_listeners;
360 ls.event_type_hash = etype.hash;
361 list = g_list_find_custom (*listeners, &ls, compare_listener_hash);
365 fprintf (stderr, "deregistering listener\n");
366 *listeners = g_list_delete_link (*listeners, list);
367 list = g_list_find_custom (*listeners, &ls, compare_listener_hash);
374 * return values: a short integer indicating the current number of
377 * Get the current number of desktops.
381 impl_accessibility_registry_get_desktop_count (PortableServer_Servant servant,
382 CORBA_Environment * ev)
384 /* TODO: implement support for multiple virtual desktops */
385 CORBA_short n_desktops;
386 n_desktops = (CORBA_short) 1;
392 * @n: the index of the requested @Desktop.
393 * return values: a reference to the requested @Desktop.
395 * Get the nth accessible desktop.
398 static Accessibility_Desktop
399 impl_accessibility_registry_get_desktop (PortableServer_Servant servant,
401 CORBA_Environment * ev)
403 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
405 /* TODO: implement support for multiple virtual desktops */
408 return (Accessibility_Desktop)
409 CORBA_Object_duplicate (
410 bonobo_object_corba_objref (bonobo_object (registry->desktop)), ev);
414 return (Accessibility_Desktop) CORBA_OBJECT_NIL;
420 * return values: a sequence containing references to
423 * Get a list of accessible desktops.
426 static Accessibility_DesktopSeq *
427 impl_accessibility_registry_get_desktop_list (PortableServer_Servant servant,
428 CORBA_Environment * ev)
430 /* TODO: implement support for multiple virtual desktops */
431 return (Accessibility_DesktopSeq *) NULL;
435 impl_accessibility_registry_get_device_event_controller (PortableServer_Servant servant,
436 CORBA_Environment * ev)
438 /* TODO: not yet implemented! */
439 return CORBA_OBJECT_NIL;
443 impl_registry_notify_event (PortableServer_Servant servant,
444 const Accessibility_Event *e,
445 CORBA_Environment *ev)
447 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
448 EventTypeStruct etype;
450 parse_event_type (&etype, e->type);
452 switch (etype.type_cat)
455 _registry_notify_listeners (registry->focus_listeners, e, ev);
457 case (ETYPE_WINDOW) :
458 _registry_notify_listeners (registry->window_listeners, e, ev);
460 case (ETYPE_TOOLKIT) :
461 _registry_notify_listeners (registry->toolkit_listeners, e, ev);
466 bonobo_object_release_unref (e->source, ev);
477 _registry_notify_listeners ( GList *listeners,
478 const Accessibility_Event *e,
479 CORBA_Environment *ev)
484 EventTypeStruct etype;
486 parse_event_type (&etype, e->type);
487 minor_hash = g_str_hash (g_strconcat (etype.major, etype.minor, NULL));
488 len = g_list_length (listeners);
490 for (n=0; n<len; ++n)
492 ls = (ListenerStruct *) g_list_nth_data (listeners, n);
494 fprintf(stderr, "event hashes: %lx %lx %lx\n", ls->event_type_hash, etype.hash, minor_hash);
495 fprintf(stderr, "event name: %s\n", etype.event_name);
497 if ((ls->event_type_hash == etype.hash) || (ls->event_type_hash == minor_hash))
500 fprintf(stderr, "notifying listener #%d\n", n);
501 fprintf(stderr, "event name %s\n", Accessibility_Accessible__get_name(e->source, ev));
503 bonobo_object_dup_ref ( e->source, ev);
504 Accessibility_EventListener_notifyEvent ((Accessibility_EventListener) ls->listener,
507 if (ev->_major != CORBA_NO_EXCEPTION) {
509 ("Accessibility app error: exception during event notification: %s\n"),
510 CORBA_exception_id(ev));
518 registry_class_init (RegistryClass *klass)
520 GObjectClass * object_class = (GObjectClass *) klass;
521 POA_Accessibility_Registry__epv *epv = &klass->epv;
523 registry_parent_class = g_type_class_ref (LISTENER_TYPE);
525 object_class->finalize = registry_object_finalize;
527 epv->registerApplication = impl_accessibility_registry_register_application;
528 epv->deregisterApplication = impl_accessibility_registry_deregister_application;
529 epv->registerGlobalEventListener = impl_accessibility_registry_register_global_event_listener;
530 epv->deregisterGlobalEventListener = impl_accessibility_registry_deregister_global_event_listener;
531 epv->deregisterGlobalEventListenerAll = impl_accessibility_registry_deregister_global_event_listener_all;
532 epv->getDesktopCount = impl_accessibility_registry_get_desktop_count;
533 epv->getDesktop = impl_accessibility_registry_get_desktop;
534 epv->getDesktopList = impl_accessibility_registry_get_desktop_list;
535 epv->getDeviceEventController = impl_accessibility_registry_get_device_event_controller;
536 ((ListenerClass *) klass)->epv.notifyEvent = impl_registry_notify_event;
540 registry_init (Registry *registry)
542 registry->focus_listeners = NULL;
543 registry->window_listeners = NULL;
544 registry->toolkit_listeners = NULL;
545 registry->applications = NULL;
546 registry->desktop = desktop_new();
550 registry_get_type (void)
552 static GType type = 0;
555 static const GTypeInfo tinfo = {
556 sizeof (RegistryClass),
557 (GBaseInitFunc) NULL,
558 (GBaseFinalizeFunc) NULL,
559 (GClassInitFunc) registry_class_init,
560 (GClassFinalizeFunc) NULL,
561 NULL, /* class data */
564 (GInstanceInitFunc) registry_init,
565 NULL /* value table */
568 * Here we use bonobo_type_unique instead of
569 * gtk_type_unique, this auto-generates a load of
570 * CORBA structures for us. All derived types must
571 * use bonobo_type_unique.
573 type = bonobo_type_unique (
575 POA_Accessibility_Registry__init,
577 G_STRUCT_OFFSET (RegistryClass, epv),
589 REGISTRY (g_object_new (registry_get_type (), NULL));