Added new test that uses the C bindings API (test/simple-at).
[platform/core/uifw/at-spi2-atk.git] / libspi / eventlistener.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2001 Sun Microsystems Inc.
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 /*
24  * accessibleeventlistener.c: bonobo implementation of Listener.idl,
25  *   with added ability to attach/remove in-process callbacks.
26  *
27  */
28
29 #ifdef SPI_DEBUG
30 #include <stdio.h>
31 #endif
32
33 #include <config.h>
34 #include <bonobo/Bonobo.h>
35 #include <libspi/Accessibility.h>
36
37 /*
38  * This pulls the definition for the BonoboObject (GType)
39  */
40 #include "accessibleeventlistener.h"
41
42 /*
43  * Our parent Gtk object type
44  */
45 #define PARENT_TYPE LISTENER_TYPE
46
47 /*
48  * A pointer to our parent object class
49  */
50 static ListenerClass *accessible_event_listener_parent_class;
51
52 /*
53  * Implemented GObject::finalize
54  */
55 static void
56 accessible_event_listener_object_finalize (GObject *object)
57 {
58 #ifdef SPI_DEBUG
59         fprintf(stderr, "listener_object_finalize called\n");
60 #endif
61         ((GObjectClass *) accessible_event_listener_parent_class)->finalize (object);
62 }
63
64 /*
65  * CORBA Accessibility::Listener::notifyEvent method implementation
66  */
67
68 static void
69 impl_accessible_event_notify_event (PortableServer_Servant     servant,
70                                     const Accessibility_Event *e,
71                                     CORBA_Environment         *ev)
72 {
73
74   int n;
75   int len;
76   VoidEventListenerCB cb;
77   AccessibleEventListener *listener = ACCESSIBLE_EVENT_LISTENER (
78                                        bonobo_object_from_servant (servant));
79   len = g_list_length (listener->callbacks);
80
81   for (n=0; n<len; ++n)
82     {
83       cb =  (VoidEventListenerCB) g_list_nth_data (listener->callbacks, n);
84       if (cb)
85         {
86           (*cb) (NULL);
87         }
88     }
89   bonobo_object_release_unref (e->target, ev);
90 }
91
92 static void
93 accessible_event_listener_class_init (AccessibleEventListenerClass *klass)
94 {
95         GObjectClass * object_class = (GObjectClass *) klass;
96         ListenerClass * listener_class = (ListenerClass *) klass;
97         POA_Accessibility_EventListener__epv *epv = &listener_class->epv;
98         accessible_event_listener_parent_class = g_type_class_ref (LISTENER_TYPE);
99
100         object_class->finalize = accessible_event_listener_object_finalize;
101
102         epv->notifyEvent = impl_accessible_event_notify_event;
103 }
104
105 static void
106 accessible_event_listener_init (Listener *listener)
107 {
108 }
109
110 GType
111 accessible_event_listener_get_type (void)
112 {
113         static GType type = 0;
114
115         if (!type) {
116                 static const GTypeInfo tinfo = {
117                         sizeof (AccessibleEventListenerClass),
118                         (GBaseInitFunc) NULL,
119                         (GBaseFinalizeFunc) NULL,
120                         (GClassInitFunc) accessible_event_listener_class_init,
121                         (GClassFinalizeFunc) NULL,
122                         NULL, /* class data */
123                         sizeof (Listener),
124                         0, /* n preallocs */
125                         (GInstanceInitFunc) accessible_event_listener_init,
126                         NULL /* value table */
127                 };
128                 /*
129                  *   Here we use bonobo_type_unique instead of
130                  * gtk_type_unique, this auto-generates a load of
131                  * CORBA structures for us. All derived types must
132                  * use bonobo_type_unique.
133                  */
134                 type = bonobo_type_unique (
135                         PARENT_TYPE,
136                         POA_Accessibility_EventListener__init,
137                         NULL,
138                         G_STRUCT_OFFSET (ListenerClass, epv),
139                         &tinfo,
140                         "AccessibleEventListener");
141         }
142
143         return type;
144 }
145
146 AccessibleEventListener *
147 accessible_event_listener_new ()
148 {
149     AccessibleEventListener *retval =
150                LISTENER (g_object_new (accessible_event_listener_get_type (), NULL));
151     return retval;
152 }
153
154 void   accessible_event_listener_add_callback (AccessibleEventListener *listener,
155                                                VoidEventListenerCB callback)
156 {
157   listener->callbacks = g_list_append (listener->callbacks, callback);
158 }
159
160 void   accessible_event_listener_remove_callback (AccessibleEventListener *listener,
161                                                   VoidEventListenerCB callback)
162 {
163   listener->callbacks = g_list_remove (listener->callbacks, callback);
164 }