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"
14 #include "ace/OS_NS_fcntl.h"
16 // Files which have the IOR
17 const ACE_TCHAR
*first_ior
= 0;
18 const ACE_TCHAR
*second_ior
= 0;
19 const ACE_TCHAR
*ior_output_file
= 0;
21 // Reference to the IOR manipulator
22 TAO_IOP::TAO_IOR_Manipulation_var iorm
= 0;
25 parse_args (int argc
, ACE_TCHAR
*argv
[])
27 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("a:b:c:"));
30 while ((c
= get_opts ()) != -1)
34 first_ior
= get_opts
.opt_arg ();
37 second_ior
= get_opts
.opt_arg ();
40 ior_output_file
= get_opts
.opt_arg ();
44 ACE_ERROR_RETURN ((LM_ERROR
,
48 "-c <output ior file>"
53 // Indicates successful parsing of the command line
58 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
64 // Initilaize the ORB, POA etc.
65 manager
.init (argc
, argv
);
67 // the command line arguments
68 if (parse_args (argc
, argv
) == -1)
71 // Merge the different IORS
72 manager
.make_merged_iors ();
74 // Set properties. This is the most important portion of the
76 manager
.set_properties ();
79 manager
.write_to_file ();
81 // Client, who is going to use the merged IOR
82 // Construct that with the managers ORB
83 Client_i
client_imp (manager
.orb ());
86 catch (const CORBA::Exception
& ex
)
88 ex
._tao_print_exception ("Caught");
96 Manager::init (int argc
, ACE_TCHAR
*argv
[])
98 this->orb_
= CORBA::ORB_init (argc
, argv
);
100 // Obtain the RootPOA.
101 CORBA::Object_var obj_var
=
102 this->orb_
->resolve_initial_references ("RootPOA");
104 // Get the POA_var object from Object_var.
105 PortableServer::POA_var root_poa_var
=
106 PortableServer::POA::_narrow (obj_var
.in ());
108 // Get the POAManager of the RootPOA.
109 PortableServer::POAManager_var poa_manager_var
=
110 root_poa_var
->the_POAManager ();
112 poa_manager_var
->activate ();
116 Manager::make_merged_iors ()
119 this->object_primary_
=
120 this->orb_
->string_to_object (first_ior
);
123 this->object_secondary_
=
124 this->orb_
->string_to_object (second_ior
);
126 // Get an object reference for the ORBs IORManipultion object!
127 CORBA::Object_var IORM
=
128 this->orb_
->resolve_initial_references (TAO_OBJID_IORMANIPULATION
,
132 TAO_IOP::TAO_IOR_Manipulation::_narrow (IORM
.in());
136 TAO_IOP::TAO_IOR_Manipulation::IORList
iors (2);
138 iors
[0] = CORBA::Object::_duplicate (this->object_primary_
.in ());
139 iors
[1] = CORBA::Object::_duplicate (this->object_secondary_
.in ());
141 // Create a merged set 1;
143 iorm
->merge_iors (iors
);
149 Manager::set_properties ()
151 FT::TagFTGroupTaggedComponent ft_tag_component
;
155 // Major and Minor revision numbers
156 ft_tag_component
.component_version
.major
= (CORBA::Octet
) 1;
157 ft_tag_component
.component_version
.minor
= (CORBA::Octet
) 0;
160 const char *id
= "iogr_testing";
161 ft_tag_component
.group_domain_id
= id
;
164 ft_tag_component
.object_group_id
=
165 (CORBA::ULongLong
) 10;
168 ft_tag_component
.object_group_ref_version
=
171 // Construct the IOGR Property class
172 TAO_FT_IOGR_Property
iogr_prop (ft_tag_component
);
175 CORBA::Boolean retval
= iorm
->set_property (&iogr_prop
,
176 this->merged_set_
.in ());
179 // See we are setting the second ior as the primary
182 retval
= iorm
->set_primary (&iogr_prop
,
183 this->object_secondary_
.in (),
184 this->merged_set_
.in ());
197 catch (const CORBA::Exception
&)
199 ACE_ERROR_RETURN ((LM_DEBUG
,
208 Manager::write_to_file ()
211 CORBA::String_var iorref
=
212 this->orb_
->object_to_string (this->merged_set_
.in ());
214 if (ior_output_file
!= 0)
216 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
217 if (output_file
== 0)
218 ACE_ERROR_RETURN ((LM_ERROR
,
219 "Cannot open output file for writing IOR: %s",
222 ACE_OS::fprintf (output_file
, "%s", iorref
.in ());
223 ACE_OS::fclose (output_file
);
232 return this->orb_
.in ();
235 Client_i::Client_i (CORBA::ORB_ptr orb
)
236 :orb_ (CORBA::ORB::_duplicate (orb
))
241 run_test (Simple_Server_ptr server
);
246 // Open the file for reading.
247 ACE_HANDLE f_handle
= ACE_OS::open (ior_output_file
,
250 if (f_handle
== ACE_INVALID_HANDLE
)
251 ACE_ERROR ((LM_ERROR
,
252 "Unable to open %s for writing: %p\n",
255 ACE_Read_Buffer
ior_buffer (f_handle
);
257 char *data
= ior_buffer
.read ();
260 ACE_ERROR ((LM_ERROR
,
261 "Unable to read ior: %p\n"));
265 ACE_TCHAR
**argv
= 0;
266 this->orb_
= CORBA::ORB_init (argc
, argv
);
268 CORBA::Object_var object
=
269 this->orb_
->string_to_object (data
);
271 // Combined IOR stuff
272 Simple_Server_var server
=
273 Simple_Server::_narrow (object
.in ());
275 if (CORBA::is_nil (server
.in ()))
277 ACE_ERROR ((LM_ERROR
,
278 "Object reference <%C> is nil\n",
282 run_test (server
.in ());
284 ior_buffer
.alloc ()->free (data
);
285 ACE_OS::close (f_handle
);
289 void run_test (Simple_Server_ptr server
)
291 // We do this twice as we know that there are only two servers.
292 for (CORBA::ULong i
= 0;
298 for (CORBA::ULong j
= 0;
302 // Make a remote call
303 server
->remote_call ();
306 ACE_DEBUG ((LM_DEBUG
,
307 ACE_TEXT ("*********************************\n")));
308 ACE_DEBUG ((LM_DEBUG
,
309 ACE_TEXT ("I am going to shutdown the server\n")));
313 catch (const CORBA::TRANSIENT
& t
)
315 if (t
.completed () != CORBA::COMPLETED_NO
)
317 t
._tao_print_exception ("Unexpected kind of TRANSIENT");
321 ACE_DEBUG ((LM_DEBUG
,
322 ACE_TEXT ("The completed status %d\n"), t
.completed ()));
323 ACE_DEBUG ((LM_DEBUG
,
324 ACE_TEXT ("Automagically re-issuing request on TRANSIENT\n")));
328 catch (const CORBA::COMM_FAILURE
& f
)
330 f
._tao_print_exception ("A (sort of) expected COMM_FAILURE");
331 ACE_DEBUG ((LM_DEBUG
,
332 ACE_TEXT ("Automagically re-issuing request on COMM_FAILURE\n")));
334 catch (const CORBA::Exception
& ex
)
336 ex
._tao_print_exception ("Unexpected exception");