2001-08-24 Mark McLoughlin <mark@skynet.ie>
[platform/core/uifw/at-spi2-atk.git] / libspi / listener.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 "listener.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 *listener_parent_class;
50
51 /*
52  * Implemented GObject::finalize
53  */
54 static void
55 listener_object_finalize (GObject *object)
56 {
57 /*        Listener *listener = LISTENER (object); */
58
59 #ifdef SPI_DEBUG
60         fprintf(stderr, "listener_object_finalize called\n");
61 #endif
62         listener_parent_class->finalize (object);
63 }
64
65 /*
66  * CORBA Accessibility::Listener::notifyEvent method implementation
67  */
68
69 static void
70 impl_notify_event (PortableServer_Servant     servant,
71                    const Accessibility_Event *e,
72                    CORBA_Environment         *ev)
73 {
74 #ifdef SPI_DEBUG
75   fprintf (stderr, "notify %s...\n", e->type);
76   fprintf (stderr, "source name: '%s'\n",
77            Accessibility_Accessible__get_name(e->source, ev));
78   if (ev->_major != CORBA_NO_EXCEPTION) {
79     fprintf(stderr,
80             ("Accessibility app error: exception during event notification: %s\n"),
81             CORBA_exception_id(ev));
82     exit(-1);
83   }
84   /*
85   fprintf (stderr, "source is component ? : %s\n",
86            Accessibility_Accessible_queryInterface (e->source,
87                                                     "IDL:Accessibility/Component:1.0",
88                                                     ev)
89            ? "yes" : "no");
90   */
91   /* TODO: free/deref the returned interface! */
92 #endif
93   Bonobo_Unknown_unref (e->source, ev);
94 }
95
96 static void
97 listener_class_init (ListenerClass *klass)
98 {
99         GObjectClass * object_class = (GObjectClass *) klass;
100         POA_Accessibility_EventListener__epv *epv = &klass->epv;
101         listener_parent_class = g_type_class_ref (BONOBO_OBJECT_TYPE);
102
103         object_class->finalize = listener_object_finalize;
104
105         epv->notifyEvent = impl_notify_event;
106 }
107
108 static void
109 listener_init (Listener *listener)
110 {
111 }
112
113 GType
114 listener_get_type (void)
115 {
116         static GType type = 0;
117
118         if (!type) {
119                 static const GTypeInfo tinfo = {
120                         sizeof (ListenerClass),
121                         (GBaseInitFunc) NULL,
122                         (GBaseFinalizeFunc) NULL,
123                         (GClassInitFunc) listener_class_init,
124                         (GClassFinalizeFunc) NULL,
125                         NULL, /* class data */
126                         sizeof (Listener),
127                         0, /* n preallocs */
128                         (GInstanceInitFunc) listener_init,
129                         NULL /* value table */
130                 };
131                 /*
132                  *   Here we use bonobo_type_unique instead of
133                  * gtk_type_unique, this auto-generates a load of
134                  * CORBA structures for us. All derived types must
135                  * use bonobo_type_unique.
136                  */
137                 type = bonobo_type_unique (
138                         PARENT_TYPE,
139                         POA_Accessibility_EventListener__init,
140                         NULL,
141                         G_STRUCT_OFFSET (ListenerClass, epv),
142                         &tinfo,
143                         "Listener");
144         }
145
146         return type;
147 }
148
149 Listener *
150 listener_new (void)
151 {
152     Listener *retval =
153                LISTENER (g_object_new (listener_get_type (), NULL));
154     return retval;
155 }