4 #include "ace/Get_Opt.h"
5 #include "ace/Read_Buffer.h"
6 #include "ace/OS_NS_fcntl.h"
7 #include "ace/OS_NS_unistd.h"
8 #include "tao/IORManipulation/IORManip_Loader.h"
9 #include "tao/PortableServer/PortableServer.h"
10 // Ensure that the PI library is linked in when building statically
11 #include "tao/PI/PI.h"
12 #include "orbsvcs/FaultTolerance/FT_Service_Activate.h"
13 #include "orbsvcs/FaultTolerance/FT_IOGR_Property.h"
14 #include "ace/OS_NS_stdio.h"
16 // Files which have the IOR
17 const ACE_TCHAR
*first_ior
= 0;
18 const ACE_TCHAR
*first_key
= 0;
19 const ACE_TCHAR
*second_ior
= 0;
20 const ACE_TCHAR
*second_key
= 0;
21 const ACE_TCHAR
*ior_output_file
= 0;
22 int shutdown_test
= 0;
26 CORBA::Object_var object_primary
= 0;
27 CORBA::Object_var object_secondary
= 0;
29 // Reference to the IOR manipulator
30 TAO_IOP::TAO_IOR_Manipulation_var iorm
= 0;
33 parse_args (int argc
, ACE_TCHAR
*argv
[])
35 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("a:k:b:l:c:sm"));
38 while ((c
= get_opts ()) != -1)
42 first_ior
= get_opts
.opt_arg ();
45 first_key
= get_opts
.opt_arg ();
48 second_ior
= get_opts
.opt_arg ();
51 second_key
= get_opts
.opt_arg ();
54 ior_output_file
= get_opts
.opt_arg ();
64 ACE_ERROR_RETURN ((LM_ERROR
,
66 "-a <iorfile1> -k <key1> "
67 "-b <iorfile2> -l <key2> "
68 "-c <output ior file>"
73 // Indicates successful parsing of the command line
86 // Initilaize the ORB, POA etc.
87 manager
.init (argc
, argv
);
89 // the command line arguments
90 if (parse_args (argc
, argv
) == -1)
93 // Merge the different IORS
94 manager
.make_merged_iors ();
98 // Set properties. This is the most important portion of the
100 manager
.set_properties ();
104 manager
.write_to_file ();
106 // Client, who is going to use the merged IOR
107 // Construct that with the managers ORB
108 Client_i
client_imp (manager
.orb ());
109 return client_imp
.init ();
111 catch (const CORBA::Exception
& ex
)
113 ex
._tao_print_exception ("Caught");
128 Manager::init (int argc
,
131 this->orb_
= CORBA::ORB_init (argc
, argv
);
133 // Obtain the RootPOA.
134 CORBA::Object_var obj_var
=
135 this->orb_
->resolve_initial_references ("RootPOA");
137 // Get the POA_var object from Object_var.
138 PortableServer::POA_var root_poa_var
=
139 PortableServer::POA::_narrow (obj_var
.in ());
141 // Get the POAManager of the RootPOA.
142 PortableServer::POAManager_var poa_manager_var
=
143 root_poa_var
->the_POAManager ();
145 poa_manager_var
->activate ();
149 Manager::make_merged_iors ()
153 this->orb_
->string_to_object (first_ior
);
159 this->orb_
->string_to_object (second_ior
);
161 // Get an object reference for the ORBs IORManipultion object!
162 CORBA::Object_var IORM
=
163 this->orb_
->resolve_initial_references (TAO_OBJID_IORMANIPULATION
,
167 TAO_IOP::TAO_IOR_Manipulation::_narrow (IORM
.in());
171 TAO_IOP::TAO_IOR_Manipulation::IORList
iors (2);
173 iors
[0] = CORBA::Object::_duplicate (object_primary
.in ());
174 iors
[1] = CORBA::Object::_duplicate (object_secondary
.in ());
176 // Create a merged set 1;
178 iorm
->merge_iors (iors
);
182 merged_set_
= object_primary
;
189 Manager::set_properties ()
191 FT::TagFTGroupTaggedComponent ft_tag_component
;
195 // Major and Minor revision numbers
196 ft_tag_component
.component_version
.major
= (CORBA::Octet
) 1;
197 ft_tag_component
.component_version
.minor
= (CORBA::Octet
) 0;
200 const char *id
= "iogr_testing";
201 ft_tag_component
.group_domain_id
= id
;
204 ft_tag_component
.object_group_id
=
205 (CORBA::ULongLong
) 10;
208 ft_tag_component
.object_group_ref_version
=
211 // Construct the IOGR Property class
212 TAO_FT_IOGR_Property
iogr_prop (ft_tag_component
);
215 CORBA::Boolean retval
= iorm
->set_primary (&iogr_prop
,
216 object_secondary
.in (),
217 this->merged_set_
.in ());
220 // See we are setting the second ior as the primary
223 retval
= iorm
->set_property (&iogr_prop
,
224 this->merged_set_
.in ());
237 catch (const CORBA::Exception
&)
239 ACE_ERROR_RETURN ((LM_DEBUG
,
248 Manager::write_to_file ()
251 CORBA::String_var iorref
=
252 this->orb_
->object_to_string (this->merged_set_
.in ());
254 if (ior_output_file
!= 0)
256 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
257 if (output_file
== 0)
258 ACE_ERROR_RETURN ((LM_ERROR
,
259 "Cannot open output file for writing IOR: %s",
262 ACE_OS::fprintf (output_file
, "%s", iorref
.in ());
263 ACE_OS::fclose (output_file
);
272 return this->orb_
.in ();
275 Client_i::Client_i (CORBA::ORB_ptr orb
)
276 :orb_ (CORBA::ORB::_duplicate (orb
))
280 int run_remote_test (Simple_Server_ptr server
, const ACE_TCHAR
* execute_key
)
282 char expected
[1024], received
[1024];
285 ACE_OS::sprintf (expected
,
286 "remote_call() completed by %s", ACE_TEXT_ALWAYS_CHAR (execute_key
));
288 else if (shutdown_test
&& !merged_test
)
290 ACE_OS::strcpy (expected
, "CORBA::COMM_FAILURE");
294 ACE_OS::strcpy (expected
, "CORBA::TRANSIENT");
299 // Make a remote call
300 CORBA::String_var s
=
301 server
->remote_call ();
305 ACE_OS::strcpy (received
, "(null)");
309 ACE_OS::strcpy (received
, s
.in());
312 catch (const CORBA::TRANSIENT
&)
314 ACE_OS::strcpy (received
, "CORBA::TRANSIENT");
316 catch (const CORBA::COMM_FAILURE
&)
318 ACE_OS::strcpy (received
, "CORBA::COMM_FAILURE");
321 ACE_DEBUG ((LM_DEBUG
,
322 ACE_TEXT("CLIENT> REMOTE expected: '%C'"),
325 if (ACE_OS::strcmp (expected
, received
))
327 ACE_DEBUG ((LM_DEBUG
,
328 ACE_TEXT ("... FAIL\n")
329 ACE_TEXT ("CLIENT> received: '%C'\n"),
334 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT("... OK\n")));
338 int run_abort_test (Simple_Server_ptr server
,
339 const ACE_TCHAR
* request_key
, const ACE_TCHAR
* execute_key
)
341 char expected
[1024], received
[1024];
344 ACE_OS::sprintf (expected
,
345 "abort() completed by %s, still_alive=1",
346 ACE_TEXT_ALWAYS_CHAR (execute_key
));
348 else if (merged_test
)
350 ACE_OS::strcpy (expected
, "CORBA::TRANSIENT");
354 ACE_OS::strcpy (expected
, "CORBA::COMM_FAILURE");
359 CORBA::String_var s
= server
->abort (ACE_TEXT_ALWAYS_CHAR (request_key
));
363 ACE_OS::strcpy (received
, "(null)");
367 ACE_OS::strcpy (received
, s
.in());
370 catch (const CORBA::TRANSIENT
&)
372 ACE_OS::strcpy (received
, "CORBA::TRANSIENT");
374 catch (const CORBA::COMM_FAILURE
&)
376 ACE_OS::strcpy (received
, "CORBA::COMM_FAILURE");
379 ACE_DEBUG ((LM_DEBUG
,
380 ACE_TEXT("CLIENT> ABORT expected: '%C'"),
382 if (ACE_OS::strcmp (expected
, received
))
384 ACE_DEBUG ((LM_DEBUG
,
385 ACE_TEXT ("... FAIL\n")
386 ACE_TEXT ("CLIENT> received: '%C'\n"),
391 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT("... OK\n")));
395 int run_shutdown_test (Simple_Server_ptr server
,
396 const ACE_TCHAR
* request_key
, const ACE_TCHAR
* execute_key
)
398 char expected
[1024], received
[1024];
401 ACE_OS::sprintf (expected
,
402 "shutdown() completed by %s, still_alive=0",
403 ACE_TEXT_ALWAYS_CHAR (execute_key
));
407 ACE_OS::strcpy (expected
, "CORBA::TRANSIENT");
412 CORBA::String_var s
= server
->shutdown (ACE_TEXT_ALWAYS_CHAR (request_key
));
416 ACE_OS::strcpy (received
, "(null)");
420 ACE_OS::strcpy (received
, s
.in());
423 catch (const CORBA::TRANSIENT
&)
425 ACE_OS::strcpy (received
, "CORBA::TRANSIENT");
428 ACE_DEBUG ((LM_DEBUG
,
429 ACE_TEXT("CLIENT> SHUTDOWN expected: '%C'"),
431 if (ACE_OS::strcmp (expected
, received
))
433 ACE_DEBUG ((LM_DEBUG
,
434 ACE_TEXT ("... FAIL\n")
435 ACE_TEXT ("CLIENT> received: '%C'\n"),
440 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT("... OK\n")));
444 int run_full_abort_test (Simple_Server_ptr server
)
446 int rv
= run_remote_test (server
, second_key
);
452 rv
= run_abort_test (server
, second_key
, first_key
);
458 rv
= run_remote_test (server
, first_key
);
464 rv
= run_abort_test (server
, first_key
, 0);
470 rv
= run_remote_test (server
, 0);
479 int run_full_shutdown_test (Simple_Server_ptr server
)
481 int rv
= run_remote_test (server
, second_key
);
487 rv
= run_shutdown_test (server
, second_key
, second_key
);
493 rv
= run_remote_test (server
, first_key
);
499 rv
= run_shutdown_test (server
, first_key
, first_key
);
505 rv
= run_remote_test (server
, 0);
517 // Open the file for reading.
518 ACE_HANDLE f_handle
= ACE_OS::open (ior_output_file
,
521 if (f_handle
== ACE_INVALID_HANDLE
)
522 ACE_ERROR ((LM_ERROR
,
523 ACE_TEXT("Unable to open %s for writing (%p)\n"),
527 ACE_Read_Buffer
ior_buffer (f_handle
);
529 char *data
= ior_buffer
.read ();
532 ACE_ERROR ((LM_ERROR
,
533 "Unable to read ior: %p\n"));
537 ACE_TCHAR
**argv
= 0;
538 this->orb_
= CORBA::ORB_init (argc
, argv
);
540 CORBA::Object_var object
=
541 this->orb_
->string_to_object (data
);
543 // Combined IOR stuff
544 Simple_Server_var server
=
545 Simple_Server::_narrow (object
.in ());
547 if (CORBA::is_nil (server
.in ()))
549 ACE_ERROR ((LM_ERROR
,
550 "Object reference <%C> is nil\n",
559 rv
= run_shutdown_test (server
.in(), first_key
, first_key
);
563 rv
= run_abort_test (server
.in(), first_key
, 0);
568 rv
= run_remote_test (server
.in(), 0);
571 else if (shutdown_test
)
573 rv
= run_full_shutdown_test (server
.in ());
577 rv
= run_full_abort_test (server
.in ());
580 ior_buffer
.alloc ()->free (data
);
581 ACE_OS::close (f_handle
);