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);
82 * Implemented GObject::finalize
85 registry_object_finalize (GObject *object)
87 /* Registry *registry = REGISTRY (object); */
88 GObjectClass *object_class = G_OBJECT_GET_CLASS( object);
90 printf("registry_object_finalize called\n");
92 object_class->finalize (object);
96 * registerApplication:
97 * @application: a reference to the requesting @Application
100 * Register a new application with the accessibility broker.
104 impl_accessibility_registry_register_application (PortableServer_Servant servant,
105 const Accessibility_Application application,
106 CORBA_Environment * ev)
108 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
111 fprintf (stderr, "registering app %p\n", application);
113 registry->desktop->applications = g_list_append (registry->desktop->applications,
114 CORBA_Object_duplicate (application, ev));
116 /* TODO: create unique string here (with libuuid call ?) */
117 Accessibility_Application__set_id (application, "test-some-unique-string", ev);
120 * TODO: change the implementation below to a WM-aware one;
121 * e.g. don't add all apps to the Desktop
126 compare_object_hash (gconstpointer p1, gconstpointer p2)
128 CORBA_Environment ev;
129 long long diff = ((CORBA_Object_hash ((CORBA_Object) p2, (CORBA_unsigned_long) 0, &ev)) -
130 (CORBA_Object_hash ((CORBA_Object) p1, (CORBA_unsigned_long) 0, &ev)));
131 return ((diff < 0) ? -1 : ((diff > 0) ? 1 : 0));
135 register_with_toolkits (Registry *registry_bonobo_object, EventTypeStruct *etype, CORBA_Environment *ev)
140 Accessibility_Desktop desktop;
141 Accessibility_Application app;
142 Accessibility_Registry registry;
143 registry = bonobo_object_corba_objref (bonobo_object (registry_bonobo_object));
145 /* for each app in each desktop, call bridge_register_toolkit_event */
147 n_desktops = Accessibility_Registry_getDesktopCount (registry, ev);
149 for (i=0; i<n_desktops; ++i)
151 desktop = Accessibility_Registry_getDesktop (registry, i, ev);
152 n_apps = Accessibility_Desktop__get_childCount (desktop, ev);
153 for (j=0; j<n_apps; ++j)
155 app = (Accessibility_Application) Accessibility_Desktop_getChildAtIndex (desktop,
158 Accessibility_Application_registerToolkitEventListener (app,
160 CORBA_string_dup (etype->event_name),
167 compare_listener_hash (gconstpointer p1, gconstpointer p2)
169 return (((ListenerStruct *)p2)->event_type_hash - ((ListenerStruct *)p1)->event_type_hash);
173 parse_event_type (EventTypeStruct *etype, char *event_name)
176 gchar **split_string;
178 split_string = g_strsplit(event_name, ":", 4);
179 etype->event_name = g_strndup(event_name, 255);
181 if (!g_ascii_strncasecmp (event_name, "focus:", 6))
183 etype->type_cat = ETYPE_FOCUS;
185 else if (!g_ascii_strncasecmp (event_name, "window:", 7))
187 etype->type_cat = ETYPE_WINDOW;
191 etype->type_cat = ETYPE_TOOLKIT;
196 etype->major = split_string[1];
199 etype->minor = split_string[2];
202 etype->detail = split_string[3];
203 etype->hash = g_str_hash ( g_strconcat (split_string[1], split_string[2], split_string[3], NULL));
207 etype->detail = g_strdup ("");
208 etype->hash = g_str_hash ( g_strconcat (split_string[1], split_string[2], NULL));
213 etype->minor = g_strdup ("");
214 etype->hash = g_str_hash ( split_string[1]);
219 etype->major = g_strdup ("");
220 etype->minor = g_strdup ("");
221 etype->detail = g_strdup ("");
222 etype->hash = g_str_hash ("");
225 /* TODO: don't forget to free the strings from caller when done ! */
229 * deregisterApplication:
230 * @application: a reference to the @Application
231 * to be deregistered.
232 * return values: void
234 * De-register an application previously registered with the broker.
238 impl_accessibility_registry_deregister_application (PortableServer_Servant servant,
239 const Accessibility_Application application,
240 CORBA_Environment * ev)
242 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
243 GList *list = g_list_find_custom (registry->applications, application, compare_object_hash);
246 fprintf (stderr, "deregistering application\n");
247 registry->applications = g_list_delete_link (registry->applications, list);
252 * CORBA Accessibility::Registry::registerGlobalEventListener method implementation
255 impl_accessibility_registry_register_global_event_listener
256 (PortableServer_Servant servant,
257 Accessibility_EventListener listener,
258 const CORBA_char *event_name,
259 CORBA_Environment *ev)
261 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
262 ListenerStruct *ls = g_malloc (sizeof (ListenerStruct));
263 EventTypeStruct etype;
265 fprintf(stderr, "registering for events of type %s\n", event_name);
267 /* parse, check major event type and add listener accordingly */
268 parse_event_type (&etype, event_name);
269 ls->event_type_hash = etype.hash;
270 ls->event_type_cat = etype.type_cat;
272 switch (etype.type_cat)
275 ls->listener = CORBA_Object_duplicate (listener, ev);
276 registry->focus_listeners =
277 g_list_append (registry->focus_listeners, ls);
279 case (ETYPE_WINDOW) :
280 /* Support for Window Manager Events is not yet implemented */
282 case (ETYPE_TOOLKIT) :
283 ls->listener = CORBA_Object_duplicate (listener, ev);
284 registry->toolkit_listeners =
285 g_list_append (registry->toolkit_listeners, ls);
286 register_with_toolkits (registry, &etype, ev);
294 * CORBA Accessibility::Registry::deregisterGlobalEventListenerAll method implementation
297 impl_accessibility_registry_deregister_global_event_listener_all
298 (PortableServer_Servant servant,
299 Accessibility_EventListener listener,
300 CORBA_Environment *ev)
302 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
303 GList *list = g_list_find_custom (registry->focus_listeners, listener, compare_object_hash);
306 * TODO : de-register with toolkit if the last instance of a listener
307 * to a particular toolkit event type has been deregistered.
312 fprintf (stderr, "deregistering listener\n");
313 registry->focus_listeners = g_list_delete_link (registry->focus_listeners, list);
314 list = g_list_find_custom (registry->focus_listeners, listener, compare_object_hash);
316 list = g_list_find_custom (registry->toolkit_listeners, listener, compare_object_hash);
319 fprintf (stderr, "deregistering listener\n");
320 registry->toolkit_listeners = g_list_delete_link (registry->toolkit_listeners, list);
321 list = g_list_find_custom (registry->toolkit_listeners, listener, compare_object_hash);
326 * CORBA Accessibility::Registry::deregisterGlobalEventListener method implementation
329 impl_accessibility_registry_deregister_global_event_listener
330 (PortableServer_Servant servant,
331 Accessibility_EventListener listener,
332 const CORBA_char * event_name,
333 CORBA_Environment *ev)
335 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
337 EventTypeStruct etype;
341 parse_event_type (&etype, event_name);
342 switch (etype.type_cat)
345 listeners = ®istry->focus_listeners;
347 case (ETYPE_WINDOW) :
348 /* Support for Window Manager Events is not yet implemented */
350 case (ETYPE_TOOLKIT) :
351 listeners = ®istry->toolkit_listeners;
357 ls.event_type_hash = etype.hash;
358 list = g_list_find_custom (*listeners, &ls, compare_listener_hash);
362 fprintf (stderr, "deregistering listener\n");
363 *listeners = g_list_delete_link (*listeners, list);
364 list = g_list_find_custom (*listeners, &ls, compare_listener_hash);
371 * return values: a short integer indicating the current number of
374 * Get the current number of desktops.
378 impl_accessibility_registry_get_desktop_count (PortableServer_Servant servant,
379 CORBA_Environment * ev)
381 /* TODO: implement support for multiple virtual desktops */
382 CORBA_short n_desktops;
383 n_desktops = (CORBA_short) 1;
389 * @n: the index of the requested @Desktop.
390 * return values: a reference to the requested @Desktop.
392 * Get the nth accessible desktop.
395 static Accessibility_Desktop
396 impl_accessibility_registry_get_desktop (PortableServer_Servant servant,
398 CORBA_Environment * ev)
400 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
402 /* TODO: implement support for multiple virtual desktops */
405 return (Accessibility_Desktop)
406 CORBA_Object_duplicate (
407 bonobo_object_corba_objref (bonobo_object (registry->desktop)), ev);
411 return (Accessibility_Desktop) CORBA_OBJECT_NIL;
417 * return values: a sequence containing references to
420 * Get a list of accessible desktops.
423 static Accessibility_DesktopSeq *
424 impl_accessibility_registry_get_desktop_list (PortableServer_Servant servant,
425 CORBA_Environment * ev)
427 /* TODO: implement support for multiple virtual desktops */
428 return (Accessibility_DesktopSeq *) NULL;
432 impl_accessibility_registry_get_device_event_controller (PortableServer_Servant servant,
433 CORBA_Environment * ev)
435 /* TODO: not yet implemented! */
436 return CORBA_OBJECT_NIL;
440 impl_registry_notify_event (PortableServer_Servant servant,
441 const Accessibility_Event *e,
442 CORBA_Environment *ev)
444 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
445 EventTypeStruct etype;
447 parse_event_type (&etype, e->type);
449 switch (etype.type_cat)
452 registry_notify_listeners (registry->focus_listeners, e, ev);
454 case (ETYPE_WINDOW) :
455 registry_notify_listeners (registry->window_listeners, e, ev);
457 case (ETYPE_TOOLKIT) :
458 registry_notify_listeners (registry->toolkit_listeners, e, ev);
463 bonobo_object_release_unref (e->target, ev);
467 registry_notify_listeners ( GList *listeners,
468 const Accessibility_Event *e,
469 CORBA_Environment *ev)
474 EventTypeStruct etype;
476 parse_event_type (&etype, e->type);
477 minor_hash = g_str_hash (g_strconcat (etype.major, etype.minor, NULL));
478 len = g_list_length (listeners);
480 for (n=0; n<len; ++n)
482 ls = (ListenerStruct *) g_list_nth_data (listeners, n);
484 fprintf(stderr, "event hashes: %lx %lx %lx\n", ls->event_type_hash, etype.hash, minor_hash);
485 fprintf(stderr, "event name: %s\n", etype.event_name);
487 if ((ls->event_type_hash == etype.hash) || (ls->event_type_hash == minor_hash))
490 fprintf(stderr, "notifying listener #%d\n", n);
491 fprintf(stderr, "event name %s\n", Accessibility_Accessible__get_name(e->target, ev));
493 bonobo_object_dup_ref ( e->target, ev);
494 Accessibility_EventListener_notifyEvent ((Accessibility_EventListener) ls->listener,
497 if (ev->_major != CORBA_NO_EXCEPTION) {
499 ("Accessibility app error: exception during event notification: %s\n"),
500 CORBA_exception_id(ev));
508 registry_class_init (RegistryClass *klass)
510 GObjectClass * object_class = (GObjectClass *) klass;
511 POA_Accessibility_Registry__epv *epv = &klass->epv;
513 registry_parent_class = g_type_class_ref (LISTENER_TYPE);
515 object_class->finalize = registry_object_finalize;
517 epv->registerApplication = impl_accessibility_registry_register_application;
518 epv->deregisterApplication = impl_accessibility_registry_deregister_application;
519 epv->registerGlobalEventListener = impl_accessibility_registry_register_global_event_listener;
520 epv->deregisterGlobalEventListener = impl_accessibility_registry_deregister_global_event_listener;
521 epv->deregisterGlobalEventListenerAll = impl_accessibility_registry_deregister_global_event_listener_all;
522 epv->getDesktopCount = impl_accessibility_registry_get_desktop_count;
523 epv->getDesktop = impl_accessibility_registry_get_desktop;
524 epv->getDesktopList = impl_accessibility_registry_get_desktop_list;
525 epv->getDeviceEventController = impl_accessibility_registry_get_device_event_controller;
526 ((ListenerClass *) klass)->epv.notifyEvent = impl_registry_notify_event;
530 registry_init (Registry *registry)
532 registry->focus_listeners = NULL;
533 registry->window_listeners = NULL;
534 registry->toolkit_listeners = NULL;
535 registry->applications = NULL;
536 registry->desktop = desktop_new();
540 registry_get_type (void)
542 static GType type = 0;
545 static const GTypeInfo tinfo = {
546 sizeof (RegistryClass),
547 (GBaseInitFunc) NULL,
548 (GBaseFinalizeFunc) NULL,
549 (GClassInitFunc) registry_class_init,
550 (GClassFinalizeFunc) NULL,
551 NULL, /* class data */
554 (GInstanceInitFunc) registry_init,
555 NULL /* value table */
558 * Here we use bonobo_type_unique instead of
559 * gtk_type_unique, this auto-generates a load of
560 * CORBA structures for us. All derived types must
561 * use bonobo_type_unique.
563 type = bonobo_type_unique (
565 POA_Accessibility_Registry__init,
567 G_STRUCT_OFFSET (RegistryClass, epv),
579 REGISTRY (g_object_new (registry_get_type (), NULL));