File: bonobo-property.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 (278 lines) | stat: -rw-r--r-- 7,259 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
/**
 * Bonobo property object implementation.
 *
 * Author:
 *    Nat Friedman (nat@nat.org)
 *
 * Copyright 1999, 2000 Helix Code, Inc.
 */

#include <config.h>
#include <bonobo/bonobo-main.h>
#include <bonobo/bonobo-exception.h>
#include <bonobo/bonobo-property-bag.h>

typedef struct {
	POA_Bonobo_Property		 prop;
	BonoboPropertyBag		*pb;
	BonoboTransient                 *transient;
	char				*property_name;
} BonoboPropertyServant;

static CORBA_char *
impl_Bonobo_Property_getName (PortableServer_Servant servant,
			       CORBA_Environment *ev)
{
	BonoboPropertyServant *ps = (BonoboPropertyServant *) servant;

	return CORBA_string_dup (ps->property_name);
}

static CORBA_TypeCode
impl_Bonobo_Property_getType (PortableServer_Servant servant,
			       CORBA_Environment *ev)
{
	BonoboPropertyServant *ps = (BonoboPropertyServant *) servant;
	BonoboArgType          type;

	type = bonobo_property_bag_get_property_type (ps->pb, ps->property_name, ev);
	/* FIXME: we need to handle obscure cases like non existance of the property */

	return (CORBA_TypeCode) CORBA_Object_duplicate ((CORBA_Object) (type), ev);
}

static CORBA_any *
impl_Bonobo_Property_getValue (PortableServer_Servant servant,
				CORBA_Environment *ev)
{
	BonoboPropertyServant *ps = (BonoboPropertyServant *) servant;

	return bonobo_property_bag_get_value (ps->pb, ps->property_name, ev);
}

static void
impl_Bonobo_Property_setValue (PortableServer_Servant servant,
				const CORBA_any       *any,
				CORBA_Environment     *ev)
{
	BonoboPropertyServant *ps = (BonoboPropertyServant *) servant;

	bonobo_property_bag_set_value (ps->pb, ps->property_name, any, ev);
}

static CORBA_any *
impl_Bonobo_Property_getDefault (PortableServer_Servant servant,
				  CORBA_Environment *ev)
{
	BonoboPropertyServant *ps = (BonoboPropertyServant *) servant;

	return bonobo_property_bag_get_default (ps->pb, ps->property_name, ev);
}

static CORBA_char *
impl_Bonobo_Property_getDocString (PortableServer_Servant servant,
				     CORBA_Environment *ev)
{
	BonoboPropertyServant *ps = (BonoboPropertyServant *) servant;

	return CORBA_string_dup (bonobo_property_bag_get_docstring (ps->pb, 
		ps->property_name, ev));
}


static CORBA_long
impl_Bonobo_Property_getFlags (PortableServer_Servant servant,
				CORBA_Environment *ev)
{
	BonoboPropertyServant *ps = (BonoboPropertyServant *) servant;

	return bonobo_property_bag_get_flags (ps->pb, ps->property_name, ev);
}

static Bonobo_EventSource_ListenerId
impl_Bonobo_Property_addListener (PortableServer_Servant servant,
				  const Bonobo_Listener  l,
				  CORBA_Environment     *ev)
{
	BonoboPropertyServant *ps = (BonoboPropertyServant *) servant;
	Bonobo_Unknown corba_es;
	Bonobo_EventSource_ListenerId id = 0;
	char *mask;

	corba_es = BONOBO_OBJREF (ps->pb->es);

	mask = g_strdup_printf ("Bonobo/Property:change:%s", 
				ps->property_name);

	id = Bonobo_EventSource_addListenerWithMask (corba_es, l, mask, ev); 

	g_free (mask);

	return id;
}

static void
impl_Bonobo_Property_removeListener (PortableServer_Servant servant,
				     const Bonobo_EventSource_ListenerId id,
				     CORBA_Environment     *ev)
{
	BonoboPropertyServant *ps = (BonoboPropertyServant *) servant;
	Bonobo_Unknown corba_es;

	corba_es = BONOBO_OBJREF (ps->pb->es);

	Bonobo_EventSource_removeListener (corba_es, id, ev); 
}

