1 | /** |
---|
2 | * Bonobo property object implementation. |
---|
3 | * |
---|
4 | * Author: |
---|
5 | * Nat Friedman (nat@nat.org) |
---|
6 | * |
---|
7 | * Copyright 1999, 2000 Helix Code, Inc. |
---|
8 | */ |
---|
9 | |
---|
10 | #include <config.h> |
---|
11 | #include <bonobo/bonobo-main.h> |
---|
12 | #include <bonobo/bonobo-exception.h> |
---|
13 | #include <bonobo/bonobo-property-bag.h> |
---|
14 | |
---|
15 | typedef struct { |
---|
16 | POA_Bonobo_Property prop; |
---|
17 | BonoboPropertyBag *pb; |
---|
18 | BonoboTransient *transient; |
---|
19 | char *property_name; |
---|
20 | } BonoboPropertyServant; |
---|
21 | |
---|
22 | static CORBA_char * |
---|
23 | impl_Bonobo_Property_getName (PortableServer_Servant servant, |
---|
24 | CORBA_Environment *ev) |
---|
25 | { |
---|
26 | BonoboPropertyServant *ps = (BonoboPropertyServant *) servant; |
---|
27 | |
---|
28 | return CORBA_string_dup (ps->property_name); |
---|
29 | } |
---|
30 | |
---|
31 | static CORBA_TypeCode |
---|
32 | impl_Bonobo_Property_getType (PortableServer_Servant servant, |
---|
33 | CORBA_Environment *ev) |
---|
34 | { |
---|
35 | BonoboPropertyServant *ps = (BonoboPropertyServant *) servant; |
---|
36 | BonoboArgType type; |
---|
37 | |
---|
38 | type = bonobo_property_bag_get_property_type (ps->pb, ps->property_name, ev); |
---|
39 | /* FIXME: we need to handle obscure cases like non existance of the property */ |
---|
40 | |
---|
41 | return (CORBA_TypeCode) CORBA_Object_duplicate ((CORBA_Object) (type), ev); |
---|
42 | } |
---|
43 | |
---|
44 | static CORBA_any * |
---|
45 | impl_Bonobo_Property_getValue (PortableServer_Servant servant, |
---|
46 | CORBA_Environment *ev) |
---|
47 | { |
---|
48 | BonoboPropertyServant *ps = (BonoboPropertyServant *) servant; |
---|
49 | |
---|
50 | return bonobo_property_bag_get_value (ps->pb, ps->property_name, ev); |
---|
51 | } |
---|
52 | |
---|
53 | static void |
---|
54 | impl_Bonobo_Property_setValue (PortableServer_Servant servant, |
---|
55 | const CORBA_any *any, |
---|
56 | CORBA_Environment *ev) |
---|
57 | { |
---|
58 | BonoboPropertyServant *ps = (BonoboPropertyServant *) servant; |
---|
59 | |
---|
60 | bonobo_property_bag_set_value (ps->pb, ps->property_name, any, ev); |
---|
61 | } |
---|
62 | |
---|
63 | static CORBA_any * |
---|
64 | impl_Bonobo_Property_getDefault (PortableServer_Servant servant, |
---|
65 | CORBA_Environment *ev) |
---|
66 | { |
---|
67 | BonoboPropertyServant *ps = (BonoboPropertyServant *) servant; |
---|
68 | |
---|
69 | return bonobo_property_bag_get_default (ps->pb, ps->property_name, ev); |
---|
70 | } |
---|
71 | |
---|
72 | static CORBA_char * |
---|
73 | impl_Bonobo_Property_getDocString (PortableServer_Servant servant, |
---|
74 | CORBA_Environment *ev) |
---|
75 | { |
---|
76 | BonoboPropertyServant *ps = (BonoboPropertyServant *) servant; |
---|
77 | |
---|
78 | return CORBA_string_dup (bonobo_property_bag_get_docstring (ps->pb, |
---|
79 | ps->property_name, ev)); |
---|
80 | } |
---|
81 | |
---|
82 | |
---|
83 | static CORBA_long |
---|
84 | impl_Bonobo_Property_getFlags (PortableServer_Servant servant, |
---|
85 | CORBA_Environment *ev) |
---|
86 | { |
---|
87 | BonoboPropertyServant *ps = (BonoboPropertyServant *) servant; |
---|
88 | |
---|
89 | return bonobo_property_bag_get_flags (ps->pb, ps->property_name, ev); |
---|
90 | } |
---|
91 | |
---|
92 | static Bonobo_EventSource_ListenerId |
---|
93 | impl_Bonobo_Property_addListener (PortableServer_Servant servant, |
---|
94 | const Bonobo_Listener l, |
---|
95 | CORBA_Environment *ev) |
---|
96 | { |
---|
97 | BonoboPropertyServant *ps = (BonoboPropertyServant *) servant; |
---|
98 | Bonobo_Unknown corba_es; |
---|
99 | Bonobo_EventSource_ListenerId id = 0; |
---|
100 | char *mask; |
---|
101 | |
---|
102 | corba_es = BONOBO_OBJREF (ps->pb->es); |
---|
103 | |
---|
104 | mask = g_strdup_printf ("Bonobo/Property:change:%s", |
---|
105 | ps->property_name); |
---|
106 | |
---|
107 | id = Bonobo_EventSource_addListenerWithMask (corba_es, l, mask, ev); |
---|
108 | |
---|
109 | g_free (mask); |
---|
110 | |
---|
111 | return id; |
---|
112 | } |
---|
113 | |
---|
114 | static void |
---|
115 | impl_Bonobo_Property_removeListener (PortableServer_Servant servant, |
---|
116 | const Bonobo_EventSource_ListenerId id, |
---|
117 | CORBA_Environment *ev) |
---|
118 | { |
---|
119 | BonoboPropertyServant *ps = (BonoboPropertyServant *) servant; |
---|
120 | Bonobo_Unknown corba_es; |
---|
121 | |
---|
122 | corba_es = BONOBO_OBJREF (ps->pb->es); |
---|
123 | |
---|
124 | Bonobo_EventSource_removeListener (corba_es, id, ev); |
---|
125 | } |
---|
126 | |
---|
127 | static POA_Bonobo_Property__epv * |
---|
128 | bonobo_property_get_epv (void) |
---|
129 | { |
---|
130 | static POA_Bonobo_Property__epv *epv = NULL; |
---|
131 | |
---|
132 | if (epv != NULL) |
---|
133 | return epv; |
---|
134 | |
---|
135 | epv = g_new0 (POA_Bonobo_Property__epv, 1); |
---|
136 | |
---|
137 | epv->getName = impl_Bonobo_Property_getName; |
---|
138 | epv->getType = impl_Bonobo_Property_getType; |
---|
139 | epv->getValue = impl_Bonobo_Property_getValue; |
---|
140 | epv->setValue = impl_Bonobo_Property_setValue; |
---|
141 | epv->getDefault = impl_Bonobo_Property_getDefault; |
---|
142 | epv->getDocString = impl_Bonobo_Property_getDocString; |
---|
143 | epv->getFlags = impl_Bonobo_Property_getFlags; |
---|
144 | epv->addListener = impl_Bonobo_Property_addListener; |
---|
145 | epv->removeListener = impl_Bonobo_Property_removeListener; |
---|
146 | |
---|
147 | return epv; |
---|
148 | } |
---|
149 | |
---|
150 | static void |
---|
151 | impl_Bonobo_Property_ref (PortableServer_Servant servant, |
---|
152 | CORBA_Environment *ev) |
---|
153 | { |
---|
154 | /* nothing to do */ |
---|
155 | } |
---|
156 | |
---|
157 | static void |
---|
158 | impl_Bonobo_Property_unref (PortableServer_Servant servant, |
---|
159 | CORBA_Environment *ev) |
---|
160 | { |
---|
161 | /* nothing to do */ |
---|
162 | } |
---|
163 | |
---|
164 | static CORBA_Object |
---|
165 | impl_Bonobo_Property_queryInterface (PortableServer_Servant servant, |
---|
166 | const CORBA_char *repoid, |
---|
167 | CORBA_Environment *ev) |
---|
168 | { |
---|
169 | BonoboPropertyServant *ps = (BonoboPropertyServant *) servant; |
---|
170 | |
---|
171 | if (!strcmp (repoid, "IDL:Bonobo/Property:1.0")) |
---|
172 | return bonobo_transient_create_objref (ps->transient, |
---|
173 | "IDL:Bonobo/Property:1.0", ps->property_name, |
---|
174 | ev); |
---|
175 | else |
---|
176 | return CORBA_OBJECT_NIL; |
---|
177 | } |
---|
178 | |
---|
179 | static POA_Bonobo_Unknown__epv * |
---|
180 | bonobo_property_get_unknown_epv (void) |
---|
181 | { |
---|
182 | POA_Bonobo_Unknown__epv *epv; |
---|
183 | |
---|
184 | epv = g_new0 (POA_Bonobo_Unknown__epv, 1); |
---|
185 | |
---|
186 | epv->ref = impl_Bonobo_Property_ref; |
---|
187 | epv->unref = impl_Bonobo_Property_unref; |
---|
188 | epv->queryInterface = impl_Bonobo_Property_queryInterface; |
---|
189 | |
---|
190 | return epv; |
---|
191 | } |
---|
192 | |
---|
193 | static POA_Bonobo_Property__vepv * |
---|
194 | bonobo_property_get_vepv (void) |
---|
195 | { |
---|
196 | static POA_Bonobo_Property__vepv *vepv = NULL; |
---|
197 | |
---|
198 | if (vepv != NULL) |
---|
199 | return vepv; |
---|
200 | |
---|
201 | vepv = g_new0 (POA_Bonobo_Property__vepv, 1); |
---|
202 | |
---|
203 | vepv->Bonobo_Property_epv = bonobo_property_get_epv (); |
---|
204 | vepv->Bonobo_Unknown_epv = bonobo_property_get_unknown_epv (); |
---|
205 | |
---|
206 | return vepv; |
---|
207 | } |
---|
208 | |
---|
209 | PortableServer_Servant |
---|
210 | bonobo_property_servant_new (PortableServer_POA poa, |
---|
211 | BonoboTransient *bt, |
---|
212 | char *property_name, |
---|
213 | void *callback_data) |
---|
214 | { |
---|
215 | BonoboPropertyServant *servant; |
---|
216 | BonoboPropertyBag *pb = (BonoboPropertyBag *)callback_data; |
---|
217 | CORBA_Environment ev; |
---|
218 | |
---|
219 | g_return_val_if_fail (pb != NULL, NULL); |
---|
220 | g_return_val_if_fail (bt != NULL, NULL); |
---|
221 | g_return_val_if_fail (BONOBO_IS_PROPERTY_BAG (pb), NULL); |
---|
222 | g_return_val_if_fail (property_name != NULL, NULL); |
---|
223 | |
---|
224 | /* |
---|
225 | * Verify that the specified property exists. |
---|
226 | */ |
---|
227 | if (! bonobo_property_bag_has_property (pb, property_name)) |
---|
228 | return CORBA_OBJECT_NIL; |
---|
229 | |
---|
230 | CORBA_exception_init (&ev); |
---|
231 | |
---|
232 | /* |
---|
233 | * Create a transient servant for the property. |
---|
234 | */ |
---|
235 | servant = g_new0 (BonoboPropertyServant, 1); |
---|
236 | |
---|
237 | servant->property_name = g_strdup (property_name); |
---|
238 | servant->transient = bt; |
---|
239 | servant->pb = pb; |
---|
240 | |
---|
241 | ((POA_Bonobo_Property *) servant)->vepv = bonobo_property_get_vepv (); |
---|
242 | |
---|
243 | POA_Bonobo_Property__init ((PortableServer_Servant) servant, &ev); |
---|
244 | if (BONOBO_EX (&ev)) { |
---|
245 | g_warning ("BonoboProperty: Could not initialize Property servant"); |
---|
246 | g_free (servant->property_name); |
---|
247 | g_free (servant); |
---|
248 | CORBA_exception_free (&ev); |
---|
249 | return CORBA_OBJECT_NIL; |
---|
250 | } |
---|
251 | |
---|
252 | CORBA_exception_free (&ev); |
---|
253 | |
---|
254 | return servant; |
---|
255 | } |
---|
256 | |
---|
257 | void |
---|
258 | bonobo_property_servant_destroy (PortableServer_Servant servant, |
---|
259 | void *callback_data) |
---|
260 | { |
---|
261 | CORBA_Environment ev; |
---|
262 | |
---|
263 | g_return_if_fail (servant != NULL); |
---|
264 | |
---|
265 | CORBA_exception_init (&ev); |
---|
266 | |
---|
267 | POA_Bonobo_Property__fini ((PortableServer_Servant) servant, &ev); |
---|
268 | if (BONOBO_EX (&ev)) { |
---|
269 | g_warning ("BonoboProperty: Could not deconstruct Property servant"); |
---|
270 | CORBA_exception_free (&ev); |
---|
271 | return; |
---|
272 | } |
---|
273 | |
---|
274 | CORBA_exception_free (&ev); |
---|
275 | |
---|
276 | g_free (((BonoboPropertyServant *) servant)->property_name); |
---|
277 | g_free (servant); |
---|
278 | } |
---|