1 #include "ace/Get_Opt.h"
2 #include "ace/OS_NS_stdio.h"
3 #include "ace/OS_NS_string.h"
4 #include "ace/OS_NS_unistd.h"
5 #include "tao/RTCORBA/RTCORBA.h"
6 #include "tao/ORB_Constants.h"
7 #include "tao/Policy_CurrentC.h"
11 static const ACE_TCHAR
*ior_file
= ACE_TEXT ("distributor.ior");
12 static const ACE_TCHAR
*ior
= ACE_TEXT ("file://receiver.ior");
13 static int number_of_connection_attempts
= 20;
16 parse_args (int argc
, ACE_TCHAR
**argv
)
18 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("f:k:"));
21 while ((c
= get_opts ()) != -1)
25 ior
= get_opts
.opt_arg ();
29 ior_file
= get_opts
.opt_arg ();
33 ACE_ERROR_RETURN ((LM_ERROR
,
35 "\t-f <ior_file> (defaults to %s)\n"
36 "\t-k <ior> (defaults to %s)\n"
51 test_i (CORBA::ORB_ptr orb
,
52 PortableServer::POA_ptr poa
,
53 RTCORBA::RTORB_ptr rtorb
,
54 CORBA::PolicyManager_ptr policy_manager
,
59 void start_test (CORBA::Long session_id
,
61 CORBA::ULong invocation_rate
,
62 CORBA::ULong message_size
,
63 CORBA::ULong iterations
);
71 void oneway_method (CORBA::Long session_id
,
72 CORBA::ULong iteration
,
73 const ::test::octets
&payload
);
75 void twoway_method (CORBA::Long
&session_id
,
76 CORBA::ULong
&iteration
,
77 ::test::octets
&payload
);
79 //FUZZ: disable check_for_lack_ACE_OS
81 //FUZZ: enable check_for_lack_ACE_OS
83 PortableServer::POA_ptr
_default_POA ();
87 PortableServer::POA_var poa_
;
88 RTCORBA::RTORB_var rtorb_
;
89 CORBA::PolicyManager_var policy_manager_
;
92 CORBA::PolicyList base_protocol_policy_
;
93 CORBA::PolicyList test_protocol_policy_
;
96 test_i::test_i (CORBA::ORB_ptr orb
,
97 PortableServer::POA_ptr poa
,
98 RTCORBA::RTORB_ptr rtorb
,
99 CORBA::PolicyManager_ptr policy_manager
,
101 : orb_ (CORBA::ORB::_duplicate (orb
)),
102 poa_ (PortableServer::POA::_duplicate (poa
)),
103 rtorb_ (RTCORBA::RTORB::_duplicate (rtorb
)),
104 policy_manager_ (CORBA::PolicyManager::_duplicate (policy_manager
)),
105 receiver_ (test::_duplicate (receiver
))
107 // Base protocol is used for setting up and tearing down the test.
108 this->base_protocol_policy_
.length (1);
110 // Test protocol is the one being tested.
111 this->test_protocol_policy_
.length (1);
113 RTCORBA::ProtocolList protocols
;
114 protocols
.length (1);
115 protocols
[0].transport_protocol_properties
=
116 RTCORBA::ProtocolProperties::_nil ();
117 protocols
[0].orb_protocol_properties
=
118 RTCORBA::ProtocolProperties::_nil ();
120 // IIOP is always used for the base protocol.
121 protocols
[0].protocol_type
= 0;
123 // User decides the test protocol.
124 this->base_protocol_policy_
[0] =
125 this->rtorb_
->create_client_protocol_policy (protocols
);
133 test_i::start_test (CORBA::Long session_id
,
134 const char *protocol
,
135 CORBA::ULong invocation_rate
,
136 CORBA::ULong message_size
,
137 CORBA::ULong iterations
)
139 RTCORBA::ProtocolList protocols
;
140 protocols
.length (1);
141 protocols
[0].transport_protocol_properties
=
142 RTCORBA::ProtocolProperties::_nil ();
143 protocols
[0].orb_protocol_properties
=
144 RTCORBA::ProtocolProperties::_nil ();
146 if (ACE_OS::strcmp (protocol
, "DIOP") == 0)
148 if (TAO_debug_level
) ACE_DEBUG ((LM_DEBUG
, "test protocol is DIOP\n"));
149 protocols
[0].protocol_type
= TAO_TAG_DIOP_PROFILE
;
151 else if (ACE_OS::strcmp (protocol
, "SCIOP") == 0)
153 if (TAO_debug_level
) ACE_DEBUG ((LM_DEBUG
, "test protocol is SCIOP\n"));
154 protocols
[0].protocol_type
= TAO_TAG_SCIOP_PROFILE
;
158 if (TAO_debug_level
) ACE_DEBUG ((LM_DEBUG
, "test protocol is IIOP\n"));
159 protocols
[0].protocol_type
= 0;
162 this->test_protocol_policy_
[0] =
163 this->rtorb_
->create_client_protocol_policy (protocols
);
165 // Make sure we have a connection to the server using the test
167 this->policy_manager_
->set_policy_overrides (this->test_protocol_policy_
,
168 CORBA::SET_OVERRIDE
);
170 // Since the network maybe unavailable temporarily, make sure to try
171 // for a few times before giving up.
178 // Send a message to ensure that the connection is setup.
179 this->receiver_
->oneway_sync ();
181 goto test_protocol_success
;
183 catch (const CORBA::TRANSIENT
&)
187 if (j
< number_of_connection_attempts
)
190 goto test_protocol_setup
;
194 ACE_ERROR ((LM_ERROR
,
195 "Cannot setup test protocol\n"));
197 throw CORBA::TRANSIENT (CORBA::OMGVMCID
| 2, CORBA::COMPLETED_NO
);
200 test_protocol_success
:
202 // Use IIOP for setting up the test since the test protocol maybe
204 this->policy_manager_
->set_policy_overrides (this->base_protocol_policy_
,
205 CORBA::SET_OVERRIDE
);
207 // Since the network maybe unavailable temporarily, make sure to try
208 // for a few times before giving up.
215 // Let the server know what to expect..
216 this->receiver_
->start_test (session_id
,
222 goto base_protocol_success
;
224 catch (const CORBA::TRANSIENT
&)
228 if (k
< number_of_connection_attempts
)
231 goto base_protocol_setup
;
235 ACE_ERROR ((LM_ERROR
,
236 "Cannot setup base protocol\n"));
238 throw CORBA::TRANSIENT (CORBA::OMGVMCID
| 2, CORBA::COMPLETED_NO
);
241 base_protocol_success
:
243 // Select the test protocol for these invocation.
244 this->policy_manager_
->set_policy_overrides (this->test_protocol_policy_
,
245 CORBA::SET_OVERRIDE
);
251 // Use IIOP to indicate end of test to server.
252 this->policy_manager_
->set_policy_overrides (this->base_protocol_policy_
,
253 CORBA::SET_OVERRIDE
);
255 this->receiver_
->end_test ();
259 test_i::oneway_sync ()
261 this->receiver_
->oneway_sync ();
265 test_i::twoway_sync ()
267 this->receiver_
->twoway_sync ();
271 test_i::oneway_method (CORBA::Long session_id
,
272 CORBA::ULong iteration
,
273 const ::test::octets
&payload
)
275 this->receiver_
->oneway_method (session_id
,
281 test_i::twoway_method (CORBA::Long
&session_id
,
282 CORBA::ULong
&iteration
,
283 ::test::octets
&payload
)
285 this->receiver_
->twoway_method (session_id
,
290 PortableServer::POA_ptr
291 test_i::_default_POA ()
293 return PortableServer::POA::_duplicate (this->poa_
.in ());
299 this->receiver_
->shutdown ();
301 this->orb_
->shutdown (false);
305 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
310 CORBA::ORB_init (argc
, argv
);
312 CORBA::Object_var object
=
313 orb
->resolve_initial_references ("RTORB");
315 RTCORBA::RTORB_var rtorb
=
316 RTCORBA::RTORB::_narrow (object
.in ());
319 orb
->resolve_initial_references ("ORBPolicyManager");
321 CORBA::PolicyManager_var policy_manager
=
322 CORBA::PolicyManager::_narrow (object
.in ());
324 int parse_args_result
=
325 parse_args (argc
, argv
);
326 if (parse_args_result
!= 0)
327 return parse_args_result
;
330 orb
->resolve_initial_references ("RootPOA");
332 PortableServer::POA_var root_poa
=
333 PortableServer::POA::_narrow (object
.in ());
335 PortableServer::POAManager_var poa_manager
=
336 root_poa
->the_POAManager ();
339 orb
->string_to_object (ior
);
342 test::_narrow (object
.in ());
345 new test_i (orb
.in (),
348 policy_manager
.in (),
350 PortableServer::ServantBase_var
safe_servant (servant
);
351 ACE_UNUSED_ARG (safe_servant
);
356 CORBA::String_var ior
=
357 orb
->object_to_string (test
.in ());
360 ACE_OS::fopen (ior_file
, "w");
361 ACE_ASSERT (output_file
!= 0);
364 ACE_OS::fprintf (output_file
,
367 ACE_ASSERT (result
== ACE_OS::strlen (ior
.in ()));
368 ACE_UNUSED_ARG (result
);
370 ACE_OS::fclose (output_file
);
372 poa_manager
->activate ();
377 catch (const CORBA::Exception
& ex
)
379 ex
._tao_print_exception ("Exception caught");