1 | /* |
---|
2 | * bonobo-property-bag-client.c: C sugar for property bags. |
---|
3 | * |
---|
4 | * Authors: |
---|
5 | * Nat Friedman (nat@ximian.com) |
---|
6 | * Michael Meeks (michael@ximian.com) |
---|
7 | * |
---|
8 | * Copyright 1999, 2001 Ximian, Inc. |
---|
9 | */ |
---|
10 | #include <config.h> |
---|
11 | #include <stdarg.h> |
---|
12 | #include <bonobo/bonobo-exception.h> |
---|
13 | #include <bonobo/bonobo-property-bag-client.h> |
---|
14 | |
---|
15 | static CORBA_unsigned_long |
---|
16 | get_kind (CORBA_TypeCode tc) |
---|
17 | { |
---|
18 | while (tc->kind == CORBA_tk_alias) |
---|
19 | tc = tc->subtypes [0]; |
---|
20 | |
---|
21 | return tc->kind; |
---|
22 | } |
---|
23 | |
---|
24 | /** |
---|
25 | * bonobo_property_bag_client_get_properties: |
---|
26 | * @pb: A #Bonobo_PropertyBag which is bound to a remote |
---|
27 | * #Bonobo_PropertyBag. |
---|
28 | * @ev: optional CORBA exception environment or NULL |
---|
29 | * |
---|
30 | * Returns: A #GList filled with #Bonobo_Property CORBA object |
---|
31 | * references for all of the properties stored in the remote |
---|
32 | * #BonoboPropertyBag. |
---|
33 | */ |
---|
34 | GList * |
---|
35 | bonobo_property_bag_client_get_properties (Bonobo_PropertyBag pb, |
---|
36 | CORBA_Environment *ev) |
---|
37 | { |
---|
38 | Bonobo_PropertyList *props; |
---|
39 | GList *prop_list; |
---|
40 | int i; |
---|
41 | CORBA_Environment *real_ev, tmp_ev; |
---|
42 | |
---|
43 | g_return_val_if_fail (pb != CORBA_OBJECT_NIL, NULL); |
---|
44 | |
---|
45 | if (ev) |
---|
46 | real_ev = ev; |
---|
47 | else { |
---|
48 | CORBA_exception_init (&tmp_ev); |
---|
49 | real_ev = &tmp_ev; |
---|
50 | } |
---|
51 | |
---|
52 | props = Bonobo_PropertyBag_getProperties (pb, real_ev); |
---|
53 | if (BONOBO_EX (real_ev)) { |
---|
54 | if (!ev) |
---|
55 | CORBA_exception_free (&tmp_ev); |
---|
56 | return NULL; |
---|
57 | } |
---|
58 | |
---|
59 | prop_list = NULL; |
---|
60 | for (i = 0; i < props->_length; i ++) { |
---|
61 | |
---|
62 | /* |
---|
63 | * FIXME: Is it necessary to duplicate these? I'm |
---|
64 | * inclined to think that it isn't. |
---|
65 | */ |
---|
66 | prop_list = g_list_prepend ( |
---|
67 | prop_list, |
---|
68 | CORBA_Object_duplicate (props->_buffer [i], real_ev)); |
---|
69 | |
---|
70 | if (BONOBO_EX (real_ev)) { |
---|
71 | CORBA_Environment ev2; |
---|
72 | GList *curr; |
---|
73 | |
---|
74 | CORBA_exception_init (&ev2); |
---|
75 | |
---|
76 | for (curr = prop_list; curr != NULL; curr = curr->next) { |
---|
77 | CORBA_Object_release ((CORBA_Object) curr->data, &ev2); |
---|
78 | CORBA_exception_free (&ev2); |
---|
79 | } |
---|
80 | |
---|
81 | g_list_free (prop_list); |
---|
82 | |
---|
83 | if (!ev) |
---|
84 | CORBA_exception_free (&tmp_ev); |
---|
85 | return NULL; |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | CORBA_free (props); |
---|
90 | |
---|
91 | if (!ev) |
---|
92 | CORBA_exception_free (&tmp_ev); |
---|
93 | |
---|
94 | return prop_list; |
---|
95 | } |
---|
96 | |
---|
97 | /** |
---|
98 | * bonobo_property_bag_client_free_properties: |
---|
99 | * @list: A #GList containing Bonobo_Property corba objrefs (as |
---|
100 | * produced by bonobo_property_bag_client_get_properties(), for |
---|
101 | * example). |
---|
102 | * |
---|
103 | * Releases the CORBA Objrefs stored in @list and frees the list. |
---|
104 | */ |
---|
105 | void |
---|
106 | bonobo_property_bag_client_free_properties (GList *list) |
---|
107 | { |
---|
108 | GList *l; |
---|
109 | |
---|
110 | if (list == NULL) |
---|
111 | return; |
---|
112 | |
---|
113 | for (l = list; l != NULL; l = l->next) { |
---|
114 | CORBA_Environment ev; |
---|
115 | Bonobo_Property prop; |
---|
116 | |
---|
117 | prop = (Bonobo_Property) l->data; |
---|
118 | |
---|
119 | CORBA_exception_init (&ev); |
---|
120 | |
---|
121 | CORBA_Object_release (prop, &ev); |
---|
122 | |
---|
123 | if (BONOBO_EX (&ev)) { |
---|
124 | g_warning ("bonobo_property_bag_client_free_properties: Exception releasing objref!"); |
---|
125 | CORBA_exception_free (&ev); |
---|
126 | return; |
---|
127 | } |
---|
128 | |
---|
129 | CORBA_exception_free (&ev); |
---|
130 | } |
---|
131 | |
---|
132 | g_list_free (list); |
---|
133 | } |
---|
134 | |
---|
135 | /** |
---|
136 | * bonobo_property_bag_client_get_property_names: |
---|
137 | * @pb: A #Bonobo_PropertyBag which is bound to a remote |
---|
138 | * #Bonobo_PropertyBag. |
---|
139 | * @ev: optional CORBA exception environment or NULL |
---|
140 | * |
---|
141 | * This function exists as a convenience, so that you don't have to |
---|
142 | * iterate through all of the #Bonobo_Property objects in order to get |
---|
143 | * a list of their names. It should be used in place of such an |
---|
144 | * iteration, as it uses fewer resources on the remote |
---|
145 | * #BonoboPropertyBag. |
---|
146 | * |
---|
147 | * Returns: A #GList filled with strings containing the names of all |
---|
148 | * the properties stored in the remote #BonoboPropertyBag. |
---|
149 | */ |
---|
150 | GList * |
---|
151 | bonobo_property_bag_client_get_property_names (Bonobo_PropertyBag pb, |
---|
152 | CORBA_Environment *ev) |
---|
153 | { |
---|
154 | Bonobo_PropertyNames *names; |
---|
155 | GList *name_list; |
---|
156 | int i; |
---|
157 | CORBA_Environment *real_ev, tmp_ev; |
---|
158 | |
---|
159 | g_return_val_if_fail (pb != CORBA_OBJECT_NIL, NULL); |
---|
160 | |
---|
161 | if (ev) |
---|
162 | real_ev = ev; |
---|
163 | else { |
---|
164 | CORBA_exception_init (&tmp_ev); |
---|
165 | real_ev = &tmp_ev; |
---|
166 | } |
---|
167 | |
---|
168 | names = Bonobo_PropertyBag_getPropertyNames (pb, real_ev); |
---|
169 | |
---|
170 | if (BONOBO_EX (real_ev)) { |
---|
171 | if (!ev) |
---|
172 | CORBA_exception_free (&tmp_ev); |
---|
173 | |
---|
174 | return NULL; |
---|
175 | } |
---|
176 | |
---|
177 | name_list = NULL; |
---|
178 | for (i = 0; i < names->_length; i ++) { |
---|
179 | char *name; |
---|
180 | |
---|
181 | name = g_strdup (names->_buffer [i]); |
---|
182 | name_list = g_list_prepend (name_list, name); |
---|
183 | } |
---|
184 | |
---|
185 | CORBA_free (names); |
---|
186 | |
---|
187 | if (!ev) |
---|
188 | CORBA_exception_free (&tmp_ev); |
---|
189 | |
---|
190 | return name_list; |
---|
191 | } |
---|
192 | |
---|
193 | /** |
---|
194 | * bonobo_property_bag_client_get_property: |
---|
195 | * @pb: A Bonobo_PropertyBag which is associated with a remote |
---|
196 | * BonoboPropertyBag. |
---|
197 | * @name: A string containing the name of the property which is to |
---|
198 | * be fetched. |
---|
199 | * @ev: optional CORBA exception environment or NULL |
---|
200 | * |
---|
201 | * Returns: A #Bonobo_Property CORBA object reference corresponding |
---|
202 | * to the requested property. |
---|
203 | * |
---|
204 | */ |
---|
205 | Bonobo_Property |
---|
206 | bonobo_property_bag_client_get_property (Bonobo_PropertyBag pb, |
---|
207 | const char *property_name, |
---|
208 | CORBA_Environment *ev) |
---|
209 | { |
---|
210 | Bonobo_Property prop; |
---|
211 | CORBA_Environment *real_ev, tmp_ev; |
---|
212 | |
---|
213 | if (ev) |
---|
214 | real_ev = ev; |
---|
215 | else { |
---|
216 | CORBA_exception_init (&tmp_ev); |
---|
217 | real_ev = &tmp_ev; |
---|
218 | } |
---|
219 | |
---|
220 | g_return_val_if_fail (pb != CORBA_OBJECT_NIL, NULL); |
---|
221 | |
---|
222 | prop = Bonobo_PropertyBag_getPropertyByName (pb, property_name, real_ev); |
---|
223 | |
---|
224 | if (BONOBO_EX (real_ev)) |
---|
225 | prop = CORBA_OBJECT_NIL; |
---|
226 | |
---|
227 | if (!ev) |
---|
228 | CORBA_exception_free (&tmp_ev); |
---|
229 | |
---|
230 | return prop; |
---|
231 | } |
---|
232 | |
---|
233 | |
---|
234 | /* |
---|
235 | * Bonobo Property streaming functions. |
---|
236 | */ |
---|
237 | |
---|
238 | /** |
---|
239 | * bonobo_property_bag_client_persist: |
---|
240 | * @pb: A #Bonobo_PropertyBag object which is bound to a remote |
---|
241 | * #Bonobo_PropertyBag server. |
---|
242 | * @stream: A #BonoboStream into which the data in @pb will be written. |
---|
243 | * @ev: optional CORBA exception environment or NULL |
---|
244 | * |
---|
245 | * Reads the property data stored in the #Bonobo_PropertyBag to which |
---|
246 | * @pb is bound and streams it into @stream. The typical use for |
---|
247 | * this function is to save the property data for a given Bonobo |
---|
248 | * Control into a persistent store to which @stream is attached. |
---|
249 | */ |
---|
250 | void |
---|
251 | bonobo_property_bag_client_persist (Bonobo_PropertyBag pb, |
---|
252 | Bonobo_Stream stream, |
---|
253 | CORBA_Environment *ev) |
---|
254 | { |
---|
255 | Bonobo_PersistStream persist; |
---|
256 | |
---|
257 | g_return_if_fail (ev != NULL); |
---|
258 | g_return_if_fail (pb != CORBA_OBJECT_NIL); |
---|
259 | g_return_if_fail (stream != CORBA_OBJECT_NIL); |
---|
260 | |
---|
261 | persist = Bonobo_Unknown_queryInterface (pb, "IDL:Bonobo/PersistStream:1.0", ev); |
---|
262 | |
---|
263 | if (BONOBO_EX (ev) || |
---|
264 | persist == CORBA_OBJECT_NIL) { |
---|
265 | g_warning ("Bonobo_PropertyBag : No PersistStream interface " |
---|
266 | "found on remote PropertyBag!"); |
---|
267 | return; |
---|
268 | } |
---|
269 | |
---|
270 | Bonobo_PersistStream_save (persist, stream, "", ev); |
---|
271 | |
---|
272 | if (BONOBO_EX (ev)) { |
---|
273 | g_warning ("Bonobo_PropertyBag : Exception caught while persisting " |
---|
274 | "remote PropertyBag!"); |
---|
275 | return; |
---|
276 | } |
---|
277 | |
---|
278 | bonobo_object_release_unref (persist, ev); |
---|
279 | } |
---|
280 | |
---|
281 | /** |
---|
282 | * bonobo_property_bag_client_depersist: |
---|
283 | * @pb: the property bag to persist |
---|
284 | * @stream: the stream to persist to |
---|
285 | * @ev: optional CORBA exception environment or NULL |
---|
286 | * |
---|
287 | * Serializes the property bag @pb to the @stream, |
---|
288 | * using the PersistStream interface associated with the |
---|
289 | * PropertyBag. |
---|
290 | **/ |
---|
291 | void |
---|
292 | bonobo_property_bag_client_depersist (Bonobo_PropertyBag pb, |
---|
293 | Bonobo_Stream stream, |
---|
294 | CORBA_Environment *ev) |
---|
295 | { |
---|
296 | Bonobo_PersistStream persist; |
---|
297 | |
---|
298 | g_return_if_fail (ev != NULL); |
---|
299 | g_return_if_fail (pb != CORBA_OBJECT_NIL); |
---|
300 | g_return_if_fail (stream != CORBA_OBJECT_NIL); |
---|
301 | |
---|
302 | persist = Bonobo_Unknown_queryInterface ( |
---|
303 | pb, "IDL:Bonobo/PersistStream:1.0", ev); |
---|
304 | |
---|
305 | if (BONOBO_EX (ev) || |
---|
306 | persist == CORBA_OBJECT_NIL) { |
---|
307 | g_warning ("Bonobo_PropertyBag : No PersistStream interface " |
---|
308 | "found on remote PropertyBag!"); |
---|
309 | return; |
---|
310 | } |
---|
311 | |
---|
312 | Bonobo_PersistStream_load (persist, stream, "", ev); |
---|
313 | |
---|
314 | if (BONOBO_EX (ev)) { |
---|
315 | g_warning ("Bonobo_PropertyBag : Exception caught while persisting " |
---|
316 | "remote PropertyBag!"); |
---|
317 | return; |
---|
318 | } |
---|
319 | |
---|
320 | bonobo_object_release_unref (persist, ev); |
---|
321 | } |
---|
322 | |
---|
323 | |
---|
324 | /* |
---|
325 | * Property convenience functions. |
---|
326 | */ |
---|
327 | |
---|
328 | /** |
---|
329 | * bonobo_property_bag_client_get_property_type: |
---|
330 | * @pb: the property bag |
---|
331 | * @propname: the property name |
---|
332 | * @ev: optional CORBA exception environment or NULL |
---|
333 | * |
---|
334 | * Finds the typecode associated with the property in @pb of name @propname |
---|
335 | * |
---|
336 | * Return value: the TypeCode for property @name or CORBA_OBJECT_NIL |
---|
337 | **/ |
---|
338 | CORBA_TypeCode |
---|
339 | bonobo_property_bag_client_get_property_type (Bonobo_PropertyBag pb, |
---|
340 | const char *propname, |
---|
341 | CORBA_Environment *ev) |
---|
342 | { |
---|
343 | Bonobo_Property prop; |
---|
344 | CORBA_TypeCode tc; |
---|
345 | CORBA_Environment *real_ev, tmp_ev; |
---|
346 | |
---|
347 | if (ev) |
---|
348 | real_ev = ev; |
---|
349 | else { |
---|
350 | CORBA_exception_init (&tmp_ev); |
---|
351 | real_ev = &tmp_ev; |
---|
352 | } |
---|
353 | |
---|
354 | g_return_val_if_fail (propname != NULL, (CORBA_TypeCode) TC_null); |
---|
355 | g_return_val_if_fail (pb != CORBA_OBJECT_NIL, (CORBA_TypeCode) TC_null); |
---|
356 | |
---|
357 | prop = bonobo_property_bag_client_get_property (pb, propname, real_ev); |
---|
358 | |
---|
359 | if (prop == CORBA_OBJECT_NIL) { |
---|
360 | if (!ev) { |
---|
361 | g_warning ("prop is NIL"); |
---|
362 | CORBA_exception_free (&tmp_ev); |
---|
363 | } |
---|
364 | return (CORBA_TypeCode) TC_null; |
---|
365 | } |
---|
366 | |
---|
367 | tc = Bonobo_Property_getType (prop, real_ev); |
---|
368 | |
---|
369 | if (BONOBO_EX (real_ev)) { |
---|
370 | g_warning ("bonobo_property_bag_client_get_property_type: Exception getting TypeCode!"); |
---|
371 | |
---|
372 | CORBA_Object_release (prop, real_ev); |
---|
373 | |
---|
374 | if (!ev) |
---|
375 | CORBA_exception_free (&tmp_ev); |
---|
376 | |
---|
377 | return (CORBA_TypeCode) TC_null; |
---|
378 | } |
---|
379 | |
---|
380 | CORBA_Object_release (prop, real_ev); |
---|
381 | |
---|
382 | if (!ev) |
---|
383 | CORBA_exception_free (&tmp_ev); |
---|
384 | |
---|
385 | return tc; |
---|
386 | } |
---|
387 | |
---|
388 | typedef enum { |
---|
389 | FIELD_VALUE, |
---|
390 | FIELD_DEFAULT |
---|
391 | } PropUtilFieldType; |
---|
392 | |
---|
393 | static BonoboArg * |
---|
394 | bonobo_property_bag_client_get_field_any (Bonobo_PropertyBag pb, |
---|
395 | const char *propname, |
---|
396 | PropUtilFieldType field, |
---|
397 | CORBA_Environment *ev) |
---|
398 | |
---|
399 | { |
---|
400 | Bonobo_Property prop; |
---|
401 | CORBA_any *any; |
---|
402 | CORBA_Environment *real_ev, tmp_ev; |
---|
403 | |
---|
404 | g_return_val_if_fail (propname != NULL, NULL); |
---|
405 | g_return_val_if_fail (pb != CORBA_OBJECT_NIL, NULL); |
---|
406 | |
---|
407 | if (ev) |
---|
408 | real_ev = ev; |
---|
409 | else { |
---|
410 | CORBA_exception_init (&tmp_ev); |
---|
411 | real_ev = &tmp_ev; |
---|
412 | } |
---|
413 | |
---|
414 | prop = bonobo_property_bag_client_get_property (pb, propname, real_ev); |
---|
415 | |
---|
416 | if (prop == CORBA_OBJECT_NIL) { |
---|
417 | if (!ev) { |
---|
418 | g_warning ("prop == NIL"); |
---|
419 | CORBA_exception_free (&tmp_ev); |
---|
420 | } |
---|
421 | return NULL; |
---|
422 | } |
---|
423 | |
---|
424 | if (field == FIELD_VALUE) |
---|
425 | any = Bonobo_Property_getValue (prop, real_ev); |
---|
426 | else |
---|
427 | any = Bonobo_Property_getDefault (prop, real_ev); |
---|
428 | |
---|
429 | if (BONOBO_EX (real_ev)) { |
---|
430 | g_warning ("bonobo_property_bag_client_get_field_any: Exception getting property value!"); |
---|
431 | CORBA_Object_release (prop, real_ev); |
---|
432 | if (!ev) |
---|
433 | CORBA_exception_free (&tmp_ev); |
---|
434 | |
---|
435 | return NULL; |
---|
436 | } |
---|
437 | |
---|
438 | CORBA_Object_release (prop, real_ev); |
---|
439 | |
---|
440 | if (!ev) |
---|
441 | CORBA_exception_free (&tmp_ev); |
---|
442 | |
---|
443 | return any; |
---|
444 | } |
---|
445 | |
---|
446 | #define MAKE_BONOBO_PROPERTY_BAG_CLIENT_GET_FIELD(type,def,corbatype,tk) \ |
---|
447 | static type \ |
---|
448 | bonobo_property_bag_client_get_field_##type (Bonobo_PropertyBag pb, \ |
---|
449 | const char *propname, \ |
---|
450 | PropUtilFieldType field, \ |
---|
451 | CORBA_Environment *ev) \ |
---|
452 | { \ |
---|
453 | CORBA_any *any; \ |
---|
454 | type d; \ |
---|
455 | \ |
---|
456 | g_return_val_if_fail (pb != NULL, (def)); \ |
---|
457 | g_return_val_if_fail (propname != NULL, (def)); \ |
---|
458 | g_return_val_if_fail (pb != CORBA_OBJECT_NIL, (def)); \ |
---|
459 | \ |
---|
460 | any = bonobo_property_bag_client_get_field_any ( \ |
---|
461 | pb, propname, field, ev); \ |
---|
462 | \ |
---|
463 | if (any == NULL) \ |
---|
464 | return 0.0; \ |
---|
465 | \ |
---|
466 | if (get_kind (any->_type) != tk) { \ |
---|
467 | g_warning ("Assertion `any->_type->kind == tk' failed"); \ |
---|
468 | CORBA_any__free (any, NULL, TRUE); \ |
---|
469 | return (def); \ |
---|
470 | } \ |
---|
471 | \ |
---|
472 | d = *(corbatype *) any->_value; \ |
---|
473 | \ |
---|
474 | CORBA_any__free (any, NULL, TRUE); \ |
---|
475 | \ |
---|
476 | return d; \ |
---|
477 | } |
---|
478 | |
---|
479 | MAKE_BONOBO_PROPERTY_BAG_CLIENT_GET_FIELD (gboolean, 0, CORBA_boolean, CORBA_tk_boolean); |
---|
480 | MAKE_BONOBO_PROPERTY_BAG_CLIENT_GET_FIELD (gint , 0, CORBA_long, CORBA_tk_long); |
---|
481 | MAKE_BONOBO_PROPERTY_BAG_CLIENT_GET_FIELD (glong, 0, CORBA_long, CORBA_tk_long); |
---|
482 | MAKE_BONOBO_PROPERTY_BAG_CLIENT_GET_FIELD (gfloat, 0.0, CORBA_float, CORBA_tk_float); |
---|
483 | MAKE_BONOBO_PROPERTY_BAG_CLIENT_GET_FIELD (gdouble, 0.0, CORBA_double, CORBA_tk_double); |
---|
484 | |
---|
485 | static char * |
---|
486 | bonobo_property_bag_client_get_field_string (Bonobo_PropertyBag pb, |
---|
487 | const char *propname, |
---|
488 | PropUtilFieldType field, |
---|
489 | CORBA_Environment *ev) |
---|
490 | { |
---|
491 | CORBA_any *any; |
---|
492 | char *str; |
---|
493 | |
---|
494 | g_return_val_if_fail (pb != CORBA_OBJECT_NIL, NULL); |
---|
495 | g_return_val_if_fail (propname != NULL, NULL); |
---|
496 | |
---|
497 | any = bonobo_property_bag_client_get_field_any ( |
---|
498 | pb, propname, field, ev); |
---|
499 | |
---|
500 | if (any == NULL) |
---|
501 | return NULL; |
---|
502 | |
---|
503 | if (get_kind (any->_type) != CORBA_tk_string) { |
---|
504 | g_warning ("assertion failed: `any->_type->kind == CORBA_tk_string'"); |
---|
505 | CORBA_any__free (any, NULL, TRUE); |
---|
506 | return NULL; |
---|
507 | } |
---|
508 | |
---|
509 | str = g_strdup (*(char **) any->_value); |
---|
510 | |
---|
511 | CORBA_any__free (any, NULL, TRUE); |
---|
512 | |
---|
513 | return str; |
---|
514 | } |
---|
515 | |
---|
516 | /* |
---|
517 | * This macro generates two functions; that to return the value |
---|
518 | * of a property and that to get its default; essentialy these |
---|
519 | * chain on to the shared bonobo_property_bag_client_get_field_gboolean |
---|
520 | * function. |
---|
521 | */ |
---|
522 | #define MAKE_BONOBO_PROPERTY_BAG_CLIENT_PAIR(type,rettype) \ |
---|
523 | rettype \ |
---|
524 | bonobo_property_bag_client_get_value_##type (Bonobo_PropertyBag pb, \ |
---|
525 | const char *propname, \ |
---|
526 | CORBA_Environment *ev) \ |
---|
527 | { \ |
---|
528 | return bonobo_property_bag_client_get_field_##type (pb, propname, FIELD_VALUE, ev); \ |
---|
529 | } \ |
---|
530 | \ |
---|
531 | rettype \ |
---|
532 | bonobo_property_bag_client_get_default_##type (Bonobo_PropertyBag pb, \ |
---|
533 | const char *propname, \ |
---|
534 | CORBA_Environment *ev) \ |
---|
535 | { \ |
---|
536 | return bonobo_property_bag_client_get_field_##type (pb, propname, FIELD_DEFAULT, ev); \ |
---|
537 | } |
---|
538 | |
---|
539 | MAKE_BONOBO_PROPERTY_BAG_CLIENT_PAIR(gboolean, gboolean); |
---|
540 | MAKE_BONOBO_PROPERTY_BAG_CLIENT_PAIR(gint, gint); |
---|
541 | MAKE_BONOBO_PROPERTY_BAG_CLIENT_PAIR(glong, glong); |
---|
542 | MAKE_BONOBO_PROPERTY_BAG_CLIENT_PAIR(gfloat, gfloat); |
---|
543 | MAKE_BONOBO_PROPERTY_BAG_CLIENT_PAIR(gdouble, gdouble); |
---|
544 | MAKE_BONOBO_PROPERTY_BAG_CLIENT_PAIR(string, char *); |
---|
545 | MAKE_BONOBO_PROPERTY_BAG_CLIENT_PAIR(any, BonoboArg *); |
---|
546 | |
---|
547 | /* |
---|
548 | * Setting property values. |
---|
549 | */ |
---|
550 | |
---|
551 | /** |
---|
552 | * bonobo_property_bag_client_set_value_any: |
---|
553 | * @pb: the property bag |
---|
554 | * @propname: name of property to set |
---|
555 | * @value: value to set it to. |
---|
556 | * @ev: optional CORBA exception environment or NULL |
---|
557 | * |
---|
558 | * This function sets the value of the property with name |
---|
559 | * @propname in @pb to @value. |
---|
560 | **/ |
---|
561 | void |
---|
562 | bonobo_property_bag_client_set_value_any (Bonobo_PropertyBag pb, |
---|
563 | const char *propname, |
---|
564 | BonoboArg *value, |
---|
565 | CORBA_Environment *ev) |
---|
566 | { |
---|
567 | Bonobo_Property prop; |
---|
568 | CORBA_Environment *real_ev, tmp_ev; |
---|
569 | |
---|
570 | g_return_if_fail (pb != CORBA_OBJECT_NIL); |
---|
571 | g_return_if_fail (propname != NULL); |
---|
572 | g_return_if_fail (value != NULL); |
---|
573 | |
---|
574 | if (ev) |
---|
575 | real_ev = ev; |
---|
576 | else { |
---|
577 | CORBA_exception_init (&tmp_ev); |
---|
578 | real_ev = &tmp_ev; |
---|
579 | } |
---|
580 | |
---|
581 | prop = bonobo_property_bag_client_get_property (pb, propname, real_ev); |
---|
582 | |
---|
583 | if (BONOBO_EX (real_ev)) { |
---|
584 | if (!ev) |
---|
585 | g_warning ("bonobo_property_bag_client_set_value_any: Exception getting property!"); |
---|
586 | } else { |
---|
587 | Bonobo_Property_setValue (prop, value, real_ev); |
---|
588 | |
---|
589 | if (!ev && BONOBO_EX (real_ev)) |
---|
590 | g_warning ("bonobo_property_bag_client_set_value_any: Exception setting property!"); |
---|
591 | |
---|
592 | CORBA_Object_release (prop, real_ev); |
---|
593 | } |
---|
594 | |
---|
595 | if (!ev) |
---|
596 | CORBA_exception_free (&tmp_ev); |
---|
597 | |
---|
598 | return; |
---|
599 | } |
---|
600 | |
---|
601 | #define MAKE_BONOBO_PROPERTY_BAG_CLIENT_SET_VALUE(gtype,capstype) \ |
---|
602 | \ |
---|
603 | void \ |
---|
604 | bonobo_property_bag_client_set_value_##gtype (Bonobo_PropertyBag pb, \ |
---|
605 | const char *propname,\ |
---|
606 | gtype value, \ |
---|
607 | CORBA_Environment *ev) \ |
---|
608 | { \ |
---|
609 | BonoboArg *arg; \ |
---|
610 | \ |
---|
611 | g_return_if_fail (propname != NULL); \ |
---|
612 | g_return_if_fail (pb != CORBA_OBJECT_NIL); \ |
---|
613 | \ |
---|
614 | arg = bonobo_arg_new (BONOBO_ARG_##capstype); \ |
---|
615 | \ |
---|
616 | BONOBO_ARG_SET_##capstype (arg, value); \ |
---|
617 | \ |
---|
618 | bonobo_property_bag_client_set_value_any (pb, propname, arg, ev); \ |
---|
619 | \ |
---|
620 | bonobo_arg_release (arg); \ |
---|
621 | } |
---|
622 | |
---|
623 | MAKE_BONOBO_PROPERTY_BAG_CLIENT_SET_VALUE(gboolean, BOOLEAN); |
---|
624 | MAKE_BONOBO_PROPERTY_BAG_CLIENT_SET_VALUE(gint, INT); |
---|
625 | MAKE_BONOBO_PROPERTY_BAG_CLIENT_SET_VALUE(glong, LONG); |
---|
626 | MAKE_BONOBO_PROPERTY_BAG_CLIENT_SET_VALUE(gfloat, FLOAT); |
---|
627 | MAKE_BONOBO_PROPERTY_BAG_CLIENT_SET_VALUE(gdouble, DOUBLE); |
---|
628 | |
---|
629 | void |
---|
630 | bonobo_property_bag_client_set_value_string (Bonobo_PropertyBag pb, |
---|
631 | const char *propname, |
---|
632 | const gchar *value, |
---|
633 | CORBA_Environment *ev) |
---|
634 | { |
---|
635 | BonoboArg *arg; |
---|
636 | |
---|
637 | g_return_if_fail (propname != NULL); |
---|
638 | g_return_if_fail (pb != CORBA_OBJECT_NIL); |
---|
639 | |
---|
640 | arg = bonobo_arg_new (BONOBO_ARG_STRING); |
---|
641 | |
---|
642 | BONOBO_ARG_SET_STRING (arg, value); |
---|
643 | |
---|
644 | bonobo_property_bag_client_set_value_any (pb, propname, arg, ev); |
---|
645 | |
---|
646 | bonobo_arg_release (arg); |
---|
647 | } |
---|
648 | |
---|
649 | /* |
---|
650 | * Querying other fields and flags. |
---|
651 | */ |
---|
652 | |
---|
653 | /** |
---|
654 | * bonobo_property_bag_client_get_docstring: |
---|
655 | * @pb: the property bag |
---|
656 | * @propname: the property name |
---|
657 | * @ev: optional CORBA exception environment or NULL |
---|
658 | * |
---|
659 | * This function retrieves the documentation string associated |
---|
660 | * with the property. |
---|
661 | * |
---|
662 | * Return value: the doc string. |
---|
663 | **/ |
---|
664 | char * |
---|
665 | bonobo_property_bag_client_get_docstring (Bonobo_PropertyBag pb, |
---|
666 | const char *propname, |
---|
667 | CORBA_Environment *ev) |
---|
668 | { |
---|
669 | Bonobo_Property prop; |
---|
670 | CORBA_char *docstr; |
---|
671 | CORBA_Environment *real_ev, tmp_ev; |
---|
672 | |
---|
673 | g_return_val_if_fail (propname != NULL, NULL); |
---|
674 | g_return_val_if_fail (pb != CORBA_OBJECT_NIL, NULL); |
---|
675 | |
---|
676 | if (ev) |
---|
677 | real_ev = ev; |
---|
678 | else { |
---|
679 | CORBA_exception_init (&tmp_ev); |
---|
680 | real_ev = &tmp_ev; |
---|
681 | } |
---|
682 | |
---|
683 | prop = bonobo_property_bag_client_get_property (pb, propname, real_ev); |
---|
684 | |
---|
685 | if (prop == CORBA_OBJECT_NIL) { |
---|
686 | if (!ev) { |
---|
687 | CORBA_exception_free (&tmp_ev); |
---|
688 | g_warning ("prop == NIL"); |
---|
689 | } |
---|
690 | return NULL; |
---|
691 | } |
---|
692 | |
---|
693 | docstr = Bonobo_Property_getDocString (prop, real_ev); |
---|
694 | |
---|
695 | if (BONOBO_EX (real_ev)) { |
---|
696 | if (!ev) |
---|
697 | g_warning ("bonobo_property_bag_client_get_doc_string: " |
---|
698 | "Exception getting doc string!"); |
---|
699 | docstr = NULL; |
---|
700 | } |
---|
701 | |
---|
702 | CORBA_Object_release (prop, real_ev); |
---|
703 | |
---|
704 | if (!ev) |
---|
705 | CORBA_exception_free (&tmp_ev); |
---|
706 | |
---|
707 | return (char *) docstr; |
---|
708 | } |
---|
709 | |
---|
710 | /** |
---|
711 | * bonobo_property_bag_client_get_flags: |
---|
712 | * @pb: the property bag |
---|
713 | * @propname: the property's name |
---|
714 | * @ev: optional CORBA exception environment or NULL |
---|
715 | * |
---|
716 | * Return value: the flags associated with this property |
---|
717 | **/ |
---|
718 | BonoboPropertyFlags |
---|
719 | bonobo_property_bag_client_get_flags (Bonobo_PropertyBag pb, |
---|
720 | const char *propname, |
---|
721 | CORBA_Environment *ev) |
---|
722 | { |
---|
723 | BonoboPropertyFlags flags; |
---|
724 | Bonobo_Property prop; |
---|
725 | CORBA_Environment *real_ev, tmp_ev; |
---|
726 | |
---|
727 | g_return_val_if_fail (pb != CORBA_OBJECT_NIL, 0); |
---|
728 | g_return_val_if_fail (propname != NULL, 0); |
---|
729 | |
---|
730 | if (ev) |
---|
731 | real_ev = ev; |
---|
732 | else { |
---|
733 | CORBA_exception_init (&tmp_ev); |
---|
734 | real_ev = &tmp_ev; |
---|
735 | } |
---|
736 | |
---|
737 | prop = bonobo_property_bag_client_get_property (pb, propname, real_ev); |
---|
738 | |
---|
739 | if (prop == CORBA_OBJECT_NIL) { |
---|
740 | if (!ev) { |
---|
741 | CORBA_exception_free (&tmp_ev); |
---|
742 | g_warning ("prop == NIL"); |
---|
743 | } |
---|
744 | return 0; |
---|
745 | } |
---|
746 | |
---|
747 | flags = Bonobo_Property_getFlags (prop, real_ev); |
---|
748 | |
---|
749 | if (BONOBO_EX (real_ev)) |
---|
750 | flags = 0; |
---|
751 | |
---|
752 | CORBA_Object_release (prop, real_ev); |
---|
753 | |
---|
754 | if (!ev) |
---|
755 | CORBA_exception_free (&tmp_ev); |
---|
756 | |
---|
757 | return flags; |
---|
758 | } |
---|
759 | |
---|
760 | #define SEND(pb,name,args,corbat,gt,ansip) \ |
---|
761 | case CORBA_tk##corbat: \ |
---|
762 | bonobo_property_bag_client_set_value##gt (pb, name, (CORBA##corbat) va_arg (args, ansip), ev);\ |
---|
763 | break; |
---|
764 | |
---|
765 | /** |
---|
766 | * bonobo_property_bag_client_setv: |
---|
767 | * @pb: the property bag |
---|
768 | * @ev: optional CORBA exception environment or NULL |
---|
769 | * @first_arg: first argument name |
---|
770 | * @var_args: list of subsequent name / value pairs |
---|
771 | * |
---|
772 | * This function uses the TypeCode data extracted from the |
---|
773 | * @pb to determine how it walks its stack. This function |
---|
774 | * provides the grunt implementation for other var-arg |
---|
775 | * functions like bonobo_widget_set_property |
---|
776 | * |
---|
777 | * Return value: an error string on error or NULL on success. |
---|
778 | **/ |
---|
779 | char * |
---|
780 | bonobo_property_bag_client_setv (Bonobo_PropertyBag pb, |
---|
781 | CORBA_Environment *ev, |
---|
782 | const char *first_arg, |
---|
783 | va_list var_args) |
---|
784 | { |
---|
785 | const char *arg_name; |
---|
786 | |
---|
787 | g_return_val_if_fail (first_arg != NULL, g_strdup ("No arg")); |
---|
788 | g_return_val_if_fail (pb != CORBA_OBJECT_NIL, g_strdup ("No property bag")); |
---|
789 | |
---|
790 | arg_name = first_arg; |
---|
791 | while (arg_name) { |
---|
792 | CORBA_TypeCode type; |
---|
793 | char *msg; |
---|
794 | |
---|
795 | type = bonobo_property_bag_client_get_property_type (pb, arg_name, ev); |
---|
796 | |
---|
797 | if (type == TC_null) |
---|
798 | return g_strdup_printf ("No such arg '%s'", arg_name); |
---|
799 | |
---|
800 | switch (get_kind (type)) { |
---|
801 | SEND (pb, arg_name, var_args, _boolean, _gboolean, int); |
---|
802 | SEND (pb, arg_name, var_args, _long, _glong, int); |
---|
803 | SEND (pb, arg_name, var_args, _float, _gfloat, double); |
---|
804 | SEND (pb, arg_name, var_args, _double, _gdouble, double); |
---|
805 | |
---|
806 | case CORBA_tk_string: |
---|
807 | bonobo_property_bag_client_set_value_string (pb, arg_name, |
---|
808 | va_arg (var_args, CORBA_char *), ev); |
---|
809 | break; |
---|
810 | |
---|
811 | case CORBA_tk_any: |
---|
812 | bonobo_property_bag_client_set_value_any (pb, arg_name, |
---|
813 | va_arg (var_args, BonoboArg *), ev); |
---|
814 | break; |
---|
815 | |
---|
816 | default: |
---|
817 | msg = g_strdup_printf ("Unhandled setv arg '%s' type %d", |
---|
818 | arg_name, get_kind (type)); |
---|
819 | |
---|
820 | CORBA_Object_release ((CORBA_Object)type, ev); |
---|
821 | return msg; |
---|
822 | } |
---|
823 | |
---|
824 | CORBA_Object_release ((CORBA_Object)type, ev); |
---|
825 | arg_name = va_arg (var_args, char *); |
---|
826 | } |
---|
827 | |
---|
828 | return NULL; |
---|
829 | } |
---|
830 | #undef SEND |
---|
831 | |
---|
832 | #define RECEIVE(pb,name,args,corbat,gt,ansip) \ |
---|
833 | case CORBA_tk##corbat: \ |
---|
834 | *((CORBA##corbat *)va_arg (args, ansip *)) = \ |
---|
835 | bonobo_property_bag_client_get_value##gt (pb, name, ev); \ |
---|
836 | break; |
---|
837 | |
---|
838 | /** |
---|
839 | * bonobo_property_bag_client_getv: |
---|
840 | * @pb: the property bag |
---|
841 | * @ev: optional CORBA exception environment or NULL |
---|
842 | * @first_arg: first argument name |
---|
843 | * @var_args: list of subsequent name / value pairs |
---|
844 | * |
---|
845 | * This function uses the TypeCode data extracted from the |
---|
846 | * @pb to determine how it walks its stack. This function |
---|
847 | * provides the grunt implementation for other var-arg |
---|
848 | * functions like bonobo_widget_get_property. |
---|
849 | * |
---|
850 | * Return value: an error string on error or NULL on success. |
---|
851 | **/ |
---|
852 | char * |
---|
853 | bonobo_property_bag_client_getv (Bonobo_PropertyBag pb, |
---|
854 | CORBA_Environment *ev, |
---|
855 | const char *first_arg, |
---|
856 | va_list var_args) |
---|
857 | { |
---|
858 | const char *arg_name; |
---|
859 | |
---|
860 | g_return_val_if_fail (first_arg != NULL, g_strdup ("No arg")); |
---|
861 | g_return_val_if_fail (pb != CORBA_OBJECT_NIL, g_strdup ("No property bag")); |
---|
862 | |
---|
863 | arg_name = first_arg; |
---|
864 | while (arg_name) { |
---|
865 | CORBA_TypeCode type; |
---|
866 | char *msg; |
---|
867 | |
---|
868 | type = bonobo_property_bag_client_get_property_type (pb, arg_name, ev); |
---|
869 | |
---|
870 | if (type == TC_null) |
---|
871 | return g_strdup_printf ("No such arg '%s'", arg_name); |
---|
872 | |
---|
873 | switch (get_kind (type)) { |
---|
874 | |
---|
875 | RECEIVE (pb, arg_name, var_args, _boolean, _gboolean, int); |
---|
876 | RECEIVE (pb, arg_name, var_args, _long, _glong, int); |
---|
877 | RECEIVE (pb, arg_name, var_args, _float, _gfloat, double); |
---|
878 | RECEIVE (pb, arg_name, var_args, _double, _gdouble, double); |
---|
879 | |
---|
880 | case CORBA_tk_string: |
---|
881 | *((CORBA_char **)(va_arg (var_args, CORBA_char **))) = |
---|
882 | bonobo_property_bag_client_get_value_string (pb, arg_name, ev); |
---|
883 | break; |
---|
884 | |
---|
885 | case CORBA_tk_any: |
---|
886 | *((BonoboArg **)(va_arg (var_args, BonoboArg **))) = |
---|
887 | bonobo_property_bag_client_get_value_any (pb, arg_name, ev); |
---|
888 | break; |
---|
889 | |
---|
890 | default: |
---|
891 | msg = g_strdup_printf ("Unhandled getv arg '%s' type %d", |
---|
892 | arg_name, get_kind (type)); |
---|
893 | CORBA_Object_release ((CORBA_Object)type, ev); |
---|
894 | return msg; |
---|
895 | } |
---|
896 | |
---|
897 | CORBA_Object_release ((CORBA_Object)type, ev); |
---|
898 | arg_name = va_arg (var_args, char *); |
---|
899 | } |
---|
900 | |
---|
901 | return NULL; |
---|
902 | } |
---|
903 | #undef RECEIVE |
---|