line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: TypeCode.pm,v 1.1.1.1 1997/05/17 11:47:05 schuller Exp $ |
2
|
|
|
|
|
|
|
# Copyright (c) 1997 Lunatech Research / Bart Schuller |
3
|
|
|
|
|
|
|
# See the file "Artistic" in the distribution for licensing and |
4
|
|
|
|
|
|
|
# (lack of) warranties. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package COPE::CORBA::TypeCode; |
7
|
|
|
|
|
|
|
sub import { |
8
|
6
|
|
|
6
|
|
12
|
shift; |
9
|
6
|
|
|
|
|
18
|
my $callpkg = caller(0); |
10
|
6
|
|
|
|
|
918
|
CORBA::TypeCode->export($callpkg, @_); |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# interface TypeCode // PIDL |
14
|
|
|
|
|
|
|
package CORBA::TypeCode; |
15
|
3
|
|
|
3
|
|
13
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
176
|
|
16
|
|
|
|
|
|
|
require Exporter; |
17
|
|
|
|
|
|
|
@CORBA::TypeCode::ISA = qw(Exporter); |
18
|
|
|
|
|
|
|
@CORBA::TypeCode::EXPORT = qw( |
19
|
|
|
|
|
|
|
_create_struct_tc _create_union_tc _create_enum_tc |
20
|
|
|
|
|
|
|
_create_alias_tc _create_exception_tc _create_interface_tc |
21
|
|
|
|
|
|
|
_create_string_tc _create_sequence_tc |
22
|
|
|
|
|
|
|
_create_recursive_sequence_tc _create_array_tc |
23
|
|
|
|
|
|
|
); |
24
|
3
|
|
|
3
|
|
3001
|
use COPE::CORBA::TCKind; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
18
|
|
25
|
|
|
|
|
|
|
@CORBA::_tc_basic = ( |
26
|
|
|
|
|
|
|
$CORBA::_tc_null = CORBA::TypeCode->_new_basic(tk_null), |
27
|
|
|
|
|
|
|
$CORBA::_tc_void = CORBA::TypeCode->_new_basic(tk_void), |
28
|
|
|
|
|
|
|
$CORBA::_tc_short = CORBA::TypeCode->_new_basic(tk_short), |
29
|
|
|
|
|
|
|
$CORBA::_tc_long = CORBA::TypeCode->_new_basic(tk_long), |
30
|
|
|
|
|
|
|
$CORBA::_tc_ushort = CORBA::TypeCode->_new_basic(tk_ushort), |
31
|
|
|
|
|
|
|
$CORBA::_tc_ulong = CORBA::TypeCode->_new_basic(tk_ulong), |
32
|
|
|
|
|
|
|
$CORBA::_tc_float = CORBA::TypeCode->_new_basic(tk_float), |
33
|
|
|
|
|
|
|
$CORBA::_tc_double = CORBA::TypeCode->_new_basic(tk_double), |
34
|
|
|
|
|
|
|
$CORBA::_tc_boolean = CORBA::TypeCode->_new_basic(tk_boolean), |
35
|
|
|
|
|
|
|
$CORBA::_tc_char = CORBA::TypeCode->_new_basic(tk_char), |
36
|
|
|
|
|
|
|
$CORBA::_tc_octet = CORBA::TypeCode->_new_basic(tk_octet), |
37
|
|
|
|
|
|
|
$CORBA::_tc_any = CORBA::TypeCode->_new_basic(tk_any), |
38
|
|
|
|
|
|
|
$CORBA::_tc_TypeCode = CORBA::TypeCode->_new_basic(tk_TypeCode), |
39
|
|
|
|
|
|
|
$CORBA::_tc_Principal = CORBA::TypeCode->_new_basic(tk_Principal), |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my(%has_id_and_name) = map { $_ => 1 } (tk_objref, tk_struct, tk_union, tk_enum, tk_alias, tk_except); |
43
|
|
|
|
|
|
|
my(%has_members) = map { $_ => 1 } (tk_struct, tk_union, tk_enum, tk_except); |
44
|
|
|
|
|
|
|
my(%has_type) = map { $_ => 1 } (tk_sequence, tk_array, tk_alias); |
45
|
|
|
|
|
|
|
my(%has_length) = map { $_ => 1 } (tk_sequence, tk_array); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _new_basic { |
48
|
42
|
|
|
42
|
|
47
|
my($class, $tk) = @_; |
49
|
42
|
|
|
|
|
174
|
return bless {_kind => $tk}, $class; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _unmarshal { |
53
|
0
|
|
|
0
|
|
|
my $kind = CORBA::ORB::_unmarshal_ulong(@_); |
54
|
0
|
|
|
|
|
|
my $self = {}; |
55
|
0
|
0
|
|
|
|
|
if ($kind <= 13) { |
56
|
0
|
|
|
|
|
|
return $CORBA::_tc_basic[$kind]; |
57
|
|
|
|
|
|
|
} else { |
58
|
0
|
|
|
|
|
|
$self->{_kind} = $kind; |
59
|
|
|
|
|
|
|
} |
60
|
0
|
0
|
|
|
|
|
if ($self->{_kind} == 0xffffffff) { |
|
|
0
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
die "CORBA::TypeCode::_unmarshal got an indirection: " . CORBA::ORB::_unmarshal_ulong(@_); |
62
|
|
|
|
|
|
|
} elsif ($self->{_kind} == tk_string) { |
63
|
0
|
|
|
|
|
|
$self->{_length} = CORBA::ORB::_unmarshal_ulong(@_); |
64
|
|
|
|
|
|
|
} else { |
65
|
|
|
|
|
|
|
# |
66
|
|
|
|
|
|
|
# if we get here, we have parameters in "complex" encoding. |
67
|
|
|
|
|
|
|
# |
68
|
0
|
|
|
|
|
|
my($byte_order) = $_[2]; |
69
|
0
|
|
|
|
|
|
my($cdrin, $index) = ('', 0); |
70
|
0
|
|
|
|
|
|
$cdrin = CORBA::ORB::_unmarshal_octet_sequence(@_); |
71
|
0
|
|
|
|
|
|
@_ = (\$cdrin, \$index, $byte_order); |
72
|
0
|
|
|
|
|
|
$byte_order = $_[2] = CORBA::ORB::_unmarshal_boolean(@_); |
73
|
0
|
0
|
|
|
|
|
if ($has_id_and_name{$self->{_kind}}) { |
74
|
0
|
|
|
|
|
|
$self->{_id} = CORBA::ORB::_unmarshal_string(@_); |
75
|
0
|
|
|
|
|
|
$self->{_name} = CORBA::ORB::_unmarshal_string(@_); |
76
|
|
|
|
|
|
|
} |
77
|
0
|
0
|
|
|
|
|
if ($self->{_kind} == tk_union) { |
78
|
0
|
|
|
|
|
|
$self->{_discriminator_type} = CORBA::TypeCode::_unmarshal(@_); |
79
|
0
|
|
|
|
|
|
$self->{_default_index} = CORBA::ORB::_unmarshal_long(@_); |
80
|
|
|
|
|
|
|
} |
81
|
0
|
0
|
|
|
|
|
if ($has_members{$self->{_kind}}) { |
|
|
0
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my($count) = CORBA::ORB::_unmarshal_ulong(@_); |
83
|
0
|
|
|
|
|
|
$self->{_members} = []; |
84
|
0
|
0
|
0
|
|
|
|
if ($self->{_kind} == tk_enum) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
while ($count--) { |
86
|
0
|
|
|
|
|
|
push @{$self->{_members}}, {_name => CORBA::ORB::_unmarshal_string(@_)}; |
|
0
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} elsif (($self->{_kind} == tk_struct) || ($self->{_kind} == tk_except)) { |
89
|
0
|
|
|
|
|
|
while ($count--) { |
90
|
0
|
|
|
|
|
|
my $member = {}; |
91
|
0
|
|
|
|
|
|
$member->{_name} = CORBA::ORB::_unmarshal_string(@_); |
92
|
0
|
|
|
|
|
|
$member->{_type} = CORBA::TypeCode::_unmarshal(@_); |
93
|
0
|
|
|
|
|
|
push @{$self->{_members}}, $member; |
|
0
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} elsif ($self->{_kind} == tk_union) { |
96
|
0
|
|
|
|
|
|
while ($count--) { |
97
|
0
|
|
|
|
|
|
my $member = {}; |
98
|
0
|
0
|
|
|
|
|
if ($self->{_discriminator_type}->kind == tk_short) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
$member->{_label} = CORBA::ORB::_unmarshal_short(@_); |
100
|
|
|
|
|
|
|
} elsif ($self->{_discriminator_type}->kind == tk_ushort) { |
101
|
0
|
|
|
|
|
|
$member->{_label} = CORBA::ORB::_unmarshal_ushort(@_); |
102
|
|
|
|
|
|
|
} elsif ($self->{_discriminator_type}->kind == tk_long) { |
103
|
0
|
|
|
|
|
|
$member->{_label} = CORBA::ORB::_unmarshal_long(@_); |
104
|
|
|
|
|
|
|
} elsif ($self->{_discriminator_type}->kind == tk_ulong) { |
105
|
0
|
|
|
|
|
|
$member->{_label} = CORBA::ORB::_unmarshal_ulong(@_); |
106
|
|
|
|
|
|
|
} elsif ($self->{_discriminator_type}->kind == tk_boolean) { |
107
|
0
|
|
|
|
|
|
$member->{_label} = CORBA::ORB::_unmarshal_boolean(@_); |
108
|
|
|
|
|
|
|
} elsif ($self->{_discriminator_type}->kind == tk_char) { |
109
|
0
|
|
|
|
|
|
$member->{_label} = CORBA::ORB::_unmarshal_char(@_); |
110
|
|
|
|
|
|
|
} elsif ($self->{_discriminator_type}->kind == tk_enum) { |
111
|
0
|
|
|
|
|
|
$member->{_label} = CORBA::ORB::_unmarshal_enum(@_); |
112
|
|
|
|
|
|
|
} |
113
|
0
|
|
|
|
|
|
$member->{_name} = CORBA::ORB::_unmarshal_string(@_); |
114
|
0
|
|
|
|
|
|
$member->{_type} = CORBA::TypeCode::_unmarshal(@_); |
115
|
0
|
|
|
|
|
|
push @{$self->{_members}}, $member; |
|
0
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} elsif ($has_type{$self->{_kind}}) { |
119
|
0
|
|
|
|
|
|
$self->{_type} = CORBA::TypeCode::_unmarshal(@_); |
120
|
|
|
|
|
|
|
} |
121
|
0
|
0
|
|
|
|
|
if ($has_length{$self->{_kind}}) { |
122
|
0
|
|
|
|
|
|
$self->{_length} = CORBA::ORB::_unmarshal_ulong(@_); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} |
125
|
0
|
|
|
|
|
|
return bless $self, 'CORBA::TypeCode'; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub kind { |
129
|
0
|
|
|
0
|
|
|
my($self) = @_; |
130
|
0
|
|
|
|
|
|
return $self->{_kind}; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub id { |
134
|
0
|
|
|
0
|
|
|
my($self) = @_; |
135
|
0
|
|
|
|
|
|
return $self->{_id}; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub name { |
139
|
0
|
|
|
0
|
|
|
my($self) = @_; |
140
|
0
|
|
|
|
|
|
return $self->{_name}; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub content_type { |
144
|
0
|
|
|
0
|
|
|
my($self) = @_; |
145
|
0
|
|
|
|
|
|
return $self->{_type}; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub member_count { |
149
|
0
|
|
|
0
|
|
|
my($self) = @_; |
150
|
0
|
|
|
|
|
|
return scalar @{$self->{_members}}; |
|
0
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub member_name { |
154
|
0
|
|
|
0
|
|
|
my($self, $index) = @_; |
155
|
0
|
|
|
|
|
|
return $self->{_members}[$index]{_name}; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub member_type { |
159
|
0
|
|
|
0
|
|
|
my($self, $index) = @_; |
160
|
0
|
|
|
|
|
|
return $self->{_members}[$index]{_type}; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub length { |
164
|
0
|
|
|
0
|
|
|
my($self) = @_; |
165
|
0
|
|
|
|
|
|
return $self->{_length}; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub _create_alias_tc ($$$) { |
169
|
0
|
|
|
0
|
|
|
my($id,$name,$original_type) = @_; |
170
|
0
|
|
|
|
|
|
my $tc = { _kind => tk_alias, |
171
|
|
|
|
|
|
|
_id => $id, |
172
|
|
|
|
|
|
|
_name => $name, |
173
|
|
|
|
|
|
|
_type => $original_type, |
174
|
|
|
|
|
|
|
}; |
175
|
0
|
|
|
|
|
|
return bless $tc, 'CORBA::TypeCode'; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub _create_struct_tc ($$$) { |
179
|
0
|
|
|
0
|
|
|
my($id,$name,$members) = @_; |
180
|
0
|
|
|
|
|
|
my $tc = { _kind => tk_struct, |
181
|
|
|
|
|
|
|
_id => $id, |
182
|
|
|
|
|
|
|
_name => $name, |
183
|
|
|
|
|
|
|
_members => [], |
184
|
|
|
|
|
|
|
}; |
185
|
0
|
|
|
|
|
|
my @members = @$members; |
186
|
0
|
|
|
|
|
|
while (my($n,$t) = splice(@members, 0, 2)) { |
187
|
0
|
|
|
|
|
|
push @{$tc->{_members}}, {_name => $n, _type => $t}; |
|
0
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
} |
189
|
0
|
|
|
|
|
|
return bless $tc, 'CORBA::TypeCode'; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
sub _create_exception_tc ($$$) { |
193
|
0
|
|
|
0
|
|
|
my($id,$name,$members) = @_; |
194
|
0
|
|
|
|
|
|
my $tc = { _kind => tk_except, |
195
|
|
|
|
|
|
|
_id => $id, |
196
|
|
|
|
|
|
|
_name => $name, |
197
|
|
|
|
|
|
|
_members => [], |
198
|
|
|
|
|
|
|
}; |
199
|
0
|
|
|
|
|
|
my @members = @$members; |
200
|
0
|
|
|
|
|
|
while (my($n,$t) = splice(@members, 0, 2)) { |
201
|
0
|
|
|
|
|
|
push @{$tc->{_members}}, {_name => $n, _type => $t}; |
|
0
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
} |
203
|
0
|
|
|
|
|
|
return bless $tc, 'CORBA::TypeCode'; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
sub _create_enum_tc ($$$) { |
207
|
0
|
|
|
0
|
|
|
my($id,$name,$members) = @_; |
208
|
0
|
|
|
|
|
|
my $tc = { _kind => tk_enum, |
209
|
|
|
|
|
|
|
_id => $id, |
210
|
|
|
|
|
|
|
_name => $name, |
211
|
|
|
|
|
|
|
_members => $members, |
212
|
|
|
|
|
|
|
}; |
213
|
0
|
|
|
|
|
|
return bless $tc, 'CORBA::TypeCode'; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub _create_sequence_tc ($$) { |
217
|
0
|
|
|
0
|
|
|
my($bound,$element_type) = @_; |
218
|
0
|
|
|
|
|
|
my $tc = { _kind => tk_sequence, |
219
|
|
|
|
|
|
|
_length => $bound, |
220
|
|
|
|
|
|
|
_type => $element_type, |
221
|
|
|
|
|
|
|
}; |
222
|
0
|
|
|
|
|
|
return bless $tc, 'CORBA::TypeCode'; |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
sub _create_array_tc ($$) { |
226
|
0
|
|
|
0
|
|
|
my($bound,$element_type) = @_; |
227
|
0
|
|
|
|
|
|
my $tc = { _kind => tk_array, |
228
|
|
|
|
|
|
|
_length => $bound, |
229
|
|
|
|
|
|
|
_type => $element_type, |
230
|
|
|
|
|
|
|
}; |
231
|
0
|
|
|
|
|
|
return bless $tc, 'CORBA::TypeCode'; |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
sub _create_string_tc ($) { |
235
|
0
|
|
|
0
|
|
|
my($bound) = @_; |
236
|
0
|
|
|
|
|
|
my $tc = { _kind => tk_string, |
237
|
|
|
|
|
|
|
_length => $bound, |
238
|
|
|
|
|
|
|
}; |
239
|
0
|
|
|
|
|
|
return bless $tc, 'CORBA::TypeCode'; |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
sub _create_interface_tc ($$) { |
243
|
0
|
|
|
0
|
|
|
my($id, $name) = @_; |
244
|
0
|
|
|
|
|
|
my $tc = { _kind => tk_objref, |
245
|
|
|
|
|
|
|
_id => $id, |
246
|
|
|
|
|
|
|
_name => $name, |
247
|
|
|
|
|
|
|
}; |
248
|
0
|
|
|
|
|
|
return bless $tc, 'CORBA::TypeCode'; |
249
|
|
|
|
|
|
|
} |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
sub _noalias_kind { |
252
|
0
|
|
|
0
|
|
|
my($self) = @_; |
253
|
0
|
|
|
|
|
|
while ($self->kind() == tk_alias) { |
254
|
0
|
|
|
|
|
|
$self = $self->content_type(); |
255
|
|
|
|
|
|
|
} |
256
|
0
|
|
|
|
|
|
return $self->kind(); |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
sub _noalias_content_type { |
260
|
0
|
|
|
0
|
|
|
my($self) = @_; |
261
|
0
|
|
|
|
|
|
while ($self->kind() == tk_alias) { |
262
|
0
|
|
|
|
|
|
$self = $self->content_type(); |
263
|
|
|
|
|
|
|
} |
264
|
0
|
|
|
|
|
|
return $self->content_type(); |
265
|
|
|
|
|
|
|
} |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
sub _needs_ref ($$) { |
268
|
0
|
|
|
0
|
|
|
my($self, $mode) = @_; |
269
|
|
|
|
|
|
|
|
270
|
0
|
0
|
|
|
|
|
return 0 if $mode == 0; # in parameters never need pass by reference |
271
|
0
|
|
|
|
|
|
my $kind = $self->kind(); |
272
|
0
|
0
|
0
|
|
|
|
if (($kind <= tk_octet) || ($kind == tk_Principal) || ($kind == tk_enum) || |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
273
|
|
|
|
|
|
|
($kind == tk_string)) { |
274
|
0
|
|
|
|
|
|
return 1; |
275
|
|
|
|
|
|
|
} |
276
|
0
|
0
|
|
|
|
|
if ($kind == tk_alias) { |
277
|
0
|
|
|
|
|
|
return $self->content_type->_needs_ref($mode); |
278
|
|
|
|
|
|
|
} |
279
|
0
|
0
|
0
|
|
|
|
if (($kind == tk_sequence) && ($self->content_type()->kind() == tk_octet)) { |
280
|
0
|
|
|
|
|
|
return 1; # octet-sequence implemented as a scalar |
281
|
|
|
|
|
|
|
} |
282
|
0
|
|
|
|
|
|
return 0; |
283
|
|
|
|
|
|
|
} |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
1; |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
__END__ |