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
|
/* -*- C++ -*- */
// $Id$
#include "UnionDef_i.h"
#include "Repository_i.h"
#include "Servant_Factory.h"
#include "ace/Auto_Ptr.h"
ACE_RCSID(IFR_Service, UnionDef_i, "$Id$")
TAO_UnionDef_i::TAO_UnionDef_i (TAO_Repository_i *repo,
ACE_Configuration_Section_Key section_key)
: TAO_IRObject_i (repo, section_key),
TAO_IDLType_i (repo, section_key),
TAO_Contained_i (repo, section_key),
TAO_TypedefDef_i (repo, section_key),
TAO_Container_i (repo, section_key)
{
}
TAO_UnionDef_i::~TAO_UnionDef_i (void)
{
}
IR::DefinitionKind
TAO_UnionDef_i::def_kind (CORBA::Environment &)
ACE_THROW_SPEC ((CORBA::SystemException))
{
return IR::dk_Union;
}
void
TAO_UnionDef_i::destroy (CORBA::Environment &ACE_TRY_ENV)
ACE_THROW_SPEC ((CORBA::SystemException))
{
// Destroy our members.
TAO_Container_i::destroy (ACE_TRY_ENV);
ACE_CHECK;
// Destroy ourself.
TAO_Contained_i::destroy (ACE_TRY_ENV);
ACE_CHECK;
}
CORBA::TypeCode_ptr
TAO_UnionDef_i::type (CORBA::Environment &ACE_TRY_ENV)
ACE_THROW_SPEC ((CORBA::SystemException))
{
ACE_TString id;
this->repo_->config ()->get_string_value (this->section_key_,
"id",
id);
ACE_TString name;
this->repo_->config ()->get_string_value (this->section_key_,
"name",
name);
CORBA::TypeCode_var tc = this->discriminator_type (ACE_TRY_ENV);
ACE_CHECK_RETURN (CORBA::TypeCode::_nil ());
IR::UnionMemberSeq_var members = this->members (ACE_TRY_ENV);
ACE_CHECK_RETURN (CORBA::TypeCode::_nil ());
return this->repo_->tc_factory ()->create_union_tc (id.c_str (),
name.c_str (),
tc.in (),
members.in (),
ACE_TRY_ENV);
}
CORBA::TypeCode_ptr
TAO_UnionDef_i::discriminator_type (CORBA::Environment &ACE_TRY_ENV)
ACE_THROW_SPEC ((CORBA::SystemException))
{
ACE_TString disc_path;
this->repo_->config ()->get_string_value (this->section_key_,
"disc_path",
disc_path);
ACE_Configuration_Section_Key disc_key;
this->repo_->config ()->expand_path (this->repo_->root_key (),
disc_path,
disc_key,
0);
TAO_IDLType_i *impl =
this->repo_->servant_factory ()->create_idltype (disc_key,
ACE_TRY_ENV);
auto_ptr<TAO_IDLType_i> safety (impl);
return impl->type (ACE_TRY_ENV);
}
IR::IDLType_ptr
TAO_UnionDef_i::discriminator_type_def (CORBA::Environment &ACE_TRY_ENV)
ACE_THROW_SPEC ((CORBA::SystemException))
{
ACE_TString disc_path;
this->repo_->config ()->get_string_value (this->section_key_,
"disc_path",
disc_path);
ACE_Configuration_Section_Key disc_key;
this->repo_->config ()->expand_path (this->repo_->root_key (),
disc_path,
disc_key,
0);
u_int kind;
this->repo_->config ()->get_integer_value (disc_key,
"def_kind",
kind);
IR::DefinitionKind def_kind =
ACE_static_cast (IR::DefinitionKind, kind);
CORBA::Object_var obj =
this->repo_->servant_factory ()->create_objref (def_kind,
disc_path.c_str (),
ACE_TRY_ENV);
ACE_CHECK_RETURN (IR::IDLType::_nil ());
return IR::IDLType::_narrow (obj.in (),
ACE_TRY_ENV);
}
void
TAO_UnionDef_i::discriminator_type_def (
IR::IDLType_ptr discriminator_type_def,
CORBA::Environment &ACE_TRY_ENV
)
ACE_THROW_SPEC ((CORBA::SystemException))
{
PortableServer::ObjectId_var oid =
this->repo_->ir_poa ()->reference_to_id (discriminator_type_def,
ACE_TRY_ENV);
ACE_CHECK;
CORBA::String_var disc_path =
PortableServer::ObjectId_to_string (oid.in ());
this->repo_->config ()->set_string_value (this->section_key_,
"disc_path",
disc_path.in ());
}
IR::UnionMemberSeq *
TAO_UnionDef_i::members (CORBA::Environment &ACE_TRY_ENV)
ACE_THROW_SPEC ((CORBA::SystemException))
{
ACE_Unbounded_Queue<ACE_Configuration_Section_Key> key_queue;
ACE_Configuration_Section_Key refs_key;
this->repo_->config ()->open_section (this->section_key_,
"refs",
0,
refs_key);
u_int count;
this->repo_->config ()->get_integer_value (refs_key,
"count",
count);
for (u_int i = 0; i < count; i++)
{
ACE_Configuration_Section_Key member_key;
CORBA::String_var section_name = this->int_to_string (i);
if (this->repo_->config ()->open_section (refs_key,
section_name.in (),
0,
member_key)
== 0)
{
ACE_TString path;
this->repo_->config ()->get_string_value (member_key,
"path",
path);
ACE_Configuration_Section_Key entry_key;
// This entry may have been removed.
if (this->repo_->config ()->expand_path (this->repo_->root_key (),
path,
entry_key,
0)
== 0)
{
key_queue.enqueue_tail (member_key);
}
}
}
size_t size = key_queue.size ();
IR::UnionMemberSeq *members = 0;
ACE_NEW_THROW_EX (members,
IR::UnionMemberSeq (size),
CORBA::NO_MEMORY ());
ACE_CHECK_RETURN (0);
members->length (size);
IR::UnionMemberSeq_var retval = members;
for (size_t k = 0; k < size; k++)
{
ACE_Configuration_Section_Key next_key;
key_queue.dequeue_head (next_key);
ACE_TString name;
this->repo_->config ()->get_string_value (next_key,
"name",
name);
retval[k].name = name.c_str ();
this->fetch_label (next_key,
retval[k],
ACE_TRY_ENV);
ACE_CHECK_RETURN (0);
ACE_TString path;
this->repo_->config ()->get_string_value (next_key,
"path",
path);
ACE_Configuration_Section_Key entry_key;
this->repo_->config ()->expand_path (this->repo_->root_key (),
path,
entry_key,
0);
u_int kind;
this->repo_->config ()->get_integer_value (entry_key,
"def_kind",
kind);
IR::DefinitionKind def_kind =
ACE_static_cast (IR::DefinitionKind, kind);
CORBA::Object_var obj =
this->repo_->servant_factory ()->create_objref (def_kind,
path.c_str (),
ACE_TRY_ENV);
ACE_CHECK_RETURN (0);
retval[k].type_def = IR::IDLType::_narrow (obj.in (),
ACE_TRY_ENV);
ACE_CHECK_RETURN (0);
retval[k].type = retval[k].type_def->type (ACE_TRY_ENV);
ACE_CHECK_RETURN (0);
}
return retval._retn ();
}
void
TAO_UnionDef_i::members (const IR::UnionMemberSeq &members,
CORBA::Environment &ACE_TRY_ENV)
ACE_THROW_SPEC ((CORBA::SystemException))
{
// Destroy our old members, both refs and defns.
TAO_Container_i::destroy (ACE_TRY_ENV);
ACE_CHECK;
ACE_TString section_name;
ACE_Configuration_Section_Key refs_key;
this->repo_->config ()->open_section (this->section_key_,
"refs",
1,
refs_key);
// Store the new member count of the union.
CORBA::ULong count = members.length ();
this->repo_->config ()->set_integer_value (refs_key,
"count",
count);
// Create a section for each member. We store the member
// name, its label value, and the path to its database entry.
for (CORBA::ULong i = 0; i < count; i++)
{
ACE_Configuration_Section_Key member_key;
char *section_name = this->int_to_string (i);
this->repo_->config ()->open_section (refs_key,
section_name,
1,
member_key);
ACE_TString name (members[i].name);
this->repo_->config ()->set_string_value (member_key,
"name",
name);
PortableServer::ObjectId_var oid =
this->repo_->ir_poa ()->reference_to_id (members[i].type_def,
ACE_TRY_ENV);
ACE_CHECK;
CORBA::String_var member_path =
PortableServer::ObjectId_to_string (oid.in ());
this->repo_->config ()->set_string_value (member_key,
"path",
member_path.in ());
this->store_label (member_key,
members[i].label,
ACE_TRY_ENV);
}
}
void
TAO_UnionDef_i::fetch_label (const ACE_Configuration_Section_Key member_key,
IR::UnionMember &member,
CORBA::Environment &ACE_TRY_ENV)
ACE_THROW_SPEC ((CORBA::SystemException))
{
ACE_Configuration::VALUETYPE vt;
this->repo_->config ()->find_value (member_key,
"label",
vt);
if (vt == ACE_Configuration::STRING)
{
member.label <<= CORBA::Any::from_octet (0);
return;
}
u_int value = 0;
this->repo_->config ()->get_integer_value (member_key,
"label",
value);
CORBA::TypeCode_var tc = this->discriminator_type (ACE_TRY_ENV);
ACE_CHECK;
CORBA::TCKind kind = tc->kind (ACE_TRY_ENV);
ACE_CHECK;
switch (kind)
{
case CORBA::tk_char:
member.label <<= CORBA::Any::from_char (ACE_static_cast (CORBA::Char,
value));
break;
case CORBA::tk_wchar:
member.label <<= CORBA::Any::from_wchar (ACE_static_cast (CORBA::WChar,
value));
break;
case CORBA::tk_boolean:
member.label <<= CORBA::Any::from_boolean (ACE_static_cast (CORBA::Boolean,
value));
break;
case CORBA::tk_short:
member.label <<= ACE_static_cast (CORBA::Short, value);
break;
case CORBA::tk_ushort:
member.label <<= ACE_static_cast (CORBA::UShort, value);
break;
case CORBA::tk_long:
member.label <<= ACE_static_cast (CORBA::Long, value);
break;
case CORBA::tk_ulong:
member.label <<= ACE_static_cast (CORBA::ULong, value);
break;
#if !defined (ACE_LACKS_LONGLONG_T)
case CORBA::tk_longlong:
member.label <<= ACE_static_cast (CORBA::LongLong, value);
break;
#endif /* ACE_LACKS_LONGLONG_T */
case CORBA::tk_ulonglong:
member.label <<= ACE_static_cast (CORBA::ULongLong, value);
break;
case CORBA::tk_enum:
{
TAO_OutputCDR cdr;
cdr.write_ulong (ACE_static_cast (CORBA::ULong, value));
member.label._tao_replace (tc.in (),
TAO_ENCAP_BYTE_ORDER,
cdr.begin ());
break;
}
default:
break;
}
}
|