File: bonobo-object-client.c

package info (click to toggle)
bonobo 1.0.22-2.2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 13,412 kB
  • ctags: 5,445
  • sloc: ansic: 51,714; sh: 7,733; makefile: 1,425; yacc: 318; xml: 266; sed: 16
file content (394 lines) | stat: -rw-r--r-- 10,330 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * bonobo-object-client.c:
 *   This handles the client-view of a remote Bonobo object.
 *
 * Author:
 *   Miguel de Icaza (miguel@kernel.org)
 *
 * Copyright 1999 Helix Code, Inc.
 */
#include <bonobo/bonobo-object-client.h>
#include <liboaf/liboaf.h>
#include <liboaf/oaf-async.h>
#include <bonobo/bonobo-stream.h>
#include <bonobo/bonobo-exception.h>

/* Internal data structure for bonobo_object_client_activate_async */
typedef struct {
	BonoboObjectClientAsyncCallback callback;
	gpointer                        user_data;
} BonoboObjectClientAsyncCallbackData;

static BonoboObjectClass *bonobo_object_client_parent_class;

/**
 * bonobo_object_client_construct:
 * @object_client: The BonoboObjectClient object to construct
 * @corba_object: The remote CORBA object this object_client refers to
 *
 * Initializes @object_client with the CORBA object for the
 * Bonobo::Unknown interface provided in @corba_object.
 *
 * Returns: the initialized BonoboObjectClient object.
 */
BonoboObjectClient *
bonobo_object_client_construct (BonoboObjectClient *object_client, CORBA_Object corba_object)
{
	g_return_val_if_fail (BONOBO_IS_OBJECT_CLIENT (object_client), NULL);
	g_return_val_if_fail (corba_object != CORBA_OBJECT_NIL, NULL);
	
	BONOBO_OBJECT (object_client)->corba_objref = corba_object;

	return object_client;
}

/**
 * bonobo_object_activate:
 * @iid: an OAFIID
 * @oaf_flags: activation flags
 *
 * This activates the object from the IID using OAF; you probably
 * don't want to do this, you might want to use bonobo_get_object
 * which does object activation through the moniker system.
 * 
 * You might also consider doing property-based activation using the 
 * the OAF-based capabilities. 
 *
 * Returns: An activated object client or NULL on failure.
 */
BonoboObjectClient *
bonobo_object_activate (const char *iid, gint oaf_flags)
{
	CORBA_Environment ev;
	BonoboObjectClient *object;
	Bonobo_Unknown      corba_object;
	
	g_return_val_if_fail (iid != NULL, NULL);

	/*
	 * We don't want this to do moniker activation too, since we'd
	 * need to break the API to add 'requested_interface' and it's
	 * a different paradigm.
	 */
	CORBA_exception_init (&ev);
	corba_object = oaf_activate_from_id ((gchar *) iid, oaf_flags, NULL, &ev);

	if (BONOBO_EX (&ev) || corba_object == CORBA_OBJECT_NIL) {
		CORBA_exception_free (&ev);
		return NULL;
	}

	CORBA_exception_free (&ev);
	
	object = gtk_type_new (bonobo_object_client_get_type ());

	bonobo_object_client_construct (object, corba_object);

	return object;
}

static void
oaf_activate_async_cb (CORBA_Object activated_object,
		       const char  *error,
		       gpointer     user_data)
{
	BonoboObjectClientAsyncCallbackData *callback_data =
		(BonoboObjectClientAsyncCallbackData *) user_data;
	BonoboObjectClient *object;

	if (activated_object == CORBA_OBJECT_NIL) {
		callback_data->callback (NULL, error, callback_data->user_data);
		g_free(callback_data);
		return;
	}

	object = gtk_type_new (bonobo_object_client_get_type ());
	bonobo_object_client_construct (object, activated_object);

	callback_data->callback (object, NULL, callback_data->user_data);

	g_free (callback_data);
}

/**
 * bonobo_object_activate_async:
 * @iid: an OAFIID
 * @oaf_flags: activation flags
 * @callback: a callback function
 * @user_data: user data
 *
 *   This activates the object from the IID using OAF; you probably
 * don't want to do this; instead do capability based activation
 * using OAF directly.
 */
