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 * Implemented GObject::finalize
72 registry_object_finalize (GObject *object)
74 /* Registry *registry = REGISTRY (object); */
75 GObjectClass *object_class = G_OBJECT_GET_CLASS( object);
77 printf("registry_object_finalize called\n");
79 object_class->finalize (object);
83 * registerApplication:
84 * @application: a reference to the requesting @Application
87 * Register a new application with the accessibility broker.
91 impl_accessibility_registry_register_application (PortableServer_Servant servant,
92 const Accessibility_Application application,
93 CORBA_Environment * ev)
95 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
98 fprintf (stderr, "registering app %p\n", application);
100 ORBit_register_objref (application);
101 registry->desktop->applications = g_list_append (registry->desktop->applications,
102 CORBA_Object_duplicate (application, ev));
104 /* TODO: create unique string here (with libuuid call ?) */
105 Accessibility_Application__set_id (application, "test-some-unique-string", ev);
108 * TODO: change the implementation below to a WM-aware one;
109 * e.g. don't add all apps to the Desktop
114 compare_object_hash (gconstpointer p1, gconstpointer p2)
116 CORBA_Environment ev;
117 long long diff = ((CORBA_Object_hash ((CORBA_Object) p2, (CORBA_unsigned_long) 0, &ev)) -
118 (CORBA_Object_hash ((CORBA_Object) p1, (CORBA_unsigned_long) 0, &ev)));
119 return ((diff < 0) ? -1 : ((diff > 0) ? 1 : 0));
123 parse_event_type (EventTypeStruct *etype, char *event_name)
125 etype->major = ETYPE_FOCUS;
129 * deregisterApplication:
130 * @application: a reference to the @Application
131 * to be deregistered.
132 * return values: void
134 * De-register an application previously registered with the broker.
138 impl_accessibility_registry_deregister_application (PortableServer_Servant servant,
139 const Accessibility_Application application,
140 CORBA_Environment * ev)
142 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
143 GList *list = g_list_find_custom (registry->applications, application, compare_object_hash);
146 fprintf (stderr, "deregistering application\n");
147 registry->applications = g_list_delete_link (registry->applications, list);
152 * CORBA Accessibility::Registry::registerGlobalEventListener method implementation
155 impl_accessibility_registry_register_global_event_listener
156 (PortableServer_Servant servant,
157 Accessibility_EventListener listener,
158 const CORBA_char *event_name,
159 CORBA_Environment *ev)
164 * distinguish between event types
165 * register with app toolkits only for requested event types
166 * maintain list of requested types and number of listeners
167 * find non-strcmp method of matching event types to listeners
171 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
172 /* fprintf(stderr, "registering %x/%x\n", listener, *listener); */
173 EventTypeStruct etype;
174 parse_event_type (&etype, event_name);
176 /* parse, check major event type */
181 case (ETYPE_WINDOW) :
183 case (ETYPE_TOOLKIT) :
189 registry->listeners = g_list_append (registry->listeners, CORBA_Object_duplicate(listener, ev));
190 /* fprintf(stderr, "there are now %d listeners registered.\n", g_list_length(registry->listeners)); */
191 /* should use hashtable and CORBA_Object_hash (...) */
195 * CORBA Accessibility::Registry::deregisterGlobalEventListener method implementation
198 impl_accessibility_registry_deregister_global_event_listener
199 (PortableServer_Servant servant,
200 Accessibility_EventListener listener,
201 CORBA_Environment *ev)
203 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
204 /* TODO: this won't work since 'listener' is a duplicate ref */
205 registry->listeners = g_list_remove (registry->listeners, listener);
206 /* fprintf(stderr, "deregister\n"); */
212 * return values: a short integer indicating the current number of
215 * Get the current number of desktops.
219 impl_accessibility_registry_get_desktop_count (PortableServer_Servant servant,
220 CORBA_Environment * ev)
222 /* TODO: implement support for multiple virtual desktops */
223 CORBA_short n_desktops;
224 n_desktops = (CORBA_short) 1;
230 * @n: the index of the requested @Desktop.
231 * return values: a reference to the requested @Desktop.
233 * Get the nth accessible desktop.
236 static Accessibility_Desktop
237 impl_accessibility_registry_get_desktop (PortableServer_Servant servant,
239 CORBA_Environment * ev)
241 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
243 /* TODO: implement support for multiple virtual desktops */
246 return (Accessibility_Desktop)
247 CORBA_Object_duplicate (
248 bonobo_object_corba_objref (bonobo_object (registry->desktop)), ev);
252 return (Accessibility_Desktop) CORBA_OBJECT_NIL;
258 * return values: a sequence containing references to
261 * Get a list of accessible desktops.
264 static Accessibility_DesktopSeq *
265 impl_accessibility_registry_get_desktop_list (PortableServer_Servant servant,
266 CORBA_Environment * ev)
268 /* TODO: implement support for multiple virtual desktops */
269 return (Accessibility_DesktopSeq *) NULL;
273 impl_accessibility_registry_get_device_event_controller (PortableServer_Servant servant,
274 CORBA_Environment * ev)
276 /* TODO: not yet implemented! */
277 return CORBA_OBJECT_NIL;
281 impl_registry_notify_event (PortableServer_Servant servant,
282 const Accessibility_Event *e,
283 CORBA_Environment *ev)
287 Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
292 * distinguish between event types
293 * find non-strcmp method of matching event types to listeners
297 len = g_list_length (registry->listeners);
298 /* fprintf(stderr, "%d listeners registered\n", len); */
300 for (n=0; n<len; ++n)
303 fprintf(stderr, "notifying listener #%d\n", n);
304 fprintf(stderr, "event name %s\n", Accessibility_Accessible__get_name(e->target, ev));
306 Accessibility_EventListener_notifyEvent (
307 (Accessibility_EventListener) g_list_nth_data (registry->listeners, n),
314 registry_class_init (RegistryClass *klass)
316 GObjectClass * object_class = (GObjectClass *) klass;
317 POA_Accessibility_Registry__epv *epv = &klass->epv;
319 registry_parent_class = g_type_class_ref (LISTENER_TYPE);
321 object_class->finalize = registry_object_finalize;
323 epv->registerApplication = impl_accessibility_registry_register_application;
324 epv->deregisterApplication = impl_accessibility_registry_deregister_application;
325 epv->registerGlobalEventListener = impl_accessibility_registry_register_global_event_listener;
326 epv->deregisterGlobalEventListener = impl_accessibility_registry_deregister_global_event_listener;
327 epv->getDesktopCount = impl_accessibility_registry_get_desktop_count;
328 epv->getDesktop = impl_accessibility_registry_get_desktop;
329 epv->getDesktopList = impl_accessibility_registry_get_desktop_list;
330 epv->getDeviceEventController = impl_accessibility_registry_get_device_event_controller;
331 ((ListenerClass *) klass)->epv.notifyEvent = impl_registry_notify_event;
335 registry_init (Registry *registry)
337 registry->listeners = NULL;
338 registry->applications = NULL;
339 registry->desktop = desktop_new();
343 registry_get_type (void)
345 static GType type = 0;
348 static const GTypeInfo tinfo = {
349 sizeof (RegistryClass),
350 (GBaseInitFunc) NULL,
351 (GBaseFinalizeFunc) NULL,
352 (GClassInitFunc) registry_class_init,
353 (GClassFinalizeFunc) NULL,
354 NULL, /* class data */
357 (GInstanceInitFunc) registry_init,
358 NULL /* value table */
361 * Here we use bonobo_x_type_unique instead of
362 * gtk_type_unique, this auto-generates a load of
363 * CORBA structures for us. All derived types must
364 * use bonobo_x_type_unique.
366 type = bonobo_type_unique (
368 POA_Accessibility_Registry__init,
370 G_STRUCT_OFFSET (RegistryClass, epv),
382 REGISTRY (g_object_new (registry_get_type (), NULL));