Initial revision
[platform/core/uifw/at-spi2-atk.git] / registryd / registry.c
1 /*
2  * registry.c: test for accessibility implementation
3  *
4  */
5 #define DEBUG_PRINTSTUFF
6 #ifdef DEBUG_PRINTSTUFF
7 #include <stdio.h>
8 #endif
9 #include <config.h>
10 #include <bonobo/Bonobo.h>
11
12 /*
13  * This pulls the CORBA definitions for the "Accessibility::Registry" server
14  */
15 #include "Registry.h"
16
17 /*
18  * This pulls the definition for the BonoboObject (GType)
19  */
20 #include "registry.h"
21
22 /*
23  * Our parent GObject type
24  */
25 #define PARENT_TYPE LISTENER_TYPE
26
27 /*
28  * A pointer to our parent object class
29  */
30 static ListenerClass *registry_parent_class;
31
32 /*
33  * Implemented GObject::finalize
34  */
35 static void
36 registry_object_finalize (GObject *object)
37 {
38 /*        Registry *registry = REGISTRY (object); */
39         GObjectClass *object_class = G_OBJECT_GET_CLASS( object);
40
41         printf("registry_object_finalize called\n");
42
43         object_class->finalize (object);
44 }
45
46 /**
47  * registerApplication:
48  * @application: a reference to the requesting @Application
49  * return values: void
50  *
51  * Register a new application with the accessibility broker.
52  *
53  **/
54 static void
55 impl_accessibility_registry_register_application (PortableServer_Servant servant,
56                                                   const Accessibility_Application application,
57                                                   CORBA_Environment * ev)
58 {
59   Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
60
61   fprintf (stderr, "registering app %p\n", application);
62   registry->desktop->applications = g_list_append (registry->desktop->applications, CORBA_Object_duplicate (application, ev));
63   /*
64    * TODO: change the implementation below to a WM-aware one;
65    * e.g. don't add all apps to the Desktop
66    */
67   /*  registry->desktop->applications = registry->applications;*/
68 }
69
70 /**
71  * deregisterApplication:
72  * @application: a reference to the @Application
73  * to be deregistered.
74  * return values: void
75  *
76  * De-register an application previously registered with the broker.
77  *
78  **/
79 static void
80 impl_accessibility_registry_deregister_application (PortableServer_Servant servant,
81                                                     const Accessibility_Application application,
82                                                     CORBA_Environment * ev)
83 {
84   Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
85   registry->applications = g_list_remove (registry->applications, application);
86 }
87
88 /*
89  * CORBA Accessibility::Registry::registerGlobalEventListener method implementation
90  */
91 static void
92 impl_accessibility_registry_register_global_event_listener
93                                             (PortableServer_Servant  servant,
94                                              Accessibility_EventListener listener,
95                                              const CORBA_char *event_name,
96                                              CORBA_Environment      *ev)
97 {
98   /**
99    *  TODO:
100    *
101    *  distinguish between event types
102    *  register with app toolkits only for requested event types
103    *  maintain list of requested types and number of listeners
104    *  find non-strcmp method of matching event types to listeners
105    *
106    **/
107
108   Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
109   /* fprintf(stderr, "registering %x/%x\n", listener, *listener); */
110   registry->listeners = g_list_append (registry->listeners, CORBA_Object_duplicate(listener, ev));
111   /* fprintf(stderr, "there are now %d listeners registered.\n", g_list_length(registry->listeners)); */
112   /* should use hashtable and CORBA_Object_hash (...) */
113 }
114
115 /*
116  * CORBA Accessibility::Registry::deregisterGlobalEventListener method implementation
117  */
118 static void
119 impl_accessibility_registry_deregister_global_event_listener
120                                                    (PortableServer_Servant  servant,
121                                                     Accessibility_EventListener listener,
122                                                     CORBA_Environment      *ev)
123 {
124   Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
125   /* TODO: this won't work since 'listener' is a duplicate ref */
126   registry->listeners = g_list_remove (registry->listeners, listener);
127   /*  fprintf(stderr, "deregister\n"); */
128 }
129
130
131 /**
132  * getDesktopCount:
133  * return values: a short integer indicating the current number of
134  * @Desktops.
135  *
136  * Get the current number of desktops.
137  *
138  **/
139 static short
140 impl_accessibility_registry_get_desktop_count (PortableServer_Servant servant,
141                                                CORBA_Environment * ev)
142 {
143   /* TODO: implement support for multiple virtual desktops */
144   CORBA_short n_desktops;
145   n_desktops = (CORBA_short) 1;
146   return n_desktops;
147 }
148
149 /**
150  * getDesktop:
151  * @n: the index of the requested @Desktop.
152  * return values: a reference to the requested @Desktop.
153  *
154  * Get the nth accessible desktop.
155  *
156  **/
157 static Accessibility_Desktop
158 impl_accessibility_registry_get_desktop (PortableServer_Servant servant,
159                                          const CORBA_short n,
160                                          CORBA_Environment * ev)
161 {
162   Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
163
164   /* TODO: implement support for multiple virtual desktops */
165   if (n == 0)
166     {
167       return (Accessibility_Desktop)
168         CORBA_Object_duplicate (
169              bonobo_object_corba_objref (bonobo_object (registry->desktop)), ev);
170     }
171   else
172     {
173       return (Accessibility_Desktop) CORBA_OBJECT_NIL;
174     }
175 }
176
177 /**
178  * getDesktopList:
179  * return values: a sequence containing references to
180  * the @Desktops.
181  *
182  * Get a list of accessible desktops.
183  *
184  **/
185 static Accessibility_DesktopSeq *
186 impl_accessibility_registry_get_desktop_list (PortableServer_Servant servant,
187                                               CORBA_Environment * ev)
188 {
189   /* TODO: implement support for multiple virtual desktops */
190   return (Accessibility_DesktopSeq *) NULL;
191 }
192
193 static CORBA_Object
194 impl_accessibility_registry_get_device_event_controller (PortableServer_Servant servant,
195                                                          CORBA_Environment * ev)
196 {
197   /* TODO: not yet implemented! */
198   return CORBA_OBJECT_NIL;
199 }
200
201 static void
202 impl_registry_notify_event (PortableServer_Servant servant,
203                             const Accessibility_Event *e,
204                             CORBA_Environment *ev)
205 {
206   int n;
207   int len;
208   Registry *registry = REGISTRY (bonobo_object_from_servant (servant));
209
210   /**
211    *  TODO:
212    *
213    *  distinguish between event types
214    *  find non-strcmp method of matching event types to listeners
215    *
216    **/
217
218   len = g_list_length (registry->listeners);
219   /* fprintf(stderr, "%d listeners registered\n", len); */
220
221   for (n=0; n<len; ++n)
222     {
223       /*      fprintf(stderr, "notifying listener #%d\n", n);*/
224       /*      fprintf(stderr, "event name %s\n", Accessibility_Accessible__get_name(e->target, ev));*/
225       Accessibility_EventListener_notifyEvent (
226                (Accessibility_EventListener) g_list_nth_data (registry->listeners, n),
227                e,
228                ev);
229     }
230 }
231
232 static void
233 registry_class_init (RegistryClass *klass)
234 {
235         GObjectClass * object_class = (GObjectClass *) klass;
236         POA_Accessibility_Registry__epv *epv = &klass->epv;
237
238         registry_parent_class = g_type_class_ref (LISTENER_TYPE);
239
240         object_class->finalize = registry_object_finalize;
241
242         epv->registerApplication = impl_accessibility_registry_register_application;
243         epv->deregisterApplication = impl_accessibility_registry_deregister_application;
244         epv->registerGlobalEventListener = impl_accessibility_registry_register_global_event_listener;
245         epv->deregisterGlobalEventListener = impl_accessibility_registry_deregister_global_event_listener;
246         epv->getDesktopCount = impl_accessibility_registry_get_desktop_count;
247         epv->getDesktop = impl_accessibility_registry_get_desktop;
248         epv->getDesktopList = impl_accessibility_registry_get_desktop_list;
249         epv->getDeviceEventController = impl_accessibility_registry_get_device_event_controller;
250         ((ListenerClass *) klass)->epv.notifyEvent = impl_registry_notify_event;
251 }
252
253 static void
254 registry_init (Registry *registry)
255 {
256   registry->listeners = NULL;
257   registry->applications = NULL;
258   registry->desktop = desktop_new();
259 }
260
261 GType
262 registry_get_type (void)
263 {
264         static GType type = 0;
265
266         if (!type) {
267                 static const GTypeInfo tinfo = {
268                         sizeof (RegistryClass),
269                         (GBaseInitFunc) NULL,
270                         (GBaseFinalizeFunc) NULL,
271                         (GClassInitFunc) registry_class_init,
272                         (GClassFinalizeFunc) NULL,
273                         NULL, /* class data */
274                         sizeof (Registry),
275                         0, /* n preallocs */
276                         (GInstanceInitFunc) registry_init,
277                         NULL /* value table */
278                 };
279                 /*
280                  *   Here we use bonobo_x_type_unique instead of
281                  * gtk_type_unique, this auto-generates a load of
282                  * CORBA structures for us. All derived types must
283                  * use bonobo_x_type_unique.
284                  */
285                 type = bonobo_x_type_unique (
286                         PARENT_TYPE,
287                         POA_Accessibility_Registry__init,
288                         NULL,
289                         G_STRUCT_OFFSET (RegistryClass, epv),
290                         &tinfo,
291                         "Registry");
292         }
293
294         return type;
295 }
296
297 Registry *
298 registry_new (void)
299 {
300     Registry *retval =
301                REGISTRY (g_object_new (registry_get_type (), NULL));
302     return retval;
303 }