void
bonobo_object_activate_async (const char                    *iid,
			      gint                           oaf_flags,
			     BonoboObjectClientAsyncCallback callback,
			     gpointer                        user_data)
{
	BonoboObjectClientAsyncCallbackData *callback_data;

	g_return_if_fail (iid != NULL);

	callback_data = g_new0 (BonoboObjectClientAsyncCallbackData, 1);
	callback_data->callback = callback;
	callback_data->user_data = user_data;

	oaf_activate_from_id_async ((gchar*) iid, oaf_flags, 
				    oaf_activate_async_cb, callback_data, NULL);
}

/**
 * bonobo_object_client_from_corba:
 * @corba_object: An existing CORBA object that implements Bonobo_Unknown.
 *
 * Wraps the @corba_object CORBA object reference in a BonoboObjectClient
 * object.  This is typically used if you got a CORBA object yourself and not
 * through one of the activation routines and you want to have a BonoboObjectClient
 * handle to use in any of the Bonobo routines. 
 *
 * Returns: A wrapped BonoboObjectClient.
 */
BonoboObjectClient *
bonobo_object_client_from_corba (Bonobo_Unknown o)
{
	BonoboObjectClient *object;
	
	g_return_val_if_fail (o != CORBA_OBJECT_NIL, NULL);

	object = gtk_type_new (bonobo_object_client_get_type ());
	bonobo_object_client_construct (object, o);

	return object;
}


/**
 * bonobo_object_client_query_interface:
 * @object: object to query interface of
 * @interface_desc: interface description
 * @opt_ev: optional exception environment, or NULL
 * 
 * Queries the object to see if it implements the interface
 * described by @interface_desc. Basically a thin
 * Bonobo_Unknown::query_interface wrapper.
 * 
 * Return value: A valid Bonobo_Unknown reference or
 *               CORBA_OBJECT_NIL if anything untoward happens.
 **/
Bonobo_Unknown
bonobo_object_client_query_interface (BonoboObjectClient *object,
				     const char *interface_desc,
				     CORBA_Environment *opt_ev)
{
	Bonobo_Unknown      interface;
	CORBA_Environment *ev, real_ev;

	g_return_val_if_fail (BONOBO_IS_OBJECT_CLIENT (object), CORBA_OBJECT_NIL);
	g_return_val_if_fail (interface_desc != NULL, CORBA_OBJECT_NIL);

	if (opt_ev)
		ev = opt_ev;
	else {
		ev = &real_ev;
		CORBA_exception_init (ev);
	}

	interface = Bonobo_Unknown_queryInterface (BONOBO_OBJREF (object),
						   interface_desc, ev);
	
        if (BONOBO_EX (ev)) {
		bonobo_object_check_env (BONOBO_OBJECT (object),
					 BONOBO_OBJREF (object), ev);
		if (!opt_ev)
			CORBA_exception_free (ev);

                return CORBA_OBJECT_NIL;
	}

	if (!opt_ev)
		CORBA_exception_free (ev);

	return interface;
}

/**
 * bonobo_object_client_has_interface:
 * @object: object to query interface of
 * @interface_desc: interface description
 * @opt_ev: optional exception environment, or NULL
 * 
 * Queries the object to see if it implements the interface
 * described by @interface_desc. Basically a thin
 * Bonobo_Unknown::query_interface wrapper.
 * 
 * Return value: TRUE if the interface is available else FALSE.
 **/
gboolean
bonobo_object_client_has_interface (BonoboObjectClient *object,
				   const char *interface_desc,
				   CORBA_Environment *opt_ev)
{
	Bonobo_Unknown      interface;

	/* safe type checking in query_interface */
	interface = bonobo_object_client_query_interface (object,
							 interface_desc,
							 opt_ev);

	if (interface != CORBA_OBJECT_NIL) {
		CORBA_Environment *ev, real_ev;

		if (opt_ev)
			ev = opt_ev;
		else {
			ev = &real_ev;
			CORBA_exception_init (ev);
		}

		Bonobo_Unknown_unref  (interface, ev);

		if (BONOBO_EX (ev)) {
			bonobo_object_check_env (BONOBO_OBJECT (object),
						 BONOBO_OBJREF (object), ev);
			if (!opt_ev)
				CORBA_exception_free (ev);
			return FALSE;
		}

		CORBA_Object_release (interface, ev);

		if (BONOBO_EX (ev)) {
			bonobo_object_check_env (BONOBO_OBJECT (object),
						 BONOBO_OBJREF (object), ev);
			if (!opt_ev)
				CORBA_exception_free (ev);
			return FALSE;
		}

		if (!opt_ev)
			CORBA_exception_free (ev);
		return TRUE;
	} else
		return FALSE;
}

/**
 * bonobo_object_client_ref:
 * @object_client: the object client
 * @opt_exception_obj: optional CORBA exception environment
 * 
 * Increments the Bonobo ref count on the remote object.
 **/
void
bonobo_object_client_ref (BonoboObjectClient *object_client,
			  BonoboObject       *opt_exception_obj)
{
	CORBA_Environment ev;
	BonoboObject     *object;

	g_return_if_fail (BONOBO_IS_OBJECT (object_client));

	object = BONOBO_OBJECT (object_client);

	CORBA_exception_init (&ev);

	Bonobo_Unknown_ref (object->corba_objref, &ev);

	if (BONOBO_EX (&ev)) {
		CORBA_exception_free (&ev);
		bonobo_object_check_env (opt_exception_obj?opt_exception_obj:object,
					 object->corba_objref, &ev);
	}

	CORBA_exception_free (&ev);
}

/**
 * bonobo_object_client_unref:
 * @object_client: the object client
 * @opt_exception_obj: optional CORBA exception environment
 * 
 * Decrements the Bonobo ref count on the remote object.
 **/
void
bonobo_object_client_unref (BonoboObjectClient *object_client,
			    BonoboObject       *opt_exception_obj)
{
	CORBA_Environment ev;
	BonoboObject     *object;

	g_return_if_fail (BONOBO_IS_OBJECT (object_client));

	object = BONOBO_OBJECT (object_client);

	CORBA_exception_init (&ev);

	Bonobo_Unknown_unref (object->corba_objref, &ev);

	if (BONOBO_EX (&ev)) {
		CORBA_exception_free (&ev);
		bonobo_object_check_env (opt_exception_obj?opt_exception_obj:object,
					 object->corba_objref, &ev);
	}

	CORBA_exception_free (&ev);
}

static void
bonobo_object_client_destroy (GtkObject *object)
{
	BonoboObject *bonobo_object = BONOBO_OBJECT (object);
	Bonobo_Unknown objref;

	objref = bonobo_object_corba_objref (bonobo_object);
	if (objref != CORBA_OBJECT_NIL) {
		CORBA_Environment ev;

		CORBA_exception_init (&ev);
		Bonobo_Unknown_unref (objref, &ev);
		CORBA_exception_free (&ev);
	}

	GTK_OBJECT_CLASS (bonobo_object_client_parent_class)->destroy (object);
}

static void
bonobo_object_client_class_init (BonoboObjectClientClass *klass)
{
	GtkObjectClass *object_class = (GtkObjectClass *) klass;

	bonobo_object_client_parent_class = gtk_type_class (bonobo_object_get_type ());

	object_class->destroy = bonobo_object_client_destroy;
}

/**
 * bonobo_object_client_get_type:
 *
 * Returns: the GtkType for the BonoboObjectClient class.
 */
GtkType
bonobo_object_client_get_type (void)
{
	static GtkType type = 0;

	if (!type){
		GtkTypeInfo info = {
			"Handle to remote Bonobo::Unknown",
			sizeof (BonoboObjectClient),
			sizeof (BonoboObjectClientClass),
			(GtkClassInitFunc) bonobo_object_client_class_init,
			(GtkObjectInitFunc) NULL,
			NULL, /* reserved 1 */
			NULL, /* reserved 2 */
			(GtkClassInitFunc) NULL
		};

		type = gtk_type_unique (bonobo_object_get_type (), &info);
	}

	return type;
}