4 #include "ace/Get_Opt.h"
5 #include "ace/Read_Buffer.h"
6 #include "tao/IORManipulation/IORManip_Loader.h"
7 #include "tao/PortableServer/PortableServer.h"
8 // Ensure that the PI library is linked in when building statically
10 #include "orbsvcs/FaultTolerance/FT_Service_Activate.h"
11 #include "orbsvcs/FaultTolerance/FT_IOGR_Property.h"
12 #include "ace/OS_NS_stdio.h"
13 #include "ace/OS_NS_unistd.h"
15 // Files which have the IOR
16 const ACE_TCHAR
*first_ior
= 0;
17 const ACE_TCHAR
*first_key
= 0;
18 const ACE_TCHAR
*second_ior
= 0;
19 const ACE_TCHAR
*second_key
= 0;
20 const ACE_TCHAR
*first_iogr_file
= 0;
21 const ACE_TCHAR
*second_iogr_file
= 0;
23 int sleep_delay
= 15; //seconds
26 CORBA::Object_var object_primary
= 0;
27 CORBA::Object_var object_secondary
= 0;
29 // Reference to the IOR manipulator
32 parse_args (int argc
, ACE_TCHAR
*argv
[])
34 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("a:k:b:l:g:h:t:"));
37 while ((c
= get_opts ()) != -1)
41 first_ior
= get_opts
.opt_arg ();
44 first_key
= get_opts
.opt_arg ();
47 second_ior
= get_opts
.opt_arg ();
50 second_key
= get_opts
.opt_arg ();
53 first_iogr_file
= get_opts
.opt_arg ();
56 second_iogr_file
= get_opts
.opt_arg ();
59 sleep_delay
= ACE_OS::atoi(get_opts
.opt_arg ());
63 ACE_ERROR_RETURN ((LM_ERROR
,
65 "-a <iorfile1> -k <key1> "
66 "-b <iorfile2> -l <key2> "
67 "-g <iogr v10 output file> "
68 "-h <iogr v11 output file> "
73 // Indicates successful parsing of the command line
79 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
85 // Initilaize the ORB, POA etc.
86 manager
.init (argc
, argv
);
88 // the command line arguments
89 if (parse_args (argc
, argv
) == -1)
92 // Merge the different IORS
93 manager
.make_merged_iors ();
96 if (manager
.write_to_files ())
99 ACE_OS::sleep (sleep_delay
);
101 // Client, who is going to use the merged IOR
102 // Construct that with the managers ORB
103 Client_i
client_imp (manager
.orb ());
104 return client_imp
.init ();
106 catch (const CORBA::Exception
& ex
)
108 ex
._tao_print_exception ("Caught");
121 Manager::init (int& argc
,
124 this->orb_
= CORBA::ORB_init (argc
, argv
);
126 // Obtain the RootPOA.
127 CORBA::Object_var obj_var
=
128 this->orb_
->resolve_initial_references ("RootPOA");
130 // Get the POA_var object from Object_var.
131 PortableServer::POA_var root_poa_var
=
132 PortableServer::POA::_narrow (obj_var
.in ());
134 // Get the POAManager of the RootPOA.
135 PortableServer::POAManager_var poa_manager_var
=
136 root_poa_var
->the_POAManager ();
138 poa_manager_var
->activate ();
142 Manager::make_merged_iors ()
144 // Get an object reference for the ORBs IORManipultion object!
145 CORBA::Object_var IORM
=
146 this->orb_
->resolve_initial_references (TAO_OBJID_IORMANIPULATION
, 0);
148 if (CORBA::is_nil (IORM
.in()))
151 TAO_IOP::TAO_IOR_Manipulation_var iorm
=
152 TAO_IOP::TAO_IOR_Manipulation::_narrow (IORM
.in());
154 if (CORBA::is_nil (iorm
.in()))
157 CORBA::Object_var first
= orb_
->string_to_object (first_ior
);
159 if (CORBA::is_nil (first
.in()))
163 TAO_IOP::TAO_IOR_Manipulation::IORList
iors (1);
167 merged_set_10_
= iorm
->merge_iors (iors
);
169 if (CORBA::is_nil (merged_set_10_
.in()))
174 int result
= set_properties (iorm
.in(), merged_set_10_
.in(),
182 first
= orb_
->string_to_object (first_ior
);
183 if (CORBA::is_nil (first
.in()))
188 CORBA::Object_var second
= orb_
->string_to_object (second_ior
);
190 if (CORBA::is_nil (second
.in()))
201 merged_set_11_
= iorm
->merge_iors (iors
);
203 if (CORBA::is_nil (merged_set_11_
.in()))
208 result
= set_properties (iorm
.in(), merged_set_11_
.in(),
220 Manager::set_properties (TAO_IOP::TAO_IOR_Manipulation_ptr iorm
,
221 CORBA::Object_ptr merged_set
,
222 CORBA::Object_ptr primary
,
223 CORBA::ULong version
)
225 FT::TagFTGroupTaggedComponent ft_tag_component
;
229 // Major and Minor revision numbers
230 ft_tag_component
.component_version
.major
= (CORBA::Octet
) 1;
231 ft_tag_component
.component_version
.minor
= (CORBA::Octet
) 0;
234 const char *id
= "iogr_testing";
235 ft_tag_component
.group_domain_id
= id
;
238 ft_tag_component
.object_group_id
= 10;
241 ft_tag_component
.object_group_ref_version
= version
;
243 // Construct the IOGR Property class
244 TAO_FT_IOGR_Property
iogr_prop (ft_tag_component
);
247 CORBA::Boolean retval
= iorm
->set_primary (&iogr_prop
,
252 // See we are setting the second ior as the primary
255 retval
= iorm
->set_property (&iogr_prop
,
269 catch (const CORBA::Exception
&)
271 ACE_ERROR_RETURN ((LM_DEBUG
,
279 int Manager::write_to_files ()
281 if (write_to_file (merged_set_10_
.in(), first_iogr_file
) ||
282 write_to_file (merged_set_11_
.in(), second_iogr_file
))
290 Manager::write_to_file (CORBA::Object_ptr ior
, const ACE_TCHAR
*ior_output_file
)
292 CORBA::String_var iorref
=
293 this->orb_
->object_to_string (ior
);
295 if (ior_output_file
!= 0)
297 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
298 if (output_file
== 0)
299 ACE_ERROR_RETURN ((LM_ERROR
,
300 "Cannot open output file for writing IOR: %s",
303 ACE_OS::fprintf (output_file
, "%s", iorref
.in ());
304 ACE_OS::fclose (output_file
);
313 return this->orb_
.in ();
316 Client_i::Client_i (CORBA::ORB_ptr orb
)
317 :orb_ (CORBA::ORB::_duplicate (orb
))
321 int run_remote_test (Simple_Server_ptr server
, const ACE_TCHAR
* execute_key
)
323 char expected
[1024], received
[1024];
326 ACE_OS::sprintf (expected
,
327 "remote_call() completed by %s", ACE_TEXT_ALWAYS_CHAR (execute_key
));
331 ACE_OS::strcpy (expected
, "CORBA::TRANSIENT");
336 // Make a remote call
337 CORBA::String_var s
=
338 server
->remote_call ();
342 ACE_OS::strcpy (received
, "(null)");
346 ACE_OS::strcpy (received
, s
.in());
349 catch (const CORBA::TRANSIENT
&)
351 ACE_OS::strcpy (received
, "CORBA::TRANSIENT");
353 catch (const CORBA::COMM_FAILURE
&)
355 ACE_OS::strcpy (received
, "CORBA::COMM_FAILURE");
358 ACE_DEBUG ((LM_DEBUG
,
359 ACE_TEXT("CLIENT> REMOTE expected: '%C'"),
361 if (ACE_OS::strcmp (expected
, received
))
363 ACE_DEBUG ((LM_DEBUG
,
364 ACE_TEXT ("... FAIL\n")
365 ACE_TEXT ("CLIENT> received: '%C'\n"),
370 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT("... OK\n")));
374 int run_abort_test (Simple_Server_ptr server
,
375 const ACE_TCHAR
* request_key
,
376 const ACE_TCHAR
* execute_key
)
378 char expected
[1024], received
[1024];
381 ACE_OS::sprintf (expected
,
382 "abort() completed by %s, still_alive=1",
383 ACE_TEXT_ALWAYS_CHAR (execute_key
));
387 ACE_OS::strcpy (expected
, "CORBA::TRANSIENT");
392 CORBA::String_var s
= server
->abort (ACE_TEXT_ALWAYS_CHAR (request_key
));
396 ACE_OS::strcpy (received
, "(null)");
400 ACE_OS::strcpy (received
, s
.in());
403 catch (const CORBA::TRANSIENT
&)
405 ACE_OS::strcpy (received
, "CORBA::TRANSIENT");
407 catch (const CORBA::COMM_FAILURE
&)
409 ACE_OS::strcpy (received
, "CORBA::COMM_FAILURE");
412 ACE_DEBUG ((LM_DEBUG
,
413 ACE_TEXT("CLIENT> ABORT expected: '%C'"),
416 if (ACE_OS::strcmp (expected
, received
))
418 ACE_DEBUG ((LM_DEBUG
,
419 ACE_TEXT ("... FAIL\n")
420 ACE_TEXT ("CLIENT> received: '%C'\n"),
425 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT("... OK\n")));
429 int run_test (Simple_Server_ptr server
)
431 int rv
= run_abort_test (server
, first_key
, second_key
);
438 rv
= run_remote_test (server
, second_key
);
445 rv
= run_abort_test (server
, second_key
, 0);
454 ACE_OS::sprintf (iogrstr
, "file://%s", ACE_TEXT_ALWAYS_CHAR (first_iogr_file
));
457 ACE_TCHAR
**argv
= 0;
458 this->orb_
= CORBA::ORB_init (argc
, argv
);
460 CORBA::Object_var object
=
461 this->orb_
->string_to_object (iogrstr
);
464 // Combined IOR stuff
465 Simple_Server_var server
=
466 Simple_Server::_narrow (object
.in ());
468 if (CORBA::is_nil (server
.in ()))
470 ACE_ERROR ((LM_ERROR
,
471 "Object reference <%C> is nil\n",
476 int result
= run_test (server
.in());