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;
69 Accessibility_EventListener listener;
70 guint event_type_hash;
71 EventTypeMajor event_type_major;
74 /* static function prototypes */
75 static void registry_notify_listeners ( GList *listeners,
76 const Accessibility_Event *e,
77 CORBA_Environment *ev);
80 * Implemented GObject::finalize
83 registry_object_finalize (GObject *object)
85 /* Registry *registry = REGISTRY (object); */
86 GObjectClass *object_class = G_OBJECT_GET_CLASS( object);
88 printf("registry_object_finalize called\n");
90 object_class->finalize (object);
94 * registerApplication:
95 * @application: a reference to the requesting @Application
98 * Register a new application with the accessibility broker.
102 impl_accessibility_registry_register_application (PortableServer_Servant servant,
103 const Accessibility_Application application,
104 CORBA_Environment * ev)
106 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
109 fprintf (stderr, "registering app %p\n", application);
111 ORBit_register_objref (application);
112 registry->desktop->applications = g_list_append (registry->desktop->applications,
113 CORBA_Object_duplicate (application, ev));
115 /* TODO: create unique string here (with libuuid call ?) */
116 Accessibility_Application__set_id (application, "test-some-unique-string", ev);
119 * TODO: change the implementation below to a WM-aware one;
120 * e.g. don't add all apps to the Desktop
125 compare_object_hash (gconstpointer p1, gconstpointer p2)
127 CORBA_Environment ev;
128 long long diff = ((CORBA_Object_hash ((CORBA_Object) p2, (CORBA_unsigned_long) 0, &ev)) -
129 (CORBA_Object_hash ((CORBA_Object) p1, (CORBA_unsigned_long) 0, &ev)));
130 return ((diff < 0) ? -1 : ((diff > 0) ? 1 : 0));
134 toolkit_listener (GSignalInvocationHint *signal_hint, guint n_param_value,
135 const GValue *param_values, gpointer data)
142 register_with_toolkit (EventTypeStruct *etype)
145 atk_add_global_event_listener (toolkit_listener, g_strconcat (etype->minor, etype->detail, NULL));
149 compare_listener_hash (gconstpointer p1, gconstpointer p2)
151 return (((ListenerStruct *)p2)->event_type_hash - ((ListenerStruct *)p1)->event_type_hash);
155 parse_event_type (EventTypeStruct *etype, char *event_name)
157 static gunichar delimiter = 0;
158 char * major_delim_char;
159 char * minor_delim_char;
164 delimiter = g_utf8_get_char (":");
167 major_delim_char = g_utf8_strchr (event_name, (gssize) 32, delimiter);
168 minor_delim_char = g_utf8_strrchr (event_name, (gssize) 255, delimiter);
170 nbytes = (guint)((gint64) minor_delim_char -
171 (gint64) major_delim_char);
173 fprintf (stderr, "nbytes = %ld\n", (long) nbytes);
174 if (!g_ascii_strncasecmp (event_name, "focus:", 6))
176 etype->major = ETYPE_FOCUS;
178 else if (!g_ascii_strncasecmp (event_name, "window:", 7))
180 etype->major = ETYPE_WINDOW;
184 etype->major = ETYPE_TOOLKIT;
187 if (major_delim_char)
189 etype->minor = g_strndup (major_delim_char, nbytes);
190 etype->hash = g_str_hash (major_delim_char);
194 etype->minor = g_strdup ("");
195 etype->hash = g_str_hash ("");
197 if (major_delim_char != minor_delim_char)
199 etype->detail = g_strdup (minor_delim_char);
203 etype->detail = g_strdup ("");
207 /* TODO: don't forget to free the strings from caller when done ! */
211 * deregisterApplication:
212 * @application: a reference to the @Application
213 * to be deregistered.
214 * return values: void
216 * De-register an application previously registered with the broker.
220 impl_accessibility_registry_deregister_application (PortableServer_Servant servant,
221 const Accessibility_Application application,
222 CORBA_Environment * ev)
224 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
225 GList *list = g_list_find_custom (registry->applications, application, compare_object_hash);
228 fprintf (stderr, "deregistering application\n");
229 registry->applications = g_list_delete_link (registry->applications, list);
234 * CORBA Accessibility::Registry::registerGlobalEventListener method implementation
237 impl_accessibility_registry_register_global_event_listener
238 (PortableServer_Servant servant,
239 Accessibility_EventListener listener,
240 const CORBA_char *event_name,
241 CORBA_Environment *ev)
246 * register with app toolkits only for requested event types
250 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
251 /* fprintf(stderr, "registering %x/%x\n", listener, *listener); */
252 ListenerStruct *ls = g_malloc (sizeof (ListenerStruct));
254 EventTypeStruct etype;
256 /* parse, check major event type and add listener accordingly */
257 parse_event_type (&etype, event_name);
258 ls->event_type_hash = etype.hash;
259 ls->event_type_major = etype.major;
264 ls->listener = CORBA_Object_duplicate (listener, ev);
265 registry->focus_listeners =
266 g_list_append (registry->focus_listeners, ls);
268 case (ETYPE_WINDOW) :
269 /* Support for Window Manager Events is not yet implemented */
271 case (ETYPE_TOOLKIT) :
272 ls->listener = CORBA_Object_duplicate (listener, ev);
273 registry->toolkit_listeners =
274 g_list_append (registry->toolkit_listeners, ls);
275 register_with_toolkit (&etype);
283 * CORBA Accessibility::Registry::deregisterGlobalEventListenerAll method implementation
286 impl_accessibility_registry_deregister_global_event_listener_all
287 (PortableServer_Servant servant,
288 Accessibility_EventListener listener,
289 CORBA_Environment *ev)
291 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
292 GList *list = g_list_find_custom (registry->focus_listeners, listener, compare_object_hash);
295 * TODO : de-register with toolkit if the last instance of a listener
296 * to a particular toolkit event type has been deregistered.
301 fprintf (stderr, "deregistering listener\n");
302 registry->focus_listeners = g_list_delete_link (registry->focus_listeners, list);
303 list = g_list_find_custom (registry->focus_listeners, listener, compare_object_hash);
305 list = g_list_find_custom (registry->toolkit_listeners, listener, compare_object_hash);
308 fprintf (stderr, "deregistering listener\n");
309 registry->toolkit_listeners = g_list_delete_link (registry->toolkit_listeners, list);
310 list = g_list_find_custom (registry->toolkit_listeners, listener, compare_object_hash);
315 * CORBA Accessibility::Registry::deregisterGlobalEventListener method implementation
318 impl_accessibility_registry_deregister_global_event_listener
319 (PortableServer_Servant servant,
320 Accessibility_EventListener listener,
321 const CORBA_char * event_name,
322 CORBA_Environment *ev)
324 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
326 EventTypeStruct etype;
330 parse_event_type (&etype, event_name);
334 listeners = ®istry->focus_listeners;
336 case (ETYPE_WINDOW) :
337 /* Support for Window Manager Events is not yet implemented */
339 case (ETYPE_TOOLKIT) :
340 listeners = ®istry->toolkit_listeners;
346 ls.event_type_hash = etype.hash;
347 list = g_list_find_custom (*listeners, &ls, compare_listener_hash);
351 fprintf (stderr, "deregistering listener\n");
352 *listeners = g_list_delete_link (*listeners, list);
353 list = g_list_find_custom (*listeners, &ls, compare_listener_hash);
360 * return values: a short integer indicating the current number of
363 * Get the current number of desktops.
367 impl_accessibility_registry_get_desktop_count (PortableServer_Servant servant,
368 CORBA_Environment * ev)
370 /* TODO: implement support for multiple virtual desktops */
371 CORBA_short n_desktops;
372 n_desktops = (CORBA_short) 1;
378 * @n: the index of the requested @Desktop.
379 * return values: a reference to the requested @Desktop.
381 * Get the nth accessible desktop.
384 static Accessibility_Desktop
385 impl_accessibility_registry_get_desktop (PortableServer_Servant servant,
387 CORBA_Environment * ev)
389 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
391 /* TODO: implement support for multiple virtual desktops */
394 return (Accessibility_Desktop)
395 CORBA_Object_duplicate (
396 bonobo_object_corba_objref (bonobo_object (registry->desktop)), ev);
400 return (Accessibility_Desktop) CORBA_OBJECT_NIL;
406 * return values: a sequence containing references to
409 * Get a list of accessible desktops.
412 static Accessibility_DesktopSeq *
413 impl_accessibility_registry_get_desktop_list (PortableServer_Servant servant,
414 CORBA_Environment * ev)
416 /* TODO: implement support for multiple virtual desktops */
417 return (Accessibility_DesktopSeq *) NULL;
421 impl_accessibility_registry_get_device_event_controller (PortableServer_Servant servant,
422 CORBA_Environment * ev)
424 /* TODO: not yet implemented! */
425 return CORBA_OBJECT_NIL;
429 impl_registry_notify_event (PortableServer_Servant servant,
430 const Accessibility_Event *e,
431 CORBA_Environment *ev)
433 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
434 EventTypeStruct etype;
436 parse_event_type (&etype, e->type);
441 registry_notify_listeners (registry->focus_listeners, e, ev);
443 case (ETYPE_WINDOW) :
444 registry_notify_listeners (registry->window_listeners, e, ev);
446 case (ETYPE_TOOLKIT) :
447 registry_notify_listeners (registry->toolkit_listeners, e, ev);
452 bonobo_object_release_unref (e->target, ev);
456 registry_notify_listeners ( GList *listeners,
457 const Accessibility_Event *e,
458 CORBA_Environment *ev)
463 EventTypeStruct etype;
465 parse_event_type (&etype, e->type);
466 minor_hash = g_str_hash (etype.minor);
467 len = g_list_length (listeners);
469 for (n=0; n<len; ++n)
471 ls = (ListenerStruct *) g_list_nth_data (listeners, n);
473 fprintf(stderr, "event hashes: %lx %lx\n", ls->event_type_hash, etype.hash);
475 if ((ls->event_type_hash == etype.hash) || (ls->event_type_hash == minor_hash))
478 fprintf(stderr, "notifying listener #%d\n", n);
479 fprintf(stderr, "event name %s\n", Accessibility_Accessible__get_name(e->target, ev));
481 bonobo_object_dup_ref ( e->target, ev);
482 Accessibility_EventListener_notifyEvent ((Accessibility_EventListener) ls->listener,
485 if (ev->_major != CORBA_NO_EXCEPTION) {
487 ("Accessibility app error: exception during event notification: %s\n"),
488 CORBA_exception_id(ev));
496 registry_class_init (RegistryClass *klass)
498 GObjectClass * object_class = (GObjectClass *) klass;
499 POA_Accessibility_Registry__epv *epv = &klass->epv;
501 registry_parent_class = g_type_class_ref (LISTENER_TYPE);
503 object_class->finalize = registry_object_finalize;
505 epv->registerApplication = impl_accessibility_registry_register_application;
506 epv->deregisterApplication = impl_accessibility_registry_deregister_application;
507 epv->registerGlobalEventListener = impl_accessibility_registry_register_global_event_listener;
508 epv->deregisterGlobalEventListener = impl_accessibility_registry_deregister_global_event_listener;
509 epv->deregisterGlobalEventListenerAll = impl_accessibility_registry_deregister_global_event_listener_all;
510 epv->getDesktopCount = impl_accessibility_registry_get_desktop_count;
511 epv->getDesktop = impl_accessibility_registry_get_desktop;
512 epv->getDesktopList = impl_accessibility_registry_get_desktop_list;
513 epv->getDeviceEventController = impl_accessibility_registry_get_device_event_controller;
514 ((ListenerClass *) klass)->epv.notifyEvent = impl_registry_notify_event;
518 registry_init (Registry *registry)
520 registry->focus_listeners = NULL;
521 registry->window_listeners = NULL;
522 registry->toolkit_listeners = NULL;
523 registry->applications = NULL;
524 registry->desktop = desktop_new();
528 registry_get_type (void)
530 static GType type = 0;
533 static const GTypeInfo tinfo = {
534 sizeof (RegistryClass),
535 (GBaseInitFunc) NULL,
536 (GBaseFinalizeFunc) NULL,
537 (GClassInitFunc) registry_class_init,
538 (GClassFinalizeFunc) NULL,
539 NULL, /* class data */
542 (GInstanceInitFunc) registry_init,
543 NULL /* value table */
546 * Here we use bonobo_type_unique instead of
547 * gtk_type_unique, this auto-generates a load of
548 * CORBA structures for us. All derived types must
549 * use bonobo_type_unique.
551 type = bonobo_type_unique (
553 POA_Accessibility_Registry__init,
555 G_STRUCT_OFFSET (RegistryClass, epv),
567 REGISTRY (g_object_new (registry_get_type (), NULL));