Added initial implementations of DeviceEventController and KeystrokeListener.
[platform/core/uifw/at-spi2-atk.git] / libspi / keystrokelistener.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  * listener.c: test for accessibility implementation
25  *
26  */
27
28 #ifdef SPI_DEBUG
29 #include <stdio.h>
30 #endif
31
32 #include <config.h>
33 #include <bonobo/Bonobo.h>
34 #include <libspi/Accessibility.h>
35
36 /*
37  * This pulls the definition for the BonoboObject (GType)
38  */
39 #include "keystrokelistener.h"
40
41 /*
42  * Our parent Gtk object type
43  */
44 #define PARENT_TYPE BONOBO_OBJECT_TYPE
45
46 /*
47  * A pointer to our parent object class
48  */
49 static GObjectClass *keystroke_listener_parent_class;
50
51 /*
52  * Implemented GObject::finalize
53  */
54 static void
55 keystroke_listener_object_finalize (GObject *object)
56 {
57 /*        KeystrokeListener *keystroke_listener = KEYSTROKE_LISTENER (object); */
58
59 #ifdef SPI_DEBUG
60         fprintf(stderr, "keystroke_listener_object_finalize called\n");
61 #endif
62         keystroke_listener_parent_class->finalize (object);
63 }
64
65 /*
66  * CORBA Accessibility::KeystrokeListener::keyEvent method implementation
67  */
68
69 static void
70 impl_key_event (PortableServer_Servant     servant,
71                 const Accessibility_KeyStroke *key,
72                 CORBA_Environment         *ev)
73 {
74 #ifdef SPI_DEBUG
75   if (ev->_major != CORBA_NO_EXCEPTION) {
76     fprintf(stderr,
77             ("Accessibility app error: exception during keystroke notification: %s\n"),
78             CORBA_exception_id(ev));
79     exit(-1);
80   }
81 #endif
82 }
83
84 static void
85 keystroke_listener_class_init (KeystrokeListenerClass *klass)
86 {
87         GObjectClass * object_class = (GObjectClass *) klass;
88         POA_Accessibility_KeystrokeListener__epv *epv = &klass->epv;
89         keystroke_listener_parent_class = g_type_class_ref (BONOBO_OBJECT_TYPE);
90
91         object_class->finalize = keystroke_listener_object_finalize;
92
93         epv->keyEvent = impl_key_event;
94 }
95
96 static void
97 keystroke_listener_init (KeystrokeListener *keystroke_listener)
98 {
99 }
100
101 GType
102 keystroke_listener_get_type (void)
103 {
104         static GType type = 0;
105
106         if (!type) {
107                 static const GTypeInfo tinfo = {
108                         sizeof (KeystrokeListenerClass),
109                         (GBaseInitFunc) NULL,
110                         (GBaseFinalizeFunc) NULL,
111                         (GClassInitFunc) keystroke_listener_class_init,
112                         (GClassFinalizeFunc) NULL,
113                         NULL, /* class data */
114                         sizeof (KeystrokeListener),
115                         0, /* n preallocs */
116                         (GInstanceInitFunc) keystroke_listener_init,
117                         NULL /* value table */
118                 };
119                 /*
120                  *   Here we use bonobo_type_unique instead of
121                  * gtk_type_unique, this auto-generates a load of
122                  * CORBA structures for us. All derived types must
123                  * use bonobo_type_unique.
124                  */
125                 type = bonobo_type_unique (
126                         PARENT_TYPE,
127                         POA_Accessibility_KeystrokeListener__init,
128                         NULL,
129                         G_STRUCT_OFFSET (KeystrokeListenerClass, epv),
130                         &tinfo,
131                         "KeystrokeListener");
132         }
133
134         return type;
135 }
136
137 KeystrokeListener *
138 keystroke_listener_new (void)
139 {
140     KeystrokeListener *retval =
141                KEYSTROKE_LISTENER (g_object_new (keystroke_listener_get_type (), NULL));
142     return retval;
143 }