2002-08-12 Michael Meeks <michael@ximian.com>
[platform/core/uifw/at-spi2-atk.git] / cspi / bonobo / cspi-bonobo.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  *           2002 Ximian Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24 #include <string.h>
25 #include <libbonobo.h>
26 #include "../cspi-lowlevel.h"
27
28 CORBA_Object
29 cspi_dup_ref (CORBA_Object object)
30 {
31   return bonobo_object_dup_ref (object, NULL);
32 }
33
34 void
35 cspi_release_unref (CORBA_Object object)
36 {
37   bonobo_object_release_unref (object, NULL);
38 }
39
40 SPIBoolean
41 cspi_check_ev (const char *error_string)
42 {
43   CORBA_Environment *ev = cspi_ev ();
44
45   if (ev->_major != CORBA_NO_EXCEPTION)
46     {
47       char *err;
48
49       err = bonobo_exception_get_text (ev);
50
51       fprintf (stderr, "Warning: AT-SPI error: %s: %s\n",
52                error_string, err);
53
54       g_free (err);
55
56       CORBA_exception_free (ev);
57
58       return FALSE;
59     }
60   else
61     {
62       return TRUE;
63     }
64 }
65
66 char *
67 cspi_exception_get_text (void)
68 {
69   char *ret, *txt;
70
71   txt = bonobo_exception_get_text (cspi_ev ());
72   ret = strdup (txt);
73   g_free (txt);
74
75   return ret;
76 }
77
78 CORBA_Object
79 cspi_init (void)
80 {
81   char *obj_id;
82   CORBA_Object registry;
83   CORBA_Environment ev;
84
85   if (!bonobo_init (0, NULL))
86     {
87       g_error ("Could not initialize Bonobo");
88     }
89
90   obj_id = "OAFIID:Accessibility_Registry:1.0";
91
92   CORBA_exception_init (&ev);
93
94   registry = bonobo_activation_activate_from_id (
95     obj_id, 0, NULL, &ev);
96
97   if (ev._major != CORBA_NO_EXCEPTION)
98     {
99       g_error ("AT-SPI error: during registry activation: %s\n",
100                bonobo_exception_get_text (&ev));
101     }
102
103   if (registry == CORBA_OBJECT_NIL)
104     {
105       g_error ("Could not locate registry");
106     }
107
108   bonobo_activate ();
109
110   return registry;
111 }
112
113 SPIBoolean
114 cspi_ping (CORBA_Object object)
115 {
116         return bonobo_unknown_ping (object, NULL);
117 }
118
119 void
120 cspi_main (void)
121 {
122   bonobo_main ();
123 }
124
125 void
126 cspi_main_quit (void)
127 {
128   bonobo_main_quit ();
129 }