2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "tao/IORManipulation/IORManip_Loader.h"
5 #include "tao/PortableServer/PortableServer.h"
6 #include "orbsvcs/FaultTolerance/FT_IOGR_Property.h"
7 #include "ServerORBInitializer2.h"
8 #include "ServerRequest_Interceptor2.h"
10 #include "tao/ORBInitializer_Registry.h"
11 // Make sure this file is included to avoid permanent forward problems in win32.
12 #include "orbsvcs/FaultTolerance/FT_ClientService_Activate.h"
14 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
15 TAO_IOP::TAO_IOR_Manipulation_var iorm
= 0;
18 parse_args (int argc
, ACE_TCHAR
*argv
[])
20 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
23 while ((c
= get_opts ()) != -1)
27 ior_output_file
= get_opts
.opt_arg ();
32 ACE_ERROR_RETURN ((LM_ERROR
,
39 // Indicates successful parsing of the command line
44 make_iogr (const char* domain_id
, CORBA::ULongLong group_id
, CORBA::ULong group_version
, CORBA::Object_ptr ref
)
46 FT::TagFTGroupTaggedComponent ft_tag_component
;
48 TAO_IOP::TAO_IOR_Manipulation::IORList
iors (1);
50 iors
[0] = CORBA::Object::_duplicate (ref
);
52 CORBA::Object_var new_ref
=
53 iorm
->merge_iors (iors
);
57 // Major and Minor revision numbers
58 ft_tag_component
.component_version
.major
= (CORBA::Octet
) 1;
59 ft_tag_component
.component_version
.minor
= (CORBA::Octet
) 0;
62 //const char *id = "iogr_testing";
63 ft_tag_component
.group_domain_id
= domain_id
;
66 ft_tag_component
.object_group_id
= group_id
;
69 ft_tag_component
.object_group_ref_version
= group_version
;
71 // Construct the IOGR Property class
72 TAO_FT_IOGR_Property
iogr_prop (ft_tag_component
);
75 CORBA::Boolean retval
= iorm
->set_property (&iogr_prop
,
80 // See we are setting the second ior as the primary
83 retval
= iorm
->set_primary (&iogr_prop
,
89 return new_ref
._retn ();
93 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
97 Server_ORBInitializer2
*temp_initializer
= 0;
98 ACE_NEW_RETURN (temp_initializer
,
99 Server_ORBInitializer2
,
100 -1); // No exceptions yet!
101 PortableInterceptor::ORBInitializer_var orb_initializer
=
104 PortableInterceptor::register_orb_initializer (orb_initializer
.in ()
109 CORBA::ORB_init (argc
, argv
);
112 CORBA::Object_var poa_object
=
113 orb
->resolve_initial_references("RootPOA" );
116 PortableServer::POA_var root_poa
=
117 PortableServer::POA::_narrow (poa_object
.in () );
120 if (CORBA::is_nil (root_poa
.in ()))
121 ACE_ERROR_RETURN ((LM_ERROR
,
122 " (%P|%t) Panic: nil RootPOA\n"),
125 PortableServer::POAManager_var poa_manager
=
126 root_poa
->the_POAManager ();
129 CORBA::PolicyList
policies (2);
133 root_poa
->create_id_assignment_policy (PortableServer::USER_ID
138 root_poa
->create_lifespan_policy (PortableServer::PERSISTENT
142 PortableServer::POA_var my_poa
=
143 root_poa
->create_POA ("my_poa",
149 // Creation of the new POA is over, so destroy the Policy_ptr's.
150 for (CORBA::ULong i
= 0; i
< policies
.length (); ++i
)
152 CORBA::Policy_ptr policy
= policies
[i
];
158 if (parse_args (argc
, argv
) != 0)
161 Hello
*hello_impl
= 0;
162 ACE_NEW_RETURN (hello_impl
,
163 Hello (orb
.in (), Test::Hello::_nil ()),
165 PortableServer::ServantBase_var
holder (hello_impl
);
167 PortableServer::ObjectId_var server_id
=
168 PortableServer::string_to_ObjectId ("server_id");
170 my_poa
->activate_object_with_id (server_id
.in (),
175 CORBA::Object_var hello
=
176 my_poa
->id_to_reference (server_id
.in () );
179 CORBA::String_var ior
=
180 orb
->object_to_string (hello
.in () );
183 // Get a ref to the IORManipulation object
184 CORBA::Object_var IORM
=
185 orb
->resolve_initial_references (TAO_OBJID_IORMANIPULATION
,
192 TAO_IOP::TAO_IOR_Manipulation::_narrow (IORM
.in() );
194 CORBA::Object_var iortmp
=
195 orb
->string_to_object (ior
.in ());
197 CORBA::Object_var iogr
= make_iogr ("Domain_1", 1, 1, iortmp
.in ());
200 CORBA::String_var iorgr_string
=
201 orb
->object_to_string (iogr
.in () );
204 // Output the IOR to the <ior_output_file>
205 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
206 if (output_file
== 0)
207 ACE_ERROR_RETURN ((LM_ERROR
,
208 "Cannot open output file for writing IOR: %s",
211 ACE_OS::fprintf (output_file
, "%s", iorgr_string
.in ());
212 ACE_OS::fclose (output_file
);
214 temp_initializer
->set_server_iogr (iogr
.in ());
216 poa_manager
->activate ();
222 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
224 root_poa
->destroy (1, 1 );
229 catch (const CORBA::Exception
& ex
)
231 ex
._tao_print_exception (
232 "Exception caught:");