CORBA/Request.pm untested

filter: Statementstmt 0.0% 0 / 90 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 151 CC 10 SCAR 36.9
CC
10
Cov
0%
invoke
90.0
get_connection
6.0
add_arg
2.0
CRAP 40.1
1 # $Id: Request.pm,v 1.4 1997/07/31 11:03:53 schuller Exp $
2 # Copyright (c) 1997 Lunatech Research / Bart Schuller <schuller@lunatech.com>
3 # See the file "Artistic" in the distribution for licensing and
4 # (lack of) warranties.
5  
6 # interface Request
7 package CORBA::Request;
8 use COPE::GIOP;
9 use IO::Socket;
10 use Data::Dumper;
11 use COPE::CORBA::TCKind;
12 use COPE::CORBA::Exception;
13  
14 $CORBA::Request::request_id = 0;
15 %CORBA::Request::connections = ();
16  
17 sub add_arg ($$$$$$) {
18 my($self,$name,$arg_type,$value,$len,$arg_flags) = @_;
19 }
20  
21 sub invoke ($$) {
22 my($self,$invoke_flags) = @_;
23 my $request_header = GIOP::RequestHeader->new(
24 service_context => [],
25 request_id => $CORBA::Request::request_id++,
26 response_expected => 1, # FIXME
27 object_key => $self->{object_key},
28 operation => $self->{operation},
29 requesting_principal => '', # FIXME
30 );
31 my $request = '';
32 my $index = 0;
33 my $byte_order = $self->{orb}{byte_order};
34 GIOP::RequestHeader::_marshal(\$request, \$index, $byte_order, $request_header);
35 foreach my $arg (@{$self->{arg_list}}) {
36 if (($arg->{arg_modes}==0)||($arg->{arg_modes}==2)) {
37 CORBA::ORB::_marshal_using_tc(\$request, \$index, $byte_order, $arg->{argument}{_type}->_needs_ref($arg->{arg_modes}) ? ${$arg->{argument}{_value}} : $arg->{argument}{_value}, $arg->{argument}{_type});
38 }
39 }
40 my $message_header = GIOP::MessageHeader->new(
41 magic => 'GIOP',
42 GIOP_version => new GIOP::Version(major => chr(1), minor => chr(0)),
43 byte_order => $byte_order,
44 message_type => GIOP::Request,
45 message_size => $index,
46 );
47 my $msg = '';
48 $index = 0;
49 GIOP::MessageHeader::_marshal(\$msg,\$index,$byte_order,$message_header);
50 $msg .= $request;
51 my $length = length($msg);
52 $index = 0;
53 my $connection = $self->get_connection();
54 while ($index < $length) {
55 $index += syswrite($connection, $msg, $length-$index, $index);
56 }
57  
58 my $reply;
59 sysread($connection, $reply, 12); # FIXME
60 $index = 0;
61 my $reply_mh = GIOP::MessageHeader::_unmarshal(\$reply, \$index, \$byte_order);
62 $byte_order = $reply_mh->{byte_order};
63 $index = 0;
64 while ($index < $reply_mh->{message_size}) {
65 $index += sysread($connection, $reply, $reply_mh->{message_size}-$index, $index);
66 }
67 $index = 0;
68 my $reply_header = GIOP::ReplyHeader::_unmarshal(\$reply, \$index, $byte_order);
69 if ($reply_header->{reply_status} == GIOP::NO_EXCEPTION) {
70 $self->{result}{_value} = CORBA::ORB::_unmarshal_using_tc(\$reply, \$index, $byte_order, $self->{result}{_type});
71 foreach my $arg (@{$self->{arg_list}}) {
72 if (($arg->{arg_modes}==1)||($arg->{arg_modes}==2)) {
73 if ((($arg->{argument}{_type}->kind() == tk_sequence) || ($arg->{argument}{_type}->kind() == tk_array)) && ($arg->{argument}{_type}->content_type()->kind() != tk_octet)) {
74 @{$arg->{argument}{_value}} = @{CORBA::ORB::_unmarshal_using_tc(\$reply, \$index, $byte_order, $arg->{argument}{_type})};
75 } elsif ($arg->{argument}{_type}->kind() == tk_struct) {
76 my $struct = CORBA::ORB::_unmarshal_using_tc(\$reply, \$index, $byte_order, $arg->{argument}{_type});
77 %{$arg->{argument}{_value}} = %$struct;
78 } else {
79 ${$arg->{argument}{_value}} = CORBA::ORB::_unmarshal_using_tc(\$reply, \$index, $byte_order, $arg->{argument}{_type});
80 }
81 }
82 }
83 } elsif ($reply_header->{reply_status} == GIOP::USER_EXCEPTION) {
84 my $tc = CORBA::ORB::_id2package(CORBA::ORB::_unmarshal_string(\$reply, \$index, $byte_order));
85 no strict 'refs';
86 $tc = ${"${tc}::_tc"};
87 my $exception = CORBA::ORB::_unmarshal_using_tc(\$reply, \$index, $byte_order, $tc);
88 throw $exception;
89
90 } elsif ($reply_header->{reply_status} == GIOP::SYSTEM_EXCEPTION) {
91 die "System exception: " . CORBA::ORB::_unmarshal_string(\$reply, \$index, $byte_order);
92 } else {
93 die "Location forward";
94 }
95 }
96  
97 sub delete ($) {
98 my($self) = @_;
99 }
100  
101 sub send ($$) {
102 my($self,$invoke_flags) = @_;
103 }
104  
105 sub get_response ($$) {
106 my($self,$response_flags) = @_;
107 }
108  
109 # private methods
110  
111 sub get_connection {
112 my($self) = @_;
113 my $peer = "$self->{host}:$self->{port}";
114 my $connection = $CORBA::Request::connections{$peer};
115 return $connection if $connection;
116 my $error;
117 # IO::Socket has a noisy way of reporting errors
118 local $SIG{__WARN__} = sub { $error = 1 };
119 $connection = IO::Socket::INET->new(
120 PeerAddr => $peer,
121 Proto => 'tcp');
122 $error && throw(
123 CORBA::COMM_FAILURE->new(minor => 0, completion_status => CORBA::CompletionStatus::COMPLETED_NO));
124 return $CORBA::Request::connections{$peer} = $connection;
125 }
126  
127 # private functions
128 1;