static POA_Bonobo_Property__epv *
bonobo_property_get_epv (void)
{
	static POA_Bonobo_Property__epv *epv = NULL;

	if (epv != NULL)
		return epv;

	epv = g_new0 (POA_Bonobo_Property__epv, 1);

	epv->getName        = impl_Bonobo_Property_getName;
	epv->getType        = impl_Bonobo_Property_getType;
	epv->getValue       = impl_Bonobo_Property_getValue;
	epv->setValue       = impl_Bonobo_Property_setValue;
	epv->getDefault     = impl_Bonobo_Property_getDefault;
	epv->getDocString   = impl_Bonobo_Property_getDocString;
	epv->getFlags       = impl_Bonobo_Property_getFlags;
	epv->addListener    = impl_Bonobo_Property_addListener;
	epv->removeListener = impl_Bonobo_Property_removeListener;

	return epv;
}

static void
impl_Bonobo_Property_ref (PortableServer_Servant servant, 
			  CORBA_Environment *ev)
{
	/* nothing to do */
}

static void
impl_Bonobo_Property_unref (PortableServer_Servant servant, 
			    CORBA_Environment *ev)
{
	/* nothing to do */
}

static CORBA_Object
impl_Bonobo_Property_queryInterface (PortableServer_Servant  servant,
				     const CORBA_char       *repoid,
				     CORBA_Environment      *ev)
{
	BonoboPropertyServant *ps = (BonoboPropertyServant *) servant;

	if (!strcmp (repoid, "IDL:Bonobo/Property:1.0"))
		return bonobo_transient_create_objref (ps->transient,
			"IDL:Bonobo/Property:1.0", ps->property_name, 
			ev);
	else
		return CORBA_OBJECT_NIL;
}

static POA_Bonobo_Unknown__epv *
bonobo_property_get_unknown_epv (void)
{
	POA_Bonobo_Unknown__epv *epv;

	epv = g_new0 (POA_Bonobo_Unknown__epv, 1);

	epv->ref            = impl_Bonobo_Property_ref;
	epv->unref          = impl_Bonobo_Property_unref;
	epv->queryInterface = impl_Bonobo_Property_queryInterface;

	return epv;
}

static POA_Bonobo_Property__vepv *
bonobo_property_get_vepv (void)
{
	static POA_Bonobo_Property__vepv *vepv = NULL;

	if (vepv != NULL)
		return vepv;

	vepv = g_new0 (POA_Bonobo_Property__vepv, 1);

	vepv->Bonobo_Property_epv = bonobo_property_get_epv ();
	vepv->Bonobo_Unknown_epv = bonobo_property_get_unknown_epv ();
	
	return vepv;
}

PortableServer_Servant
bonobo_property_servant_new (PortableServer_POA     poa,
			     BonoboTransient        *bt,
			     char                   *property_name,
			     void                   *callback_data)
{
	BonoboPropertyServant	*servant;
	BonoboPropertyBag       *pb = (BonoboPropertyBag *)callback_data;
	CORBA_Environment        ev;

	g_return_val_if_fail (pb != NULL, NULL);
	g_return_val_if_fail (bt != NULL, NULL);
	g_return_val_if_fail (BONOBO_IS_PROPERTY_BAG (pb), NULL);
	g_return_val_if_fail (property_name != NULL, NULL);

	/*
	 * Verify that the specified property exists.
	 */
	if (! bonobo_property_bag_has_property (pb, property_name))
		return CORBA_OBJECT_NIL;

	CORBA_exception_init (&ev);

	/*
	 * Create a transient servant for the property.
	 */
	servant = g_new0 (BonoboPropertyServant, 1);

	servant->property_name = g_strdup (property_name);
	servant->transient = bt;
	servant->pb = pb;

	((POA_Bonobo_Property *) servant)->vepv = bonobo_property_get_vepv ();
	
	POA_Bonobo_Property__init ((PortableServer_Servant) servant, &ev);
	if (BONOBO_EX (&ev)) {
		g_warning ("BonoboProperty: Could not initialize Property servant");
		g_free (servant->property_name);
		g_free (servant);
		CORBA_exception_free (&ev);
		return CORBA_OBJECT_NIL;
	}

	CORBA_exception_free (&ev);

	return servant;
}

void
bonobo_property_servant_destroy (PortableServer_Servant  servant,
				 void                   *callback_data)
{
	CORBA_Environment ev;

	g_return_if_fail (servant != NULL);

	CORBA_exception_init (&ev);

	POA_Bonobo_Property__fini ((PortableServer_Servant) servant, &ev);
	if (BONOBO_EX (&ev)) {
		g_warning ("BonoboProperty: Could not deconstruct Property servant");
		CORBA_exception_free (&ev);
		return;
	}

	CORBA_exception_free (&ev);

	g_free (((BonoboPropertyServant *) servant)->property_name);
	g_free (servant);
}