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
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
|
// $Id$
#include "tao/DynamicAny/DynUnion_i.h"
#include "tao/DynamicAny/DynAnyFactory.h"
#include "tao/DynamicAny/DynAnyUtils_T.h"
#include "tao/AnyTypeCode/Marshal.h"
#include "tao/AnyTypeCode/Any_Unknown_IDL_Type.h"
#include "tao/AnyTypeCode/AnyTypeCode_methods.h"
#include "tao/CDR.h"
ACE_RCSID (DynamicAny,
DynUnion_i,
"$Id$")
TAO_BEGIN_VERSIONED_NAMESPACE_DECL
TAO_DynUnion_i::TAO_DynUnion_i (void)
{
}
TAO_DynUnion_i::~TAO_DynUnion_i (void)
{
}
void
TAO_DynUnion_i::init_common (void)
{
this->ref_to_component_ = false;
this->container_is_destroying_ = false;
this->has_components_ = true;
this->destroyed_ = false;
this->component_count_ = 2;
this->current_position_ = 0;
this->member_slot_ = 0;
}
void
TAO_DynUnion_i::init (const CORBA::Any& any
ACE_ENV_ARG_DECL)
{
CORBA::TypeCode_var tc = any.type ();
CORBA::TCKind kind = TAO_DynAnyFactory::unalias (tc.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
if (kind != CORBA::tk_union)
{
ACE_THROW (DynamicAny::DynAnyFactory::InconsistentTypeCode ());
}
// Initialize the typecode holder.
this->type_ = tc;
this->init_common ();
// Set the from_factory arg to TRUE, so any problems will throw
// InconsistentTypeCode.
this->set_from_any (any
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
}
void
TAO_DynUnion_i::init (CORBA::TypeCode_ptr tc
ACE_ENV_ARG_DECL)
{
CORBA::TCKind kind = TAO_DynAnyFactory::unalias (tc
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
if (kind != CORBA::tk_union)
{
ACE_THROW (DynamicAny::DynAnyFactory::InconsistentTypeCode ());
}
// Initialize the typecode holder and current index.
this->type_ = CORBA::TypeCode::_duplicate (tc);
this->init_common ();
// member_type()/member_label() do not work with aliased type codes.
CORBA::TypeCode_var unaliased_tc =
TAO_DynAnyFactory::strip_alias (this->type_.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
CORBA::Any_var first_label =
unaliased_tc->member_label (this->current_position_
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
// Initialize the discriminator to the label value of the first member.
this->discriminator_ =
TAO::MakeDynAnyUtils::make_dyn_any_t<const CORBA::Any&> (
first_label.in ()._tao_get_typecode (),
first_label.in ());
CORBA::TypeCode_var first_type =
unaliased_tc->member_type (this->current_position_
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
// Recursively initialize the member to its default value.
this->member_ =
TAO::MakeDynAnyUtils::make_dyn_any_t<CORBA::TypeCode_ptr> (
first_type.in (),
first_type.in ());
}
// ****************************************************************
TAO_DynUnion_i *
TAO_DynUnion_i::_narrow (CORBA::Object_ptr _tao_objref
ACE_ENV_ARG_DECL_NOT_USED)
{
if (CORBA::is_nil (_tao_objref))
{
return 0;
}
return dynamic_cast<TAO_DynUnion_i *> (_tao_objref);
}
// This code is common to from_any() and the init() overload that takes
// an Any argument.
void
TAO_DynUnion_i::set_from_any (const CORBA::Any & any
ACE_ENV_ARG_DECL)
ACE_THROW_SPEC ((
CORBA::SystemException,
DynamicAny::DynAny::TypeMismatch,
DynamicAny::DynAnyFactory::InconsistentTypeCode
))
{
// discriminator_type () does not work with aliased type codes,
// only on unions, so strip the alias out of the type code
//
CORBA::TypeCode_var tc =
TAO_DynAnyFactory::strip_alias (any._tao_get_typecode ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
CORBA::TypeCode_var disc_tc =
tc->discriminator_type (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
CORBA::Any disc_any;
TAO::Unknown_IDL_Type *unk = 0;
// Get a CDR stream - if the Any doesn't have one, make one.
TAO::Any_Impl *impl = any.impl ();
TAO_OutputCDR out;
TAO_InputCDR in (static_cast<ACE_Message_Block *> (0));
if (impl->encoded ())
{
TAO::Unknown_IDL_Type *tmp =
dynamic_cast<TAO::Unknown_IDL_Type *> (impl);
in = tmp->_tao_get_cdr ();
}
else
{
impl->marshal_value (out);
TAO_InputCDR tmp_in (out);
in = tmp_in;
}
TAO_InputCDR unk_in (in);
ACE_NEW (unk,
TAO::Unknown_IDL_Type (disc_tc.in (),
unk_in));
disc_any.replace (unk);
// Need this here because we might have been called from init().
if (!CORBA::is_nil (this->discriminator_.in ()))
{
this->discriminator_->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
}
// Set the discriminator.
this->discriminator_ =
TAO::MakeDynAnyUtils::make_dyn_any_t<const CORBA::Any&> (
disc_any._tao_get_typecode (),
disc_any);
// Move to the next field in the CDR stream.
(void) TAO_Marshal_Object::perform_skip (disc_tc.in (),
&in
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
CORBA::TypeCode_var unaliased =
TAO_DynAnyFactory::strip_alias (tc.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
CORBA::ULong const count =
unaliased->member_count (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
CORBA::Boolean match = false;
CORBA::ULong i;
// Get the index.
for (i = 0; i < count; ++i)
{
CORBA::Any_var label_any = tc->member_label (i
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
match = this->label_match (label_any.in (),
disc_any
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
if (match)
{
break;
}
}
// Need this here because we might have been called from init().
if (!CORBA::is_nil (this->member_.in ()))
{
this->member_->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
}
if (match)
{
CORBA::TypeCode_var member_tc =
tc->member_type (i
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
CORBA::Any member_any;
TAO::Unknown_IDL_Type *unk = 0;
ACE_NEW (unk,
TAO::Unknown_IDL_Type (member_tc.in (),
in));
member_any.replace (unk);
this->member_ =
TAO::MakeDynAnyUtils::make_dyn_any_t<const CORBA::Any&> (
member_any._tao_get_typecode (),
member_any);
this->member_slot_ = i;
}
else
{
// If no match, either the Any contains the default member or the
// type code was bad.
// default_index() does not work with aliased type codes.
CORBA::TypeCode_var unaliased_tc =
TAO_DynAnyFactory::strip_alias (this->type_.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
CORBA::Long default_index =
unaliased_tc->default_index (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
if (default_index == -1)
{
set_to_no_active_member (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
}
else
{
CORBA::ULong index = static_cast<CORBA::ULong> (default_index);
CORBA::TypeCode_var default_tc =
tc->member_type (index
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
CORBA::Any default_any;
TAO::Unknown_IDL_Type *unk = 0;
ACE_NEW (unk,
TAO::Unknown_IDL_Type (default_tc.in (),
in));
default_any.replace (unk);
this->member_ =
TAO::MakeDynAnyUtils::make_dyn_any_t<const CORBA::Any&> (
default_any._tao_get_typecode (),
default_any);
this->member_slot_ = index;
}
}
}
// ****************************************************************
DynamicAny::DynAny_ptr
TAO_DynUnion_i::get_discriminator (ACE_ENV_SINGLE_ARG_DECL)
ACE_THROW_SPEC ((
CORBA::SystemException
))
{
if (this->destroyed_)
{
ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (),
DynamicAny::DynAny::_nil ());
}
// A deep copy is made only by copy() (CORBA 2.4.2 section 9.2.3.6).
// Set the flag so the caller can't destroy.
this->set_flag (this->discriminator_.in (),
0
ACE_ENV_ARG_PARAMETER);
return DynamicAny::DynAny::_duplicate (this->discriminator_.in ());
}
void
TAO_DynUnion_i::set_discriminator (DynamicAny::DynAny_ptr value
ACE_ENV_ARG_DECL)
ACE_THROW_SPEC ((
CORBA::SystemException,
DynamicAny::DynAny::TypeMismatch
))
{
if (this->destroyed_)
{
ACE_THROW (CORBA::OBJECT_NOT_EXIST ());
}
CORBA::TypeCode_var tc = value->type (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
CORBA::TypeCode_var disc_tc =
this->discriminator_->type (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
CORBA::Boolean equivalent = disc_tc->equivalent (tc.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
if (!equivalent)
{
ACE_THROW (DynamicAny::DynAny::TypeMismatch ());
}
CORBA::Any_var value_any = value->to_any (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
CORBA::ULong length =
this->type_->member_count (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
CORBA::Any_var label_any;
CORBA::ULong i;
// member_label() does not work with aliased type codes.
CORBA::TypeCode_var unaliased_tc =
TAO_DynAnyFactory::strip_alias (this->type_.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
CORBA::Boolean match = 0;
for (i = 0; i < length; ++i)
{
label_any = unaliased_tc->member_label (i
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
match = this->label_match (label_any.in (),
value_any.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
if (match)
{
break;
}
}
if (match)
{
// If the incoming label value matches the one we already
// have, we do nothing.
if (i == this->member_slot_)
{
return;
}
// If we got a match, a named member will be active.
this->discriminator_->from_any (label_any.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
// member_type() does not work with aliased type codes.
CORBA::TypeCode_var member_tc =
unaliased_tc->member_type (i
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
this->member_->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
// Initialize member to default value.
this->member_ =
TAO::MakeDynAnyUtils::make_dyn_any_t<CORBA::TypeCode_ptr> (
member_tc.in (),
member_tc.in ());
// Named active member (CORBA 2.3.1).
this->current_position_ = 1;
this->component_count_ = 2;
this->member_slot_ = i;
}
else
{
// default_index() does not work with aliased type codes.
CORBA::TypeCode_var unaliased_tc =
TAO_DynAnyFactory::strip_alias (this->type_.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
// If no match, either the default member or no member is active.
CORBA::Long default_index =
unaliased_tc->default_index (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
if (default_index == -1)
{
// This can't throw InvalidValue - if there's no default case
// and all possible labels are used, we'd have had a match above.
this->set_to_no_active_member (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
}
else
{
this->set_to_default_member (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
this->member_slot_ = static_cast<CORBA::ULong> (default_index);
}
}
// If we get here, we update the discriminator no matter what.
// Any value will correspond to one of the three cases above.
this->discriminator_->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
this->discriminator_ = value->copy (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
}
void
TAO_DynUnion_i::set_to_default_member (ACE_ENV_SINGLE_ARG_DECL)
ACE_THROW_SPEC ((
CORBA::SystemException,
DynamicAny::DynAny::TypeMismatch
))
{
if (this->destroyed_)
{
ACE_THROW (CORBA::OBJECT_NOT_EXIST ());
}
// default_index() does not work with aliased type codes.
CORBA::TypeCode_var unaliased_tc =
TAO_DynAnyFactory::strip_alias (this->type_.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
CORBA::Long default_index =
unaliased_tc->default_index (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
if (default_index == -1)
{
// No explicit default case.
ACE_THROW (DynamicAny::DynAny::TypeMismatch ());
}
else
{
CORBA::ULong index = static_cast<CORBA::ULong> (default_index);
CORBA::TypeCode_var default_tc =
unaliased_tc->member_type (index
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
this->member_->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
this->member_ =
TAO::MakeDynAnyUtils::make_dyn_any_t<CORBA::TypeCode_ptr> (
default_tc.in (),
default_tc.in ());
// Default member active (CORBA 2.3.1).
this->current_position_ = 0;
this->component_count_ = 2;
this->member_slot_ = index;
}
}
void
TAO_DynUnion_i::set_to_no_active_member (ACE_ENV_SINGLE_ARG_DECL)
ACE_THROW_SPEC ((
CORBA::SystemException,
DynamicAny::DynAny::TypeMismatch
))
{
if (this->destroyed_)
{
ACE_THROW (CORBA::OBJECT_NOT_EXIST ());
}
// default_index() does not work with aliased type codes.
CORBA::TypeCode_var unaliased_tc =
TAO_DynAnyFactory::strip_alias (this->type_.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
CORBA::Long default_index =
unaliased_tc->default_index (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
// Throw an exception is there is an explicit default case or if all
// possible case label values are used.
if (default_index != -1)
{
ACE_THROW (DynamicAny::DynAny::TypeMismatch ());
}
else
{
CORBA::TypeCode_var disc_tc =
this->discriminator_->type (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
CORBA::TCKind kind =
TAO_DynAnyFactory::unalias (disc_tc.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
if (kind == CORBA::tk_enum)
{
CORBA::ULong const member_count =
this->type_->member_count (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
CORBA::ULong const label_count =
disc_tc->member_count (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
if (member_count == label_count)
{
ACE_THROW (DynamicAny::DynAny::TypeMismatch ());
}
}
}
// No active member (CORBA 2.3.1).
this->current_position_ = 0;
this->component_count_ = 1;
}
CORBA::Boolean
TAO_DynUnion_i::has_no_active_member (ACE_ENV_SINGLE_ARG_DECL)
ACE_THROW_SPEC ((
CORBA::SystemException
))
{
if (this->destroyed_)
{
ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (),
0);
}
// No active member (CORBA 2.3.1).
return (this->current_position_ == 0
&& this->component_count_ == 1);
}
CORBA::TCKind
TAO_DynUnion_i::discriminator_kind (ACE_ENV_SINGLE_ARG_DECL)
ACE_THROW_SPEC ((
CORBA::SystemException
))
{
if (this->destroyed_)
{
ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (),
CORBA::tk_null);
}
CORBA::TypeCode_var tc =
this->discriminator_->type (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (CORBA::tk_null);
CORBA::TCKind retval = TAO_DynAnyFactory::unalias (tc.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (CORBA::tk_null);
return retval;
}
DynamicAny::DynAny_ptr
TAO_DynUnion_i::member (ACE_ENV_SINGLE_ARG_DECL)
ACE_THROW_SPEC ((
CORBA::SystemException,
DynamicAny::DynAny::InvalidValue
))
{
if (this->destroyed_)
{
ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (),
DynamicAny::DynAny::_nil ());
}
CORBA::Boolean has_no_active_member =
this->has_no_active_member (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (DynamicAny::DynAny::_nil ());
if (has_no_active_member)
{
ACE_THROW_RETURN (DynamicAny::DynAny::InvalidValue (),
DynamicAny::DynAny::_nil ());
}
// A deep copy is made only by copy() (CORBA 2.4.2 section 9.2.3.6).
// Set the flag so the caller can't destroy.
this->set_flag (this->member_.in (),
0
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (DynamicAny::DynAny::_nil ());
return DynamicAny::DynAny::_duplicate (this->member_.in ());
}
char *
TAO_DynUnion_i::member_name (ACE_ENV_SINGLE_ARG_DECL)
ACE_THROW_SPEC ((
CORBA::SystemException,
DynamicAny::DynAny::InvalidValue
))
{
if (this->destroyed_)
{
ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (),
0);
}
CORBA::Boolean has_no_active_member =
this->has_no_active_member (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
if (has_no_active_member)
{
ACE_THROW_RETURN (DynamicAny::DynAny::InvalidValue (),
0);
}
const char *retval = this->type_->member_name (this->member_slot_
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
return CORBA::string_dup (retval);
}
CORBA::TCKind
TAO_DynUnion_i::member_kind (ACE_ENV_SINGLE_ARG_DECL)
ACE_THROW_SPEC ((
CORBA::SystemException,
DynamicAny::DynAny::InvalidValue
))
{
if (this->destroyed_)
{
ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (),
CORBA::tk_null);
}
CORBA::Boolean has_no_active_member =
this->has_no_active_member (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (CORBA::tk_null);
if (has_no_active_member)
{
ACE_THROW_RETURN (DynamicAny::DynAny::InvalidValue (),
CORBA::tk_null);
}
CORBA::TypeCode_var tc =
this->member_->type (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (CORBA::tk_null);
CORBA::TCKind retval = TAO_DynAnyFactory::unalias (tc.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (CORBA::tk_null);
return retval;
}
// ****************************************************************
void
TAO_DynUnion_i::from_any (const CORBA::Any& any
ACE_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 tc = any.type ();
CORBA::Boolean equivalent =
this->type_.in ()->equivalent (tc.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
if (equivalent)
{
// CORBA 2.3.1 section 9.2.3.3.
this->current_position_ = 0;
// May be changed in set_from_any().
this->component_count_ = 2;
// Set the from_factory arg to FALSE, so any problems will throw
// TypeMismatch.
this->set_from_any (any
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
}
else
{
ACE_THROW (DynamicAny::DynAny::TypeMismatch ());
}
}
CORBA::Any_ptr
TAO_DynUnion_i::to_any (ACE_ENV_SINGLE_ARG_DECL)
ACE_THROW_SPEC ((
CORBA::SystemException
))
{
if (this->destroyed_)
{
ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (),
0);
}
TAO_OutputCDR out_cdr;
// Add the discriminator to the CDR stream.
CORBA::TypeCode_var disc_tc =
this->discriminator_->type (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
CORBA::Any_var disc_any =
this->discriminator_->to_any (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
TAO::Any_Impl *disc_any_impl = disc_any->impl ();
TAO_OutputCDR disc_out_cdr;
TAO_InputCDR disc_in_cdr (static_cast<ACE_Message_Block *> (0));
if (disc_any_impl->encoded ())
{
TAO::Unknown_IDL_Type *disc_unk =
dynamic_cast<TAO::Unknown_IDL_Type *> (disc_any_impl);
disc_in_cdr = disc_unk->_tao_get_cdr ();
}
else
{
disc_any_impl->marshal_value (disc_out_cdr);
TAO_InputCDR disc_tmp_in_cdr (disc_out_cdr);
disc_in_cdr = disc_tmp_in_cdr;
}
(void) TAO_Marshal_Object::perform_append (disc_tc.in (),
&disc_in_cdr,
&out_cdr
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
// Add the member to the CDR stream unless it has no active member.
if (this->has_no_active_member () == 0)
{
CORBA::TypeCode_var member_tc =
this->member_->type (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
CORBA::Any_var member_any =
this->member_->to_any (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
TAO::Any_Impl *member_any_impl = member_any->impl ();
TAO_OutputCDR member_out_cdr;
TAO_InputCDR member_in_cdr (static_cast<ACE_Message_Block *> (0));
if (member_any_impl->encoded ())
{
TAO::Unknown_IDL_Type *member_unk =
dynamic_cast<TAO::Unknown_IDL_Type *> (member_any_impl);
member_in_cdr = member_unk->_tao_get_cdr ();
}
else
{
member_any_impl->marshal_value (member_out_cdr);
TAO_InputCDR member_tmp_in_cdr (member_out_cdr);
member_in_cdr = member_tmp_in_cdr;
}
(void) TAO_Marshal_Object::perform_append (member_tc.in (),
&member_in_cdr,
&out_cdr
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
}
// Make the Any.
TAO_InputCDR in_cdr (out_cdr);
CORBA::Any_ptr retval = 0;
ACE_NEW_THROW_EX (retval,
CORBA::Any,
CORBA::NO_MEMORY ());
ACE_CHECK_RETURN (0);
TAO::Unknown_IDL_Type *unk = 0;
ACE_NEW_THROW_EX (unk,
TAO::Unknown_IDL_Type (this->type_.in (),
in_cdr),
CORBA::NO_MEMORY ());
ACE_CHECK_RETURN (0);
retval->replace (unk);
return retval;
}
CORBA::Boolean
TAO_DynUnion_i::equal (DynamicAny::DynAny_ptr rhs
ACE_ENV_ARG_DECL)
ACE_THROW_SPEC ((
CORBA::SystemException
))
{
if (this->destroyed_)
{
ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (),
0);
}
TAO_DynUnion_i *impl = TAO_DynUnion_i::_narrow (rhs
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
if (impl == 0)
{
return 0;
}
CORBA::Boolean equivalent =
this->type_->equivalent (impl->type_.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
if (!equivalent)
{
return 0;
}
CORBA::Boolean member_equal =
this->member_->equal (impl->member_.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
CORBA::Boolean disc_equal =
this->discriminator_->equal (impl->discriminator_.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
impl->_remove_ref ();
return (member_equal && disc_equal);
}
void
TAO_DynUnion_i::destroy (ACE_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_)
{
// Free the two components.
this->set_flag (this->member_.in (),
1
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
this->member_->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
this->set_flag (this->discriminator_.in (),
1
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
this->discriminator_->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
this->destroyed_ = 1;
}
}
DynamicAny::DynAny_ptr
TAO_DynUnion_i::current_component (ACE_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 ());
}
if (this->current_position_ == 1)
{
this->set_flag (this->member_.in (),
0
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (DynamicAny::DynAny::_nil ());
return DynamicAny::DynAny::_duplicate (this->member_.in ());
}
else
{
this->set_flag (this->discriminator_.in (),
0
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (DynamicAny::DynAny::_nil ());
return DynamicAny::DynAny::_duplicate (this->discriminator_.in ());
}
}
// ****************************************************************
CORBA::Boolean
TAO_DynUnion_i::label_match (const CORBA::Any &my_any,
const CORBA::Any &other_any
ACE_ENV_ARG_DECL)
ACE_THROW_SPEC ((
CORBA::SystemException
))
{
// Use my_any so we can detect a default case label,
// if we are iterating through the union type code's
// member_label() calls.
CORBA::TypeCode_var tc = my_any.type ();
CORBA::TCKind kind = TAO_DynAnyFactory::unalias (tc.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
// No need to do any type checking - it was done before this
// call was made.
switch (kind)
{
case CORBA::tk_octet:
// Default case label - just skip it.
return 0;
case CORBA::tk_short:
{
CORBA::Short my_val;
CORBA::Short other_val;
my_any >>= my_val;
other_any >>= other_val;
return my_val == other_val;
}
case CORBA::tk_long:
{
CORBA::Long my_val;
CORBA::Long other_val;
my_any >>= my_val;
other_any >>= other_val;
return my_val == other_val;
}
case CORBA::tk_ushort:
{
CORBA::UShort my_val;
CORBA::UShort other_val;
my_any >>= my_val;
other_any >>= other_val;
return my_val == other_val;
}
case CORBA::tk_ulong:
{
CORBA::ULong my_val;
CORBA::ULong other_val;
my_any >>= my_val;
other_any >>= other_val;
return my_val == other_val;
}
case CORBA::tk_boolean:
{
CORBA::Boolean my_val;
CORBA::Boolean other_val;
my_any >>= CORBA::Any::to_boolean (my_val);
other_any >>= CORBA::Any::to_boolean (other_val);
return my_val == other_val;
}
case CORBA::tk_char:
{
CORBA::Char my_val;
CORBA::Char other_val;
my_any >>= CORBA::Any::to_char (my_val);
other_any >>= CORBA::Any::to_char (other_val);
return my_val == other_val;
}
// For platforms without native 64-bit ints.
#if !defined (ACE_LACKS_LONGLONG_T)
case CORBA::tk_longlong:
{
CORBA::LongLong my_val;
CORBA::LongLong other_val;
my_any >>= my_val;
other_any >>= other_val;
return my_val == other_val;
}
#endif /* ACE_LACKS_LONGLONG_T */
case CORBA::tk_ulonglong:
{
CORBA::ULongLong my_val;
CORBA::ULongLong other_val;
my_any >>= my_val;
other_any >>= other_val;
return my_val == other_val;
}
case CORBA::tk_wchar:
{
CORBA::WChar my_val;
CORBA::WChar other_val;
my_any >>= CORBA::Any::to_wchar (my_val);
other_any >>= CORBA::Any::to_wchar (other_val);
return my_val == other_val;
}
case CORBA::tk_enum:
{
CORBA::ULong my_val;
CORBA::ULong other_val;
TAO::Any_Impl *my_impl = my_any.impl ();
if (my_impl->encoded ())
{
TAO::Unknown_IDL_Type *my_unk =
dynamic_cast<TAO::Unknown_IDL_Type *> (my_impl);
// We don't want unk's rd_ptr to move, in case we are shared by
// another Any, so we use this to copy the state, not the buffer.
TAO_InputCDR for_reading (my_unk->_tao_get_cdr ());
for_reading.read_ulong (my_val);
}
else
{
TAO_OutputCDR my_out;
my_impl->marshal_value (my_out);
TAO_InputCDR my_in (my_out);
my_in.read_ulong (my_val);
}
TAO::Any_Impl *other_impl = other_any.impl ();
if (other_impl->encoded ())
{
TAO::Unknown_IDL_Type *other_unk =
dynamic_cast<TAO::Unknown_IDL_Type *> (other_impl);
// We don't want unk's rd_ptr to move, in case we are shared by
// another Any, so we use this to copy the state, not the buffer.
TAO_InputCDR for_reading (other_unk->_tao_get_cdr ());
for_reading.read_ulong (other_val);
}
else
{
TAO_OutputCDR other_out;
other_impl->marshal_value (other_out);
TAO_InputCDR other_in (other_out);
other_in.read_ulong (other_val);
}
return my_val == other_val;
}
// Cannot happen - we've covered all the legal discriminator types.
default:
return 0;
}
}
TAO_END_VERSIONED_NAMESPACE_DECL
|