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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
|
/* -*- C++ -*- */
// $Id$
#include "DynAny_i.h"
#include "DynAnyFactory.h"
ACE_RCSID(DynamicAny, DynAny_i, "$Id$")
// Constructor from typecode
TAO_DynAny_i::TAO_DynAny_i (void)
{
}
// Destructor
TAO_DynAny_i::~TAO_DynAny_i (void)
{
}
void
TAO_DynAny_i::check_typecode (CORBA::TypeCode_ptr tc
TAO_ENV_ARG_DECL)
{
// Check to see if it's a simple type.
CORBA::TCKind tk = TAO_DynAnyFactory::unalias (tc TAO_ENV_ARG_PARAMETER);
ACE_CHECK;
switch (tk)
{
case CORBA::tk_null:
case CORBA::tk_void:
case CORBA::tk_short:
case CORBA::tk_long:
case CORBA::tk_ushort:
case CORBA::tk_ulong:
case CORBA::tk_float:
case CORBA::tk_double:
case CORBA::tk_longlong:
case CORBA::tk_ulonglong:
case CORBA::tk_boolean:
case CORBA::tk_char:
case CORBA::tk_wchar:
case CORBA::tk_octet:
case CORBA::tk_any:
case CORBA::tk_TypeCode:
case CORBA::tk_objref:
case CORBA::tk_string:
case CORBA::tk_wstring:
break;
default:
ACE_THROW (DynamicAny::DynAnyFactory::InconsistentTypeCode ());
}
}
void
TAO_DynAny_i::set_to_default_value (CORBA::TypeCode_ptr tc
TAO_ENV_ARG_DECL)
{
CORBA::TCKind tk = TAO_DynAnyFactory::unalias (tc TAO_ENV_ARG_PARAMETER);
ACE_CHECK;
switch (tk)
{
case CORBA::tk_null:
break;
case CORBA::tk_void:
this->any_ = CORBA_Any (CORBA::_tc_void);
break;
case CORBA::tk_short:
this->any_ <<= ACE_static_cast (CORBA::Short, 0);
break;
case CORBA::tk_long:
this->any_ <<= ACE_static_cast (CORBA::Long, 0);
break;
case CORBA::tk_ushort:
this->any_ <<= ACE_static_cast (CORBA::UShort, 0);
break;
case CORBA::tk_ulong:
this->any_ <<= ACE_static_cast (CORBA::ULong, 0);
break;
#if !defined (ACE_LACKS_LONGLONG_T)
case CORBA::tk_longlong:
this->any_ <<= ACE_static_cast (CORBA::LongLong, 0);
break;
case CORBA::tk_ulonglong:
this->any_ <<= ACE_static_cast (CORBA::ULongLong, 0);
break;
#endif /* ACE_LACKS_LONGLONG_T */
case CORBA::tk_boolean:
this->any_ <<= CORBA::Any::from_boolean (0);
break;
case CORBA::tk_octet:
this->any_ <<= CORBA::Any::from_octet (0);
break;
case CORBA::tk_char:
this->any_ <<= CORBA::Any::from_char (0);
break;
case CORBA::tk_wchar:
this->any_ <<= CORBA::Any::from_wchar (0);
break;
case CORBA::tk_float:
this->any_ <<= ACE_static_cast (CORBA::Float, 0);
break;
case CORBA::tk_double:
this->any_ <<= ACE_static_cast (CORBA::Double, 0);
break;
case CORBA::tk_any:
this->any_ <<= CORBA::Any (CORBA::_tc_null);
break;
case CORBA::tk_TypeCode:
{
CORBA::TypeCode tc (CORBA::tk_null);
CORBA::TypeCode_ptr tc_ptr = &tc;
this->any_ <<= tc_ptr;
break;
}
case CORBA::tk_objref:
{
TAO_OutputCDR stream;
stream << CORBA::Object::_nil ();
this->any_._tao_replace (tc,
TAO_ENCAP_BYTE_ORDER,
stream.begin ());
break;
}
case CORBA::tk_string:
this->any_ <<= "";
break;
case CORBA::tk_wstring:
{
CORBA::WChar wstr[1];
wstr[0] = 0;
this->any_ <<= wstr;
break;
}
default:
// Should never get here - check_typecode() has already been called.
break;
}
}
void
TAO_DynAny_i::init_common (void)
{
this->ref_to_component_ = 0;
this->container_is_destroying_ = 0;
this->has_components_ = 0;
this->destroyed_ = 0;
this->current_position_ = -1;
this->component_count_ = 0;
}
void
TAO_DynAny_i::init (CORBA_TypeCode_ptr tc
TAO_ENV_ARG_DECL)
{
this->check_typecode (tc
TAO_ENV_ARG_PARAMETER);
ACE_CHECK;
this->set_to_default_value (tc
TAO_ENV_ARG_PARAMETER);
ACE_CHECK;
this->init_common ();
this->type_ = CORBA::TypeCode::_duplicate (tc);
}
void
TAO_DynAny_i::init (const CORBA_Any& any
TAO_ENV_ARG_DECL)
{
this->type_ = any.type ();
this->check_typecode (this->type_.in ()
TAO_ENV_ARG_PARAMETER);
ACE_CHECK;
this->init_common ();
this->any_ = any;
}
// ****************************************************************
TAO_DynAny_i *
TAO_DynAny_i::_narrow (CORBA::Object_ptr obj
TAO_ENV_ARG_DECL_NOT_USED)
{
if (CORBA::is_nil (obj))
{
return 0;
}
return ACE_reinterpret_cast (
TAO_DynAny_i*,
obj->_tao_QueryInterface (
ACE_reinterpret_cast (
ptr_arith_t,
&TAO_DynAny_i::_narrow
)
)
);
}
void*
TAO_DynAny_i::_tao_QueryInterface (ptr_arith_t type)
{
ptr_arith_t mytype =
ACE_reinterpret_cast (ptr_arith_t,
&TAO_DynAny_i::_narrow);
if (type == mytype)
{
this->_add_ref ();
return this;
}
return
this->ACE_NESTED_CLASS (DynamicAny, DynAny::_tao_QueryInterface) (type);
}
// ****************************************************************
void
TAO_DynAny_i::from_any (const CORBA_Any &any
TAO_ENV_ARG_DECL)
ACE_THROW_SPEC ((
CORBA::SystemException,
DynamicAny::DynAny::TypeMismatch,
DynamicAny::DynAny::InvalidValue
))
{
if (this->destroyed_)
{
ACE_THROW (CORBA::OBJECT_NOT_EXIST ());
}
CORBA::TypeCode_var any_tc = any.type ();
CORBA::Boolean equiv =
this->type_->equivalent (any_tc.in ()
TAO_ENV_ARG_PARAMETER);
ACE_CHECK;
if (!equiv)
{
ACE_THROW (DynamicAny::DynAny::TypeMismatch ());
}
// @@@ (JP) Spec also says we should check for illegal Any
// value here, and throw InvalidValue if we find one.
// Something like a null string will be caught in the constructor.
this->any_ = any;
}
CORBA::Any_ptr
TAO_DynAny_i::to_any (TAO_ENV_SINGLE_ARG_DECL)
ACE_THROW_SPEC ((
CORBA::SystemException
))
{
if (this->destroyed_)
{
ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (),
0);
}
CORBA_Any_ptr retval;
ACE_NEW_THROW_EX (retval,
CORBA::Any (this->any_),
CORBA::NO_MEMORY ());
ACE_CHECK_RETURN (0);
return retval;
}
CORBA::Boolean
TAO_DynAny_i::equal (DynamicAny::DynAny_ptr rhs
TAO_ENV_ARG_DECL)
ACE_THROW_SPEC ((
CORBA::SystemException
))
{
if (this->destroyed_)
{
ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (),
0);
}
TAO_DynAny_i *rhs_n = TAO_DynAny_i::_narrow (rhs
TAO_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
if (rhs_n == 0)
{
return 0;
}
CORBA::Boolean equiv = this->type_->equivalent (rhs_n->type_.in ()
TAO_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
if (!equiv)
{
return 0;
}
int tk = this->type_->kind ();
ACE_CHECK_RETURN (0);
switch (tk)
{
case CORBA::tk_null:
case CORBA::tk_void:
return 1;
case CORBA::tk_short:
{
CORBA::Short rhs_v;
rhs_n->any_ >>= rhs_v;
CORBA::Short lhs_v;
this->any_ >>= lhs_v;
return (lhs_v == rhs_v);
}
case CORBA::tk_long:
{
CORBA::Long rhs_v;
rhs_n->any_ >>= rhs_v;
CORBA::Long lhs_v;
this->any_ >>= lhs_v;
return (lhs_v == rhs_v);
}
case CORBA::tk_ushort:
{
CORBA::UShort rhs_v;
rhs_n->any_ >>= rhs_v;
CORBA::UShort lhs_v;
this->any_ >>= lhs_v;
return (lhs_v == rhs_v);
}
case CORBA::tk_ulong:
{
CORBA::ULong rhs_v;
rhs_n->any_ >>= rhs_v;
CORBA::ULong lhs_v;
this->any_ >>= lhs_v;
return (lhs_v == rhs_v);
}
case CORBA::tk_float:
{
CORBA::Float rhs_v;
rhs_n->any_ >>= rhs_v;
CORBA::Float lhs_v;
this->any_ >>= lhs_v;
return (lhs_v == rhs_v);
}
case CORBA::tk_double:
{
CORBA::Double rhs_v;
rhs_n->any_ >>= rhs_v;
CORBA::Double lhs_v;
this->any_ >>= lhs_v;
return (lhs_v == rhs_v);
}
case CORBA::tk_longlong:
{
CORBA::LongLong rhs_v;
rhs_n->any_ >>= rhs_v;
CORBA::LongLong lhs_v;
this->any_ >>= lhs_v;
return (lhs_v == rhs_v);
}
case CORBA::tk_ulonglong:
{
CORBA::ULongLong rhs_v;
rhs_n->any_ >>= rhs_v;
CORBA::ULongLong lhs_v;
this->any_ >>= lhs_v;
return (lhs_v == rhs_v);
}
case CORBA::tk_boolean:
{
CORBA::Boolean rhs_v;
rhs_n->any_ >>= CORBA::Any::to_boolean (rhs_v);
CORBA::Boolean lhs_v;
this->any_ >>= CORBA::Any::to_boolean (lhs_v);
return (lhs_v == rhs_v);
}
case CORBA::tk_char:
{
CORBA::Char rhs_v;
rhs_n->any_ >>= CORBA::Any::to_char (rhs_v);
CORBA::Char lhs_v;
this->any_ >>= CORBA::Any::to_char (lhs_v);
return (lhs_v == rhs_v);
}
case CORBA::tk_wchar:
{
CORBA::WChar rhs_v;
rhs_n->any_ >>= CORBA::Any::to_wchar (rhs_v);
CORBA::WChar lhs_v;
this->any_ >>= CORBA::Any::to_wchar (lhs_v);
return (lhs_v == rhs_v);
}
case CORBA::tk_octet:
{
CORBA::Octet rhs_v;
rhs_n->any_ >>= CORBA::Any::to_octet (rhs_v);
CORBA::Octet lhs_v;
this->any_ >>= CORBA::Any::to_octet (lhs_v);
return (lhs_v == rhs_v);
}
case CORBA::tk_any:
{
CORBA::Any rhs_v;
rhs_n->any_ >>= rhs_v;
CORBA::Any lhs_v;
this->any_ >>= lhs_v;
DynamicAny::DynAny_var rhs_dyn =
TAO_DynAnyFactory::make_dyn_any (rhs_v
TAO_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
DynamicAny::DynAny_var lhs_dyn =
TAO_DynAnyFactory::make_dyn_any (lhs_v
TAO_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
CORBA::Boolean b = rhs_dyn->equal (lhs_dyn.in ()
TAO_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
rhs_dyn->destroy (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
lhs_dyn->destroy (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
return b;
}
case CORBA::tk_TypeCode:
{
CORBA::TypeCode_ptr rhs_v;
rhs_n->any_ >>= rhs_v;
CORBA::TypeCode_ptr lhs_v;
this->any_ >>= lhs_v;
// See CORBA 2.4.2 - must use equal() here.
return lhs_v->equal (lhs_v
TAO_ENV_ARG_PARAMETER);
}
case CORBA::tk_objref:
{
CORBA::Object_ptr rhs_v;
rhs_n->any_ >>= CORBA::Any::to_object (rhs_v);
CORBA::Object_ptr lhs_v;
this->any_ >>= CORBA::Any::to_object (lhs_v);
return lhs_v->_is_equivalent (lhs_v
TAO_ENV_ARG_PARAMETER);
}
case CORBA::tk_string:
{
CORBA::TypeCode_var unaliased_tc =
TAO_DynAnyFactory::strip_alias (this->type_.in ()
TAO_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
CORBA::ULong bound = unaliased_tc->length (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
const char* rhs_v;
rhs_n->any_ >>= CORBA::Any::to_string (rhs_v,
bound);
// @@@ (JP) On Windows (only), this any does not get the bound
// set in its type code when copied from another DynAny. So we
// dispense with the to_string here, since the type codes have
// already been checked for equivalence above (done with this
// DynAny's type_ member, which does have the bound set correctly).
const char* lhs_v;
this->any_ >>= lhs_v;
return ACE_OS::strcmp (rhs_v, lhs_v) == 0;
}
case CORBA::tk_wstring:
{
CORBA::TypeCode_var unaliased_tc =
TAO_DynAnyFactory::strip_alias (this->type_.in ()
TAO_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
CORBA::ULong bound = unaliased_tc->length (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
CORBA::WChar * rhs_v;
rhs_n->any_ >>= CORBA::Any::to_wstring (rhs_v,
bound);
CORBA::WChar * lhs_v;
this->any_ >>= CORBA::Any::to_wstring (lhs_v,
bound);
return ACE_OS::wscmp (rhs_v, lhs_v) == 0;
}
default:
break; // Cannot happen...
}
return 0;
}
void
TAO_DynAny_i::destroy (TAO_ENV_SINGLE_ARG_DECL)
ACE_THROW_SPEC ((
CORBA::SystemException
))
{
if (this->destroyed_)
{
ACE_THROW (CORBA::OBJECT_NOT_EXIST ());
}
if (!this->ref_to_component_ || this->container_is_destroying_)
{
this->destroyed_ = 1;
}
}
DynamicAny::DynAny_ptr
TAO_DynAny_i::current_component (TAO_ENV_SINGLE_ARG_DECL)
ACE_THROW_SPEC ((
CORBA::SystemException,
DynamicAny::DynAny::TypeMismatch
))
{
if (this->destroyed_)
{
ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (),
DynamicAny::DynAny::_nil ());
}
ACE_THROW_RETURN (DynamicAny::DynAny::TypeMismatch (),
DynamicAny::DynAny::_nil ());
}
|