| 1 | |||
| 2 | # | ||
| 3 | # Interface Definition Language (OMG IDL CORBA v3.0) | ||
| 4 | # | ||
| 5 | |||
| 6 | package CORBA::Perl::ClientVisitor; | ||
| 7 | |||
| 8 | use strict; | ||
| 9 | use warnings; | ||
| 10 | |||
| 11 | our $VERSION = '0.43'; | ||
| 12 | |||
| 13 | use CORBA::Perl::CdrVisitor; | ||
| 14 | use base qw(CORBA::Perl::CdrVisitor); | ||
| 15 | |||
| 16 | use File::Basename; | ||
| 17 | use POSIX qw(ctime); | ||
| 18 | |||
| 19 | # needs $node->{pl_name} $node->{pl_package} (PerlNameVisitor) | ||
| 20 | |||
| 21 | sub new { | ||
| 22 | my $proto = shift; | ||
| 23 | my $class = ref($proto) || $proto; | ||
| 24 | my $self = {}; | ||
| 25 | bless $self, $class; | ||
| 26 | my($parser, $pkg_prefix) = @_; | ||
| 27 | $self->{srcname} = $parser->YYData->{srcname}; | ||
| 28 | $self->{srcname_size} = $parser->YYData->{srcname_size}; | ||
| 29 | $self->{srcname_mtime} = $parser->YYData->{srcname_mtime}; | ||
| 30 | $self->{symbtab} = $parser->YYData->{symbtab}; | ||
| 31 | $self->{client} = 1; | ||
| 32 | $self->{miop} = 0; | ||
| 33 | $self->{use} = {}; | ||
| 34 | if ($pkg_prefix) { | ||
| 35 | $self->{pkg_prefix} = $pkg_prefix; | ||
| 36 | $self->{pkg_prefix} =~ s/\//::/g; | ||
| 37 | $self->{pkg_prefix} .= '::'; | ||
| 38 | } | ||
| 39 | else { | ||
| 40 | $self->{pkg_prefix} = q{}; | ||
| 41 | } | ||
| 42 | my $filename = basename($self->{srcname}, '.idl') . '.pm'; | ||
| 43 | $self->open_stream($filename); | ||
| 44 | $self->{done_hash} = {}; | ||
| 45 | $self->{num_key} = 'num_pl_cli'; | ||
| 46 | $self->{pkg_modif} = 0; | ||
| 47 | $self->{stringify} = 1; | ||
| 48 | $self->{id} = 1; | ||
| 49 | return $self; | ||
| 50 | } | ||
| 51 | |||
| 52 | # | ||
| 53 | # 3.5 OMG IDL Specification | ||
| 54 | # | ||
| 55 | |||
| 56 | sub visitSpecification { | ||
| 57 | my $self = shift; | ||
| 58 | my($node) = @_; | ||
| 59 | my $FH = $self->{out}; | ||
| 60 | $self->{pkg_modif} = 0; | ||
| 61 | print $FH "# ex: set ro:\n"; | ||
| 62 | print $FH "# This file was generated (by ",$0,"). DO NOT modify it.\n"; | ||
| 63 | print $FH "# From file : ",$self->{srcname},", ",$self->{srcname_size}," octets, ",POSIX::ctime($self->{srcname_mtime}); | ||
| 64 | print $FH "\n"; | ||
| 65 | print $FH "use strict;\n"; | ||
| 66 | print $FH "use warnings;\n"; | ||
| 67 | print $FH "\n"; | ||
| 68 | print $FH "package main;\n"; | ||
| 69 | print $FH "\n"; | ||
| 70 | print $FH "use CORBA::Perl::rpc_giop;\n"; | ||
| 71 | print $FH "use Carp;\n"; | ||
| 72 | print $FH "\n"; | ||
| 73 | if (exists $node->{list_import}) { | ||
| 74 | foreach (@{$node->{list_import}}) { | ||
| 75 | $_->visit($self); | ||
| 76 | } | ||
| 77 | } | ||
| 78 | foreach (@{$node->{list_decl}}) { | ||
| 79 | $self->_get_defn($_)->visit($self); | ||
| 80 | if ($self->{pkg_modif}) { | ||
| 81 | $self->{pkg_modif} = 0; | ||
| 82 | print $FH "package main;\n"; | ||
| 83 | print $FH "\n"; | ||
| 84 | } | ||
| 85 | } | ||
| 86 | print $FH "1;\n"; | ||
| 87 | print $FH "\n"; | ||
| 88 | print $FH "# end of file : ",$self->{filename},"\n"; | ||
| 89 | print $FH "\n"; | ||
| 90 | print $FH "# Local variables:\n"; | ||
| 91 | print $FH "# buffer-read-only: t\n"; | ||
| 92 | print $FH "# End:\n"; | ||
| 93 | close $FH; | ||
| 94 | } | ||
| 95 | |||
| 96 | # | ||
| 97 | # 3.7 Module Declaration (inherited) | ||
| 98 | # | ||
| 99 | |||
| 100 | # | ||
| 101 | # 3.8 Interface Declaration | ||
| 102 | # | ||
| 103 | |||
| 104 | sub visitRegularInterface { | ||
| 105 | my $self = shift; | ||
| 106 | my($node) = @_; | ||
| 107 | if ($self->{srcname} eq $node->{filename}) { | ||
| 108 | my $FH = $self->{out}; | ||
| 109 | $self->{pkg_modif} = 0; | ||
| 110 | print $FH "#\n"; | ||
| 111 | print $FH "# begin of interface ",$node->{pl_package},"\n"; | ||
| 112 | print $FH "#\n"; | ||
| 113 | print $FH "\n"; | ||
| 114 | print $FH "package ",$node->{pl_package},";\n"; | ||
| 115 | print $FH "\n"; | ||
| 116 | print $FH "use CORBA::Perl::CORBA;\n"; | ||
| 117 | print $FH "use Carp;\n"; | ||
| 118 | print $FH "\n"; | ||
| 119 | foreach (@{$node->{list_decl}}) { | ||
| 120 | my $defn = $self->_get_defn($_); | ||
| 121 | if ( $defn->isa('Operation') | ||
| 122 | or $defn->isa('Attributes') ) { | ||
| 123 | next; | ||
| 124 | } | ||
| 125 | $defn->visit($self); | ||
| 126 | if ($self->{pkg_modif}) { | ||
| 127 | $self->{pkg_modif} = 0; | ||
| 128 | print $FH "package ",$node->{pl_package},";\n"; | ||
| 129 | print $FH "\n"; | ||
| 130 | } | ||
| 131 | } | ||
| 132 | print $FH "\n"; | ||
| 133 | if (keys %{$node->{hash_attribute_operation}}) { | ||
| 134 | $self->{itf} = $node->{pl_name}; | ||
| 135 | $self->{repos_id} = $node->{repos_id}; | ||
| 136 | print $FH "###### methodes\n"; | ||
| 137 | print $FH "\n"; | ||
| 138 | print $FH "# constructor\n"; | ||
| 139 | print $FH "sub new {\n"; | ||
| 140 | print $FH "\tmy \$proto = shift;\n"; | ||
| 141 | print $FH "\tmy \$class = ref(\$proto) || \$proto;\n"; | ||
| 142 | print $FH "\tmy \$self = {};\n"; | ||
| 143 | print $FH "\tbless \$self, \$class;\n"; | ||
| 144 | print $FH "\tmy(\$sock) = \@_;\n"; | ||
| 145 | print $FH "\tcroak \"undefined parameter 'sock' in '",$node->{idf},"'.\\n\"\n"; | ||
| 146 | print $FH "\t\t\tunless (defined \$sock);\n"; | ||
| 147 | print $FH "\tcroak \"invalid parameter 'sock' in '",$node->{idf},"'.\\n\"\n"; | ||
| 148 | print $FH "\t\t\tunless (ref \$sock eq 'IO::Socket::INET');\n"; | ||
| 149 | print $FH "\t\$self->{sock} = \$sock;\n"; | ||
| 150 | print $FH "\t\$self->{trace} = sub { print \@_ };\n"; | ||
| 151 | print $FH "\treturn \$self;\n"; | ||
| 152 | print $FH "}\n"; | ||
| 153 | print $FH "\n"; | ||
| 154 | print $FH "sub ",$node->{pl_name},"__id () {\n"; | ||
| 155 | print $FH "\t\treturn \"",$node->{repos_id},"\";\n"; | ||
| 156 | print $FH "}\n"; | ||
| 157 | print $FH "\n"; | ||
| 158 | print $FH "use Error qw(:try);\n"; | ||
| 159 | print $FH "\n"; | ||
| 160 | foreach (values %{$node->{hash_attribute_operation}}) { | ||
| 161 | $self->_get_defn($_)->visit($self); | ||
| 162 | } | ||
| 163 | print $FH "\n"; | ||
| 164 | } | ||
| 165 | print $FH "#\n"; | ||
| 166 | print $FH "# end of interface ",$node->{pl_package},"\n"; | ||
| 167 | print $FH "#\n"; | ||
| 168 | print $FH "\n"; | ||
| 169 | $self->{pkg_modif} = 1; | ||
| 170 | } | ||
| 171 | else { | ||
| 172 | $self->_insert_use($node->{filename}); | ||
| 173 | } | ||
| 174 | } | ||
| 175 | |||
| 176 | sub visitAbstractInterface { | ||
| 177 | my $self = shift; | ||
| 178 | my($node) = @_; | ||
| 179 | if ($self->{srcname} eq $node->{filename}) { | ||
| 180 | my $FH = $self->{out}; | ||
| 181 | $self->{pkg_modif} = 0; | ||
| 182 | print $FH "#\n"; | ||
| 183 | print $FH "# begin of abstract interface ",$node->{pl_package},"\n"; | ||
| 184 | print $FH "#\n"; | ||
| 185 | print $FH "\n"; | ||
| 186 | print $FH "package ",$node->{pl_package},";\n"; | ||
| 187 | print $FH "\n"; | ||
| 188 | print $FH "use CORBA::Perl::CORBA;\n"; | ||
| 189 | print $FH "use Carp;\n"; | ||
| 190 | print $FH "\n"; | ||
| 191 | foreach (@{$node->{list_decl}}) { | ||
| 192 | my $defn = $self->_get_defn($_); | ||
| 193 | if ( $defn->isa('Operation') | ||
| 194 | or $defn->isa('Attributes') ) { | ||
| 195 | next; | ||
| 196 | } | ||
| 197 | $defn->visit($self); | ||
| 198 | if ($self->{pkg_modif}) { | ||
| 199 | $self->{pkg_modif} = 0; | ||
| 200 | print $FH "package ",$node->{pl_package},";\n"; | ||
| 201 | print $FH "\n"; | ||
| 202 | } | ||
| 203 | } | ||
| 204 | print $FH "\n"; | ||
| 205 | print $FH "#\n"; | ||
| 206 | print $FH "# end of abstract interface ",$node->{pl_package},"\n"; | ||
| 207 | print $FH "#\n"; | ||
| 208 | print $FH "\n"; | ||
| 209 | $self->{pkg_modif} = 1; | ||
| 210 | } | ||
| 211 | else { | ||
| 212 | $self->_insert_use($node->{filename}); | ||
| 213 | } | ||
| 214 | } | ||
| 215 | |||
| 216 | # | ||
| 217 | # 3.9 Value Declaration (inherited) | ||
| 218 | # | ||
| 219 | |||
| 220 | # | ||
| 221 | # 3.10 Constant Declaration (inherited) | ||
| 222 | # | ||
| 223 | |||
| 224 | # | ||
| 225 | # 3.11 Type Declaration (inherited) | ||
| 226 | # | ||
| 227 | |||
| 228 | # | ||
| 229 | # 3.12 Exception Declaration (inherited) | ||
| 230 | # | ||
| 231 | |||
| 232 | # | ||
| 233 | # 3.13 Operation Declaration | ||
| 234 | # | ||
| 235 | |||
| 236 | sub visitOperation { | ||
| 237 | my $self = shift; | ||
| 238 | my($node) = @_; | ||
| 239 | my $type = $self->_get_defn($node->{type}); | ||
| 240 | my $FH = $self->{out}; | ||
| 241 | my $r_inout = q{}; | ||
| 242 | foreach (@{$node->{list_param}}) { # paramater | ||
| 243 | if ($_->{attr} eq 'inout') { | ||
| 244 | $r_inout .= ", \$r_" . $_->{pl_name}; | ||
| 245 | } | ||
| 246 | } | ||
| 247 | print $FH "# ",$self->{itf},"::",$node->{pl_name},"\n"; | ||
| 248 | print $FH "sub ",$node->{pl_name}," {\n"; | ||
| 249 | print $FH "\tmy \$self = shift;\n"; | ||
| 250 | print $FH "\n"; | ||
| 251 | print $FH "\tmy (\$_request_header, \$_buffer",$r_inout,") = \$self->",$node->{pl_name},"__marshal_request(\@_);\n"; | ||
| 252 | if (exists $node->{modifier}) { # oneway | ||
| 253 | print $FH "\tCORBA::Perl::GIOP::RequestOneWay(\$self->{sock},\$_request_header,\$_buffer);\t\t# oneway\n"; | ||
| 254 | } | ||
| 255 | else { | ||
| 256 | print $FH "\tmy(\$_status, \$_service_context, \$_reply, \$_endian) = CORBA::Perl::GIOP::RequestReply(\$self->{sock},\$_request_header,\$_buffer);\n"; | ||
| 257 | print $FH "\tmy \$_offset = 0;\n"; | ||
| 258 | print $FH "\treturn \$self->",$node->{pl_name},"__demarshal_reply(\$_status, \$_service_context, \\\$_reply, \\\$_offset, \$_endian",$r_inout,");\n"; | ||
| 259 | } | ||
| 260 | print $FH "}\n"; | ||
| 261 | print $FH "\n"; | ||
| 262 | if (exists $self->{miop} and exists $node->{modifier}) { | ||
| 263 | print $FH "sub ",$node->{pl_name},"__marshal {\n"; | ||
| 264 | foreach (@{$node->{list_param}}) { # paramater | ||
| 265 | print $FH "\tmy \$",$_->{pl_name}," = shift;\n"; | ||
| 266 | print $FH "\tcroak \"undefined parameter '",$_->{pl_name},"' in '",$node->{pl_name},"'.\\n\"\n"; | ||
| 267 | print $FH "\t\t\tunless (defined \$",$_->{pl_name},");\n"; | ||
| 268 | } | ||
| 269 | print $FH "\n"; | ||
| 270 | print $FH "\tmy \$_request = q{};\n"; | ||
| 271 | print $FH "\tmy \$_request_header = {\n"; | ||
| 272 | print $FH "\t\t\trequest_id => CORBA::Perl::GIOP::GetRequestId(),\n"; | ||
| 273 | print $FH "\t\t\tresponse_flags => 0, # NONE\n"; | ||
| 274 | print $FH "\t\t\treserved => [0, 0, 0],\n"; | ||
| 275 | print $FH "\t\t\ttarget => [CORBA::Perl::GIOP::KeyAddr(), \"",$self->{repos_id},"\"],\n"; | ||
| 276 | print $FH "\t\t\toperation => \"",$node->{idf},"\",\n"; | ||
| 277 | print $FH "\t\t\tservice_context => [] # empty sequence\n"; | ||
| 278 | print $FH "\t};\n"; | ||
| 279 | print $FH "\tCORBA::Perl::GIOP::RequestHeader_1_2__marshal(\\\$_request, \$_request_header);\n"; | ||
| 280 | print $FH "\t# body\n"; | ||
| 281 | foreach (@{$node->{list_param}}) { # paramater | ||
| 282 | my $type = $self->_get_defn($_->{type}); | ||
| 283 | print $FH "\t",$type->{pl_package},"::",$type->{pl_name},"__marshal"; | ||
| 284 | print $FH "(\\\$_request,\$",$_->{pl_name},");\n"; | ||
| 285 | } | ||
| 286 | print $FH "\n"; | ||
| 287 | print $FH "\tmy \$_message = q{};\n"; | ||
| 288 | print $FH "\tmy \$_message_header = {\n"; | ||
| 289 | print $FH "\t\t\tmagic => [ 'G', 'I', 'O', 'P' ],\n"; | ||
| 290 | print $FH "\t\t\tGIOP_version => {\n"; | ||
| 291 | print $FH "\t\t\t\t\tmajor => 1,\n"; | ||
| 292 | print $FH "\t\t\t\t\tminor => 2,\n"; | ||
| 293 | print $FH "\t\t\t},\n"; | ||
| 294 | print $FH "\t\t\tflags => 0x01, # flags : little endian\n"; | ||
| 295 | print $FH "\t\t\tmessage_type => 0, # Request\n"; | ||
| 296 | print $FH "\t\t\tmessage_size => length(\$_request)\n"; | ||
| 297 | print $FH "\t};\n"; | ||
| 298 | print $FH "\tCORBA::Perl::GIOP::MessageHeader_1_2__marshal(\\\$_message, \$_message_header);\n"; | ||
| 299 | print $FH "\t\$_message .= \$_request;\n"; | ||
| 300 | print $FH "\n"; | ||
| 301 | print $FH "\treturn \$_message;\n"; | ||
| 302 | print $FH "}\n"; | ||
| 303 | print $FH "\n"; | ||
| 304 | print $FH "sub ",$node->{pl_name},"__demarshal_body {\n"; | ||
| 305 | print $FH "\tmy \$self = shift;\n"; | ||
| 306 | print $FH "\tmy (\$r_buffer,\$r_offset,\$endian) = \@_;\n"; | ||
| 307 | print $FH "\tmy \@_parameters = ();\n"; | ||
| 308 | print $FH "\n"; | ||
| 309 | foreach (@{$node->{list_param}}) { # paramater | ||
| 310 | my $type = $self->_get_defn($_->{type}); | ||
| 311 | print $FH "\tpush \@_parameters, ",$type->{pl_package},"::",$type->{pl_name},"__demarshal(\$r_buffer,\$r_offset,\$endian);\n"; | ||
| 312 | } | ||
| 313 | print $FH "\n"; | ||
| 314 | print $FH "\treturn \@_parameters;\n"; | ||
| 315 | print $FH "}\n"; | ||
| 316 | print $FH "\n"; | ||
| 317 | } | ||
| 318 | print $FH "sub ",$node->{pl_name},"__marshal_request {\n"; | ||
| 319 | print $FH "\tmy \$self = shift;\n"; | ||
| 320 | print $FH "\n"; | ||
| 321 | foreach (@{$node->{list_param}}) { # paramater | ||
| 322 | if ($_->{attr} eq 'in') { | ||
| 323 | print $FH "\tmy \$",$_->{pl_name}," = shift;\n"; | ||
| 324 | print $FH "\tcroak \"undefined parameter '",$_->{pl_name},"' in '",$node->{pl_name},"'.\\n\"\n"; | ||
| 325 | print $FH "\t\t\tunless (defined \$",$_->{pl_name},");\n"; | ||
| 326 | } | ||
| 327 | if ($_->{attr} eq 'inout') { | ||
| 328 | print $FH "\tmy \$r_",$_->{pl_name}," = shift;\n"; | ||
| 329 | print $FH "\tcroak \"undefined parameter '",$_->{pl_name},"' in '",$node->{pl_name},"'.\\n\"\n"; | ||
| 330 | print $FH "\t\t\tunless (defined \$r_",$_->{pl_name},");\n"; | ||
| 331 | } | ||
| 332 | } | ||
| 333 | print $FH "\n"; | ||
| 334 | print $FH "\tmy \$_request_header = {\n"; | ||
| 335 | print $FH "\t\t\trequest_id => 0, # overloaded by CORBA::Perl::GIOP::Request* \n"; | ||
| 336 | if (exists $node->{modifier}) { # oneway | ||
| 337 | print $FH "\t\t\tresponse_flags => 0, # NONE\n"; | ||
| 338 | } | ||
| 339 | else { | ||
| 340 | print $FH "\t\t\tresponse_flags => 3, # WITH_TARGET\n"; | ||
| 341 | } | ||
| 342 | print $FH "\t\t\treserved => [0, 0, 0],\n"; | ||
| 343 | print $FH "\t\t\ttarget => [CORBA::Perl::GIOP::KeyAddr(), \"",$self->{repos_id},"\"],\n"; | ||
| 344 | print $FH "\t\t\toperation => \"",$node->{idf},"\",\n"; | ||
| 345 | print $FH "\t\t\tservice_context => [] # empty sequence\n"; | ||
| 346 | print $FH "\t};\n"; | ||
| 347 | print $FH "\tmy \$_request_body = q{};\n"; | ||
| 348 | foreach (@{$node->{list_param}}) { # paramater | ||
| 349 | my $type = $self->_get_defn($_->{type}); | ||
| 350 | if ($_->{attr} eq 'in') { | ||
| 351 | print $FH "\t",$type->{pl_package},"::",$type->{pl_name},"__marshal"; | ||
| 352 | print $FH "(\\\$_request_body,\$",$_->{pl_name},");\n"; | ||
| 353 | } | ||
| 354 | elsif ($_->{attr} eq 'inout') { | ||
| 355 | print $FH "\t",$type->{pl_package},"::",$type->{pl_name},"__marshal"; | ||
| 356 | print $FH "(\\\$_request_body,\${\$r_",$_->{pl_name},"});\n"; | ||
| 357 | } | ||
| 358 | } | ||
| 359 | print $FH "\treturn (\$_request_header,\$_request_body",$r_inout,");\n"; | ||
| 360 | print $FH "};\n"; | ||
| 361 | print $FH "\n"; | ||
| 362 | unless (exists $node->{modifier}) { # !oneway | ||
| 363 | print $FH "sub ",$node->{pl_name},"__demarshal_reply {\n"; | ||
| 364 | print $FH "\tmy \$self = shift;\n"; | ||
| 365 | print $FH "\n"; | ||
| 366 | print $FH "\tmy(\$_status, \$_service_context, \$_reply, \$_offset, \$_endian",$r_inout,") = \@_;\n"; | ||
| 367 | print $FH "\tif (\$_status eq CORBA::Perl::CORBA::NO_EXCEPTION) {\n"; | ||
| 368 | my $nb = 0; | ||
| 369 | my $type = $self->_get_defn($node->{type}); | ||
| 370 | unless ($type->isa('VoidType')) { | ||
| 371 | print $FH "\t\tmy \$_return = "; | ||
| 372 | print $FH $type->{pl_package},"::",$type->{pl_name}; | ||
| 373 | print $FH "__demarshal(\$_reply,\$_offset,\$_endian);\n"; | ||
| 374 | $nb ++; | ||
| 375 | } | ||
| 376 | foreach (@{$node->{list_param}}) { # paramater | ||
| 377 | $type = $self->_get_defn($_->{type}); | ||
| 378 | if ( $_->{attr} eq 'inout' | ||
| 379 | or $_->{attr} eq 'out' ) { | ||
| 380 | print $FH "\t\tmy \$",$_->{pl_name}," = "; | ||
| 381 | print $FH $type->{pl_package},"::",$type->{pl_name}; | ||
| 382 | print $FH "__demarshal(\$_reply,\$_offset,\$_endian);\n"; | ||
| 383 | $nb ++ if ($_->{attr} eq 'out'); | ||
| 384 | } | ||
| 385 | } | ||
| 386 | foreach (@{$node->{list_param}}) { # paramater | ||
| 387 | if ($_->{attr} eq 'inout') { | ||
| 388 | print $FH "\t\t\${\$r_",$_->{pl_name},"} = \$",$_->{pl_name},";\n"; | ||
| 389 | } | ||
| 390 | } | ||
| 391 | print $FH "\t\treturn"; | ||
| 392 | print $FH " " if ($nb > 0); | ||
| 393 | print $FH "(" if ($nb > 1); | ||
| 394 | my $first = 1; | ||
| 395 | $type = $self->_get_defn($node->{type}); | ||
| 396 | unless ($type->isa('VoidType')) { | ||
| 397 | print $FH "\$_return"; | ||
| 398 | $first = 0; | ||
| 399 | } | ||
| 400 | foreach (@{$node->{list_param}}) { # paramater | ||
| 401 | if ($_->{attr} eq 'out') { | ||
| 402 | print $FH ", " unless ($first); | ||
| 403 | print $FH "\$",$_->{pl_name}; | ||
| 404 | $first = 0; | ||
| 405 | } | ||
| 406 | } | ||
| 407 | print $FH ")" if ($nb > 1); | ||
| 408 | print $FH ";\n"; | ||
| 409 | print $FH "\t}\n"; | ||
| 410 | print $FH "\telsif (\$_status eq CORBA::Perl::CORBA::USER_EXCEPTION) {\n"; | ||
| 411 | print $FH "\t\tmy \$_exception_id = CORBA::Perl::CORBA::string__demarshal(\$_reply,\$_offset,\$_endian);\n"; | ||
| 412 | print $FH "\t\tif (0) {\n"; | ||
| 413 | foreach (@{$node->{list_raise}}) { | ||
| 414 | my $defn = $self->_get_defn($_); | ||
| 415 | print $FH "\t\t}\n"; | ||
| 416 | print $FH "\t\telsif (\$_exception_id eq \"",$defn->{repos_id},"\") {\n"; | ||
| 417 | print $FH "\t\t\tmy \$_value = "; | ||
| 418 | print $FH $defn->{pl_package},"::",$defn->{pl_name}; | ||
| 419 | print $FH "__demarshal(\$_reply,\$_offset,\$_endian);\n"; | ||
| 420 | print $FH "\t\t\t\$self->{trace}(CORBA::Perl::CORBA::USER_EXCEPTION,\" \$_exception_id.\\n\");\n"; | ||
| 421 | print $FH "\t\t\tthrow ",$defn->{pl_package},"::",$defn->{pl_name},"(\n"; | ||
| 422 | print $FH "\t\t\t\t\t_repos_id => \$_exception_id,\n"; | ||
| 423 | print $FH "\t\t\t\t\t\%{\$_value}\n"; | ||
| 424 | print $FH "\t\t\t);\n"; | ||
| 425 | } | ||
| 426 | print $FH "\t\t}\n"; | ||
| 427 | print $FH "\t\telse {\n"; | ||
| 428 | print $FH "\t\t\twarn \"unknown user exception \$_exception_id.\\n\";\n"; | ||
| 429 | print $FH "\t\t}\n"; | ||
| 430 | print $FH "\t}\n"; | ||
| 431 | print $FH "\telsif (\$_status eq CORBA::Perl::CORBA::SYSTEM_EXCEPTION) {\n"; | ||
| 432 | print $FH "\t\tmy \$_exception_id = CORBA::Perl::CORBA::string__demarshal(\$_reply,\$_offset,\$_endian);\n"; | ||
| 433 | print $FH "\t\tmy \$_minor_code_value = CORBA::Perl::CORBA::unsigned_long__demarshal(\$_reply,\$_offset,\$_endian);\n"; | ||
| 434 | print $FH "\t\tmy \$_completion_status = CORBA::Perl::CORBA::completion_status__demarshal(\$_reply,\$_offset,\$_endian);\n"; | ||
| 435 | print $FH "\t\t\$self->{trace}(CORBA::Perl::CORBA::SYSTEM_EXCEPTION,\" \$_exception_id.\\n\");\n"; | ||
| 436 | print $FH "\t\tthrow CORBA::Perl::CORBA::SystemException(\n"; | ||
| 437 | print $FH "\t\t\t\t_repos_id => \$_exception_id,\n"; | ||
| 438 | print $FH "\t\t\t\tminor => \$_minor_code_value,\n"; | ||
| 439 | print $FH "\t\t\t\tcompleted => \$_completion_status\n"; | ||
| 440 | print $FH "\t\t);\n"; | ||
| 441 | print $FH "\t}\n"; | ||
| 442 | print $FH "\telse {\n"; | ||
| 443 | print $FH "\t\twarn \"reply status \$_status.\\n\";\n"; | ||
| 444 | print $FH "\t}\n"; | ||
| 445 | print $FH "}\n"; | ||
| 446 | print $FH "\n"; | ||
| 447 | } | ||
| 448 | |||
| 449 | print $FH "sub srv_",$node->{pl_name}," {\n"; | ||
| 450 | print $FH "\tmy \$self = shift;\n"; | ||
| 451 | print $FH "\tmy (\$r_buffer,\$r_offset,\$endian) = \@_;\n"; | ||
| 452 | print $FH "\tmy \@_parameters = ();\n"; | ||
| 453 | print $FH "\n"; | ||
| 454 | foreach (@{$node->{list_param}}) { # paramater | ||
| 455 | my $type = $self->_get_defn($_->{type}); | ||
| 456 | if ($_->{attr} eq 'in') { | ||
| 457 | print $FH "\tpush \@_parameters, ",$type->{pl_package},"::",$type->{pl_name},"__demarshal(\$r_buffer,\$r_offset,\$endian);\n"; | ||
| 458 | } | ||
| 459 | elsif ($_->{attr} eq 'inout') { | ||
| 460 | print $FH "\tpush \@_parameters, ",$type->{pl_package},"::",$type->{pl_name},"__demarshal(\$r_buffer,\$r_offset,\$endian);\n"; | ||
| 461 | } | ||
| 462 | } | ||
| 463 | print $FH "\n"; | ||
| 464 | if (exists $node->{modifier}) { # oneway | ||
| 465 | print $FH "\t\$self->",$node->{pl_name},"(\@_parameters);\n"; | ||
| 466 | print $FH "\treturn undef;\n"; | ||
| 467 | } | ||
| 468 | else { | ||
| 469 | print $FH "\tmy \$reply_body = q{};\n"; | ||
| 470 | print $FH "\ttry {\n"; | ||
| 471 | print $FH "\t\tmy \@result = (\$self->",$node->{pl_name},"(\@_parameters));\n"; | ||
| 472 | unless ($type->isa('VoidType')) { | ||
| 473 | print $FH "\t\t",$type->{pl_package},"::",$type->{pl_name},"__marshal(\\\$reply_body, shift \@result);\n"; | ||
| 474 | } | ||
| 475 | foreach (@{$node->{list_param}}) { # parameter | ||
| 476 | if ( $_->{attr} eq 'inout' | ||
| 477 | or $_->{attr} eq 'out' ) { | ||
| 478 | $type = $self->_get_defn($_->{type}); | ||
| 479 | print $FH "\t\t",$type->{pl_package},"::",$type->{pl_name},"__marshal(\\\$reply_body, shift \@result);\n"; | ||
| 480 | } | ||
| 481 | } | ||
| 482 | print $FH "\t\treturn (CORBA::Perl::CORBA::NO_EXCEPTION, \$reply_body);\n"; | ||
| 483 | print $FH "\t}\n"; | ||
| 484 | foreach (@{$node->{list_raise}}) { | ||
| 485 | my $defn = $self->_get_defn($_); | ||
| 486 | print $FH "\tcatch ",$defn->{pl_package},"::",$defn->{pl_name}," with {\n"; | ||
| 487 | print $FH "\t\tCORBA::Perl::CORBA::string__marshal(\\\$reply_body,",$defn->{pl_package},"::",$defn->{pl_name},"__id());\n"; | ||
| 488 | if (exists $defn->{list_expr}) { | ||
| 489 | print $FH "\t\tmy \$E = shift;\n"; | ||
| 490 | } | ||
| 491 | print $FH "\t\treturn (CORBA::Perl::CORBA::USER_EXCEPTION, \$reply_body);\n"; | ||
| 492 | print $FH "\t}\n"; | ||
| 493 | } | ||
| 494 | print $FH "\tcatch CORBA::Perl::CORBA::Exception with {\n"; | ||
| 495 | print $FH "\t\tmy \$E = shift;\n"; | ||
| 496 | print $FH "\t\tCORBA::Perl::CORBA::string__marshal(\\\$reply_body,\$E->{exception_id});\n"; | ||
| 497 | print $FH "\t\tCORBA::Perl::CORBA::unsigned_long__marshal(\\\$reply_body,\$E->{minor_code_value});\n"; | ||
| 498 | print $FH "\t\tCORBA::Perl::CORBA::completion_status__marshal(\\\$reply_body,\$E->{completion_status});\n"; | ||
| 499 | print $FH "\t\treturn (CORBA::Perl::CORBA::SYSTEM_EXCEPTION, \$reply_body);\n"; | ||
| 500 | print $FH "\t};\n"; | ||
| 501 | } | ||
| 502 | print $FH "}\n"; | ||
| 503 | print $FH "\n"; | ||
| 504 | } | ||
| 505 | |||
| 506 | # | ||
| 507 | # 3.14 Attribute Declaration (inherited) | ||
| 508 | # | ||
| 509 | |||
| 510 | 1; | ||
| 511 |