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
|
// $Id$
#include "testC.h"
#include "tao/IFR_Client/IFR_BasicC.h"
#include "tao/TypeCodeFactory/TypeCodeFactory_Adapter_Impl.h"
ACE_RCSID(TypeCode_Creation, main, "$Id$")
int main(int argc, char *argv[])
{
ACE_TRY_NEW_ENV
{
CORBA::ORB_var orb = CORBA::ORB_init (argc,
argv,
""
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
CORBA::TypeCode_var iface_tc =
orb->create_interface_tc (CORBA::string_dup ("IDL:iface:1.0"),
CORBA::string_dup ("iface")
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
CORBA::ULong length = 5;
CORBA::UnionMemberSeq foo_members (length);
foo_members.length (length);
// The first three members are multiple case labels for a
// single string member. The label values are not in order
// or consecutive.
foo_members[0].name = CORBA::string_dup ("foo_str_member");
// The type member of the UnionMember takes ownership.
foo_members[0].type = CORBA::TypeCode::_duplicate (CORBA::_tc_string);
// Not needed for ORB-created typecodes
// (see CORBA 2.4.2 section 10.7.3).
foo_members[0].type_def = CORBA::IDLType::_nil ();
CORBA::Short label_value = -3;
foo_members[0].label <<= label_value;
foo_members[1].name = CORBA::string_dup ("foo_str_member");
foo_members[1].type = CORBA::TypeCode::_duplicate (CORBA::_tc_string);
foo_members[1].type_def = CORBA::IDLType::_nil ();
label_value = 4;
foo_members[1].label <<= label_value;
foo_members[2].name = CORBA::string_dup ("foo_str_member");
foo_members[2].type = CORBA::TypeCode::_duplicate (CORBA::_tc_string);
foo_members[2].type_def = CORBA::IDLType::_nil ();
label_value = -1;
foo_members[2].label <<= label_value;
// The default member.
foo_members[3].name = CORBA::string_dup ("foo_iface_member");
foo_members[3].type = CORBA::TypeCode::_duplicate (iface_tc.in ());
foo_members[3].type_def = CORBA::IDLType::_nil ();
CORBA::Octet default_label_value = 0;
foo_members[3].label <<= CORBA::Any::from_octet (default_label_value);
// The last member is the same type as the previous one, but has
// a different name.
foo_members[4].name = CORBA::string_dup ("foo_iface_member2");
foo_members[4].type = CORBA::TypeCode::_duplicate (iface_tc.in ());
foo_members[4].type_def = CORBA::IDLType::_nil ();
label_value = 0;
foo_members[4].label <<= label_value;
CORBA::TypeCode_ptr foo_tc = orb->create_union_tc ("IDL:foo:1.0",
"foo",
CORBA::_tc_short,
foo_members
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
length = 2;
CORBA::StructMemberSeq bar_members (length);
bar_members.length (length);
bar_members[0].name = CORBA::string_dup ("bar_long_member");
bar_members[0].type = CORBA::TypeCode::_duplicate (CORBA::_tc_long);
bar_members[0].type_def = CORBA::IDLType::_nil ();
bar_members[1].name = CORBA::string_dup ("bar_foo_member");
bar_members[1].type = foo_tc;
bar_members[1].type_def = CORBA::IDLType::_nil ();
CORBA::TypeCode_var bar_tc = orb->create_struct_tc ("IDL:bar:1.0",
"bar",
bar_members
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
// Check for equality with the typecode created by the IDL compiler.
CORBA::Boolean eq = bar_tc->equal (_tc_bar
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
if (!eq)
{
ACE_ERROR_RETURN ((LM_ERROR,
"ORB-created typecode not correct!\n"),
-1);
}
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
"exception:");
return 1;
}
ACE_ENDTRY;
return 0;
}
|