Changes to begin memory management of relayed events and sources.
[platform/core/uifw/at-spi2-atk.git] / atk-bridge / bridge.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 <orbit/orbit.h>
27 #include <atk/atk.h>
28 #include <atk/atkobject.h>
29 #include <libspi/Accessibility.h>
30 #include "accessible.h"
31 #include "application.h"
32
33 typedef struct _ArgStruct ArgStruct;
34
35 struct _ArgStruct {
36   gint c;
37   char **v;
38 };
39
40 static CORBA_Environment ev;
41 static Accessibility_Registry registry;
42
43 static gboolean bridge_register_app (gpointer p);
44 static void bridge_focus_tracker (AtkObject *object);
45
46 int
47 gtk_module_init(gint argc, char* argv[])
48 {
49   ArgStruct *args = (ArgStruct *) g_new0(ArgStruct, 1);
50   args->c = argc;
51   args->v = argv;
52   g_idle_add (bridge_register_app, args);
53 }
54
55 static gboolean
56 bridge_register_app (gpointer gp)
57 {
58   CORBA_Object oclient;
59   AtkObject *atko;
60   char *obj_id;
61   char sbuf[30];
62   ArgStruct *args = (ArgStruct *)gp;
63
64   Application *app;
65
66   CORBA_exception_init(&ev);
67
68   if (!bonobo_init (&(args->c), args->v))
69     {
70       g_error ("Could not initialize Bonobo");
71     }
72
73   /* Create the accesssible application server object */
74   app = application_new(atk_get_root ());
75
76   obj_id = "OAFIID:Accessibility_Registry:proto0.1";
77
78   oclient = bonobo_activation_activate_from_id (obj_id, 0, NULL, &ev);
79   if (ev._major != CORBA_NO_EXCEPTION) {
80     fprintf(stderr,
81             ("Accessibility app error: exception during registry activation from id: %s\n"),
82             CORBA_exception_id(&ev));
83     CORBA_exception_free(&ev);
84     exit(-1);
85   }
86
87   if (CORBA_Object_is_nil (oclient, &ev))
88     {
89       g_error ("Could not locate registry");
90     }
91
92   registry = (Accessibility_Registry) oclient;
93
94   fprintf(stderr, "About to register application\n");
95
96   bonobo_activate ();
97
98   /* Register for focus event notifications, and register app with central registry  */
99   atk_add_focus_tracker (bridge_focus_tracker);
100
101   Accessibility_Registry_registerApplication (registry,
102                                               bonobo_object_corba_objref (bonobo_object (app)),
103                                               &ev);
104   return FALSE;
105 }
106
107 static void bridge_focus_tracker (AtkObject *object)
108 {
109   Accessibility_Event *e = g_new0(Accessibility_Event, 1);
110   e->type = CORBA_string_dup ("focus:");
111   e->target = bonobo_object_corba_objref (bonobo_object (accessible_new (object)));
112   e->detail1 = 0;
113   e->detail2 = 0;
114   Accessibility_Registry_notifyEvent (registry, e, &ev);
115 }