source: trunk/third/bonobo/bonobo/bonobo-object-client.c @ 15814

Revision 15814, 9.7 KB checked in by ghudson, 24 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r15813, which included commits to RCS files with non-trunk default branches.
Line 
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2/*
3 * bonobo-object-client.c:
4 *   This handles the client-view of a remote Bonobo object.
5 *
6 * Author:
7 *   Miguel de Icaza (miguel@kernel.org)
8 *
9 * Copyright 1999 Helix Code, Inc.
10 */
11#include <bonobo/bonobo-object-client.h>
12#include <liboaf/liboaf.h>
13#include <liboaf/oaf-async.h>
14#include <bonobo/bonobo-stream.h>
15#include <bonobo/bonobo-exception.h>
16
17/* Internal data structure for bonobo_object_client_activate_async */
18typedef struct {
19        BonoboObjectClientAsyncCallback callback;
20        gpointer                        user_data;
21} BonoboObjectClientAsyncCallbackData;
22
23static BonoboObjectClass *bonobo_object_client_parent_class;
24
25/**
26 * bonobo_object_client_construct:
27 * @object_client: The BonoboObjectClient object to construct
28 * @corba_object: The remote CORBA object this object_client refers to
29 *
30 * Initializes @object_client with the CORBA object for the
31 * Bonobo::Unknown interface provided in @corba_object.
32 *
33 * Returns: the initialized BonoboObjectClient object.
34 */
35BonoboObjectClient *
36bonobo_object_client_construct (BonoboObjectClient *object_client, CORBA_Object corba_object)
37{
38        g_return_val_if_fail (BONOBO_IS_OBJECT_CLIENT (object_client), NULL);
39        g_return_val_if_fail (corba_object != CORBA_OBJECT_NIL, NULL);
40       
41        BONOBO_OBJECT (object_client)->corba_objref = corba_object;
42
43        return object_client;
44}
45
46/**
47 * bonobo_object_activate:
48 * @iid: an OAFIID
49 * @oaf_flags: activation flags
50 *
51 * This activates the object from the IID using oaf; you probably
52 * don't want to do this, you might want to use bonobo_get_object
53 * which does object activation through the moniker system.
54 *
55 * You might also consider doing property-based activation using the
56 * the OAF-based capabilities.
57 *
58 * Returns: An activated object client or NULL on failure.
59 */
60BonoboObjectClient *
61bonobo_object_activate (const char *iid, gint oaf_flags)
62{
63        CORBA_Environment ev;
64        BonoboObjectClient *object;
65        Bonobo_Unknown      corba_object;
66       
67        g_return_val_if_fail (iid != NULL, NULL);
68
69        /*
70         * We don't want this to do moniker activation too, since we'd
71         * need to break the API to add 'requested_interface' and it's
72         * a different paradigm.
73         */
74        CORBA_exception_init (&ev);
75        corba_object = oaf_activate_from_id ((gchar *) iid, oaf_flags, NULL, &ev);
76
77        if (BONOBO_EX (&ev) || corba_object == CORBA_OBJECT_NIL) {
78                CORBA_exception_free (&ev);
79                return NULL;
80        }
81
82        CORBA_exception_free (&ev);
83       
84        object = gtk_type_new (bonobo_object_client_get_type ());
85
86        bonobo_object_client_construct (object, corba_object);
87
88        return object;
89}
90
91static void
92oaf_activate_async_cb (CORBA_Object activated_object,
93                       const char  *error,
94                       gpointer     user_data)
95{
96        BonoboObjectClientAsyncCallbackData *callback_data =
97                (BonoboObjectClientAsyncCallbackData *) user_data;
98        BonoboObjectClient *object;
99
100        if (activated_object == CORBA_OBJECT_NIL) {
101                callback_data->callback (NULL, error, callback_data->user_data);
102                g_free(callback_data);
103                return;
104        }
105
106        object = gtk_type_new (bonobo_object_client_get_type ());
107        bonobo_object_client_construct (object, activated_object);
108
109        callback_data->callback (object, NULL, callback_data->user_data);
110
111        g_free (callback_data);
112}
113
114/**
115 * bonobo_object_activate_async:
116 * @iid: an OAFIID
117 * @oaf_flags: activation flags
118 * @callback: a callback function
119 * @user_data: user data
120 *
121 *   This activates the object from the IID using oaf; you probably
122 * don't want to do this; instead do capability based activation
123 * using Oaf directly.
124 */
125void
126bonobo_object_activate_async (const char                    *iid,
127                              gint                           oaf_flags,
128                             BonoboObjectClientAsyncCallback callback,
129                             gpointer                        user_data)
130{
131        BonoboObjectClientAsyncCallbackData *callback_data;
132
133        g_return_if_fail (iid != NULL);
134
135        callback_data = g_new0 (BonoboObjectClientAsyncCallbackData, 1);
136        callback_data->callback = callback;
137        callback_data->user_data = user_data;
138
139        oaf_activate_from_id_async ((gchar*) iid, oaf_flags,
140                                    oaf_activate_async_cb, callback_data, NULL);
141}
142
143/**
144 * bonobo_object_client_from_corba:
145 * @corba_object: An existing CORBA object that implements Bonobo_Unknown.
146 *
147 * Wraps the @corba_object CORBA object reference in a BonoboObjectClient
148 * object.  This is typically used if you got a CORBA object yourself and not
149 * through one of the activation routines and you want to have a BonoboObjectClient
150 * handle to use in any of the Bonobo routines.
151 *
152 * Returns: A wrapped BonoboObjectClient.
153 */
154BonoboObjectClient *
155bonobo_object_client_from_corba (Bonobo_Unknown o)
156{
157        BonoboObjectClient *object;
158       
159        g_return_val_if_fail (o != CORBA_OBJECT_NIL, NULL);
160
161        object = gtk_type_new (bonobo_object_client_get_type ());
162        bonobo_object_client_construct (object, o);
163
164        return object;
165}
166
167
168/**
169 * bonobo_object_client_query_interface:
170 * @object: object to query interface of
171 * @interface_desc: interface description
172 * @opt_ev: optional exception environment, or NULL
173 *
174 * Queries the object to see if it implements the interface
175 * described by @interface_desc. Basicaly a thin
176 * Bonobo_Unknown::query_interface wrapper.
177 *
178 * Return value: A valid Bonobo_Unknown reference or
179 *               CORBA_OBJECT_NIL if anything untoward happens.
180 **/
181Bonobo_Unknown
182bonobo_object_client_query_interface (BonoboObjectClient *object,
183                                     const char *interface_desc,
184                                     CORBA_Environment *opt_ev)
185{
186        Bonobo_Unknown      interface;
187        CORBA_Environment *ev, real_ev;
188
189        g_return_val_if_fail (BONOBO_IS_OBJECT_CLIENT (object), CORBA_OBJECT_NIL);
190        g_return_val_if_fail (interface_desc != NULL, CORBA_OBJECT_NIL);
191
192        if (opt_ev)
193                ev = opt_ev;
194        else {
195                ev = &real_ev;
196                CORBA_exception_init (ev);
197        }
198
199        interface = Bonobo_Unknown_queryInterface (BONOBO_OBJREF (object),
200                                                   interface_desc, ev);
201       
202        if (BONOBO_EX (ev)) {
203                bonobo_object_check_env (BONOBO_OBJECT (object),
204                                         BONOBO_OBJREF (object), ev);
205                if (!opt_ev)
206                        CORBA_exception_free (ev);
207
208                return CORBA_OBJECT_NIL;
209        }
210
211        if (!opt_ev)
212                CORBA_exception_free (ev);
213
214        return interface;
215}
216
217/**
218 * bonobo_object_client_has_interface:
219 * @object: object to query interface of
220 * @interface_desc: interface description
221 * @opt_ev: optional exception environment, or NULL
222 *
223 * Queries the object to see if it implements the interface
224 * described by @interface_desc. Basicaly a thin
225 * Bonobo_Unknown::query_interface wrapper.
226 *
227 * Return value: TRUE if the interface is available else FALSE.
228 **/
229gboolean
230bonobo_object_client_has_interface (BonoboObjectClient *object,
231                                   const char *interface_desc,
232                                   CORBA_Environment *opt_ev)
233{
234        Bonobo_Unknown      interface;
235
236        /* safe type checking in query_interface */
237        interface = bonobo_object_client_query_interface (object,
238                                                         interface_desc,
239                                                         opt_ev);
240
241        if (interface != CORBA_OBJECT_NIL) {
242                CORBA_Environment *ev, real_ev;
243
244                if (opt_ev)
245                        ev = opt_ev;
246                else {
247                        ev = &real_ev;
248                        CORBA_exception_init (ev);
249                }
250
251                Bonobo_Unknown_unref  (interface, ev);
252
253                if (BONOBO_EX (ev)) {
254                        bonobo_object_check_env (BONOBO_OBJECT (object),
255                                                 BONOBO_OBJREF (object), ev);
256                        if (!opt_ev)
257                                CORBA_exception_free (ev);
258                        return FALSE;
259                }
260
261                CORBA_Object_release (interface, ev);
262
263                if (BONOBO_EX (ev)) {
264                        bonobo_object_check_env (BONOBO_OBJECT (object),
265                                                 BONOBO_OBJREF (object), ev);
266                        if (!opt_ev)
267                                CORBA_exception_free (ev);
268                        return FALSE;
269                }
270
271                if (!opt_ev)
272                        CORBA_exception_free (ev);
273                return TRUE;
274        } else
275                return FALSE;
276}
277
278void
279bonobo_object_client_ref (BonoboObjectClient *object_client,
280                          BonoboObject       *opt_exception_obj)
281{
282        CORBA_Environment ev;
283        BonoboObject     *object;
284
285        g_return_if_fail (BONOBO_IS_OBJECT (object_client));
286
287        object = BONOBO_OBJECT (object_client);
288
289        CORBA_exception_init (&ev);
290
291        Bonobo_Unknown_ref (object->corba_objref, &ev);
292
293        if (BONOBO_EX (&ev)) {
294                CORBA_exception_free (&ev);
295                bonobo_object_check_env (opt_exception_obj?opt_exception_obj:object,
296                                         object->corba_objref, &ev);
297        }
298
299        CORBA_exception_free (&ev);
300}
301
302void
303bonobo_object_client_unref (BonoboObjectClient *object_client,
304                            BonoboObject       *opt_exception_obj)
305{
306        CORBA_Environment ev;
307        BonoboObject     *object;
308
309        g_return_if_fail (BONOBO_IS_OBJECT (object_client));
310
311        object = BONOBO_OBJECT (object_client);
312
313        CORBA_exception_init (&ev);
314
315        Bonobo_Unknown_unref (object->corba_objref, &ev);
316
317        if (BONOBO_EX (&ev)) {
318                CORBA_exception_free (&ev);
319                bonobo_object_check_env (opt_exception_obj?opt_exception_obj:object,
320                                         object->corba_objref, &ev);
321        }
322
323        CORBA_exception_free (&ev);
324}
325
326static void
327bonobo_object_client_destroy (GtkObject *object)
328{
329        BonoboObject *bonobo_object = BONOBO_OBJECT (object);
330        Bonobo_Unknown objref;
331
332        objref = bonobo_object_corba_objref (bonobo_object);
333        if (objref != CORBA_OBJECT_NIL) {
334                CORBA_Environment ev;
335
336                CORBA_exception_init (&ev);
337                Bonobo_Unknown_unref (objref, &ev);
338                CORBA_exception_free (&ev);
339        }
340
341        GTK_OBJECT_CLASS (bonobo_object_client_parent_class)->destroy (object);
342}
343
344static void
345bonobo_object_client_class_init (BonoboObjectClientClass *klass)
346{
347        GtkObjectClass *object_class = (GtkObjectClass *) klass;
348
349        bonobo_object_client_parent_class = gtk_type_class (bonobo_object_get_type ());
350
351        object_class->destroy = bonobo_object_client_destroy;
352}
353
354/**
355 * bonobo_object_client_get_type:
356 *
357 * Returns: the GtkType for the BonoboObjectClient class.
358 */
359GtkType
360bonobo_object_client_get_type (void)
361{
362        static GtkType type = 0;
363
364        if (!type){
365                GtkTypeInfo info = {
366                        "Handle to remote Bonobo::Unknown",
367                        sizeof (BonoboObjectClient),
368                        sizeof (BonoboObjectClientClass),
369                        (GtkClassInitFunc) bonobo_object_client_class_init,
370                        (GtkObjectInitFunc) NULL,
371                        NULL, /* reserved 1 */
372                        NULL, /* reserved 2 */
373                        (GtkClassInitFunc) NULL
374                };
375
376                type = gtk_type_unique (bonobo_object_get_type (), &info);
377        }
378
379        return type;
380}
Note: See TracBrowser for help on using the repository browser.