2002-05-09 Marc Mulcahy <marc.mulcahy@sun.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  *
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 <string.h>
24 #include <libbonobo.h>
25 #include "../cspi-lowlevel.h"
26
27 void
28 cspi_dup_ref (CORBA_Object object)
29 {
30   bonobo_object_dup_ref (object, NULL);
31 }
32
33 void
34 cspi_release_unref (CORBA_Object object)
35 {
36   bonobo_object_release_unref (object, NULL);
37 }
38
39 SPIBoolean
40 cspi_check_ev (const char *error_string)
41 {
42   CORBA_Environment *ev = cspi_ev ();
43
44   if (ev->_major != CORBA_NO_EXCEPTION)
45     {
46       char *err;
47
48       err = bonobo_exception_get_text (ev);
49
50       fprintf (stderr, "Warning: AT-SPI error: %s: %s\n",
51                error_string, err);
52
53       g_free (err);
54
55       CORBA_exception_free (ev);
56
57       return FALSE;
58     }
59   else
60     {
61       return TRUE;
62     }
63 }
64
65 char *
66 cspi_exception_get_text (void)
67 {
68   char *ret, *txt;
69
70   txt = bonobo_exception_get_text (cspi_ev ());
71   ret = strdup (txt);
72   g_free (txt);
73
74   return ret;
75 }
76
77 CORBA_Object
78 cspi_init (void)
79 {
80   char *obj_id;
81   CORBA_Object registry;
82   CORBA_Environment ev;
83
84   if (!bonobo_init (0, NULL))
85     {
86       g_error ("Could not initialize Bonobo");
87     }
88
89   obj_id = "OAFIID:Accessibility_Registry:proto0.1";
90
91   CORBA_exception_init (&ev);
92
93   registry = bonobo_activation_activate_from_id (
94     obj_id, 0, NULL, &ev);
95
96   if (ev._major != CORBA_NO_EXCEPTION)
97     {
98       g_error ("AT-SPI error: during registry activation: %s\n",
99                bonobo_exception_get_text (&ev));
100     }
101
102   if (registry == CORBA_OBJECT_NIL)
103     {
104       g_error ("Could not locate registry");
105     }
106
107   bonobo_activate ();
108
109   return registry;
110 }
111
112 void
113 cspi_main (void)
114 {
115   bonobo_main ();
116 }
117
118 void
119 cspi_main_quit (void)
120 {
121   bonobo_main_quit ();
122 }