Revved to 1.0.0; at-spi 1.0 is now API frozen.
[platform/core/uifw/at-spi2-atk.git] / test / at.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 #include <stdio.h>
24 #include <stdlib.h>
25 #include <libbonobo.h>
26 #include <libspi/Accessibility.h>
27 #include "accessible.h"
28 #include "listener.h"
29
30 void
31 check_ev (CORBA_Environment *ev, char *desc)
32 {
33         if (ev->_major != CORBA_NO_EXCEPTION) {
34                 fprintf(stderr,
35                 ("Accessibility app error: exception during CORBA call %s (%s)\n"),
36                         CORBA_exception_id(ev), desc);
37                 CORBA_exception_free(ev);
38                 exit(-1);
39         }
40 }
41
42 int
43 main(int argc, char **argv)
44 {
45         CORBA_Environment ev;
46         CORBA_Object oclient;
47         char *obj_id;
48         CORBA_long i;
49         CORBA_short n_desktops;
50         CORBA_long j;
51         CORBA_long n_apps;
52         CORBA_string s;
53         Accessibility_Desktop desktop;
54         Accessibility_Application app;
55         Accessibility_Registry registry;
56         SpiListener *listener;
57
58         CORBA_exception_init(&ev);
59
60         if (!bonobo_init (&argc, argv))
61           {
62             g_error ("Could not initialize Bonobo");
63           }
64
65         obj_id = "OAFIID:Accessibility_Registry:1.0";
66
67         oclient = bonobo_activation_activate_from_id (obj_id, 0, NULL, &ev);
68         if (ev._major != CORBA_NO_EXCEPTION) {
69                 fprintf(stderr,
70                 ("Accessibility app error: exception during registry activation from id: %s\n"),
71                         CORBA_exception_id(&ev));
72                 CORBA_exception_free(&ev);
73                 exit(-1);
74         }
75
76         if (CORBA_Object_is_nil (oclient, &ev))
77           {
78             g_error ("Could not locate registry");
79           }
80
81         bonobo_activate ();
82
83         listener = spi_listener_new ();
84
85         registry = (Accessibility_Registry) oclient;
86
87         Accessibility_Registry_registerGlobalEventListener
88                                    (registry,
89                                     (Accessibility_EventListener)
90                                          bonobo_object_corba_objref (bonobo_object (listener)),
91                                     "focus:",
92                                     &ev);
93         check_ev (&ev, "register:focus");
94         Accessibility_Registry_registerGlobalEventListener
95                                    (registry,
96                                     (Accessibility_EventListener)
97                                          bonobo_object_corba_objref (bonobo_object (listener)),
98                                     "Gtk:GtkWidget:button-press-event",
99                                     &ev);
100         check_ev (&ev, "register:button_press");
101         fprintf (stderr, "AT callback registered.\n");
102
103             n_desktops = Accessibility_Registry_getDesktopCount (registry, &ev);
104
105             for (i=0; i<n_desktops; ++i)
106               {
107                 desktop = Accessibility_Registry_getDesktop (registry, i, &ev);
108                 s = Accessibility_Desktop__get_name (desktop, &ev);
109                 fprintf (stderr, "desktop %d name: %s\n", i, s);
110                 CORBA_free (s);  
111                 check_ev (&ev, "desktop:name");
112                 n_apps = Accessibility_Desktop__get_childCount (desktop, &ev);
113                 check_ev (&ev, "desktop:childCount");
114                 fprintf (stderr, "desktop has %d apps:\n", n_apps);
115                 for (j=0; j<n_apps; ++j)
116                   {
117                     app = (Accessibility_Application) Accessibility_Desktop_getChildAtIndex (desktop, j, &ev);
118                     check_ev (&ev, "desktop:getChildAtIndex");
119                     s = Accessibility_Application__get_name (app, &ev);
120                     fprintf (stderr, "app %d name: %s\n", j, s);
121                     CORBA_free (s);
122                     check_ev (&ev, "app:getName");
123                   }
124               }
125
126             fprintf (stderr, "finished querying desktop(s).\n");
127             bonobo_main ();
128                /* needed by at because it is a server ? */
129         exit(0);
130 }