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
,
79 // See we are setting the second ior as the primary
82 retval
= iorm
->set_primary (&iogr_prop
,
87 return new_ref
._retn ();
91 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
95 Server_ORBInitializer2
*temp_initializer
= 0;
96 ACE_NEW_RETURN (temp_initializer
,
97 Server_ORBInitializer2
,
98 -1); // No exceptions yet!
99 PortableInterceptor::ORBInitializer_var orb_initializer
=
102 PortableInterceptor::register_orb_initializer (orb_initializer
.in ());
105 CORBA::ORB_init (argc
, argv
);
107 CORBA::Object_var poa_object
=
108 orb
->resolve_initial_references("RootPOA");
110 PortableServer::POA_var root_poa
=
111 PortableServer::POA::_narrow (poa_object
.in ());
113 if (CORBA::is_nil (root_poa
.in ()))
114 ACE_ERROR_RETURN ((LM_ERROR
,
115 " (%P|%t) Panic: nil RootPOA\n"),
118 PortableServer::POAManager_var poa_manager
=
119 root_poa
->the_POAManager ();
121 CORBA::PolicyList
policies (2);
125 root_poa
->create_id_assignment_policy (PortableServer::USER_ID
);
128 root_poa
->create_lifespan_policy (PortableServer::PERSISTENT
);
130 PortableServer::POA_var my_poa
=
131 root_poa
->create_POA ("my_poa",
135 // Creation of the new POA is over, so destroy the Policy_ptr's.
136 for (CORBA::ULong i
= 0; i
< policies
.length (); ++i
)
138 CORBA::Policy_ptr policy
= policies
[i
];
143 if (parse_args (argc
, argv
) != 0)
146 Hello
*hello_impl
= 0;
147 ACE_NEW_RETURN (hello_impl
,
148 Hello (orb
.in (), Test::Hello::_nil ()),
150 PortableServer::ServantBase_var
owner (hello_impl
);
152 PortableServer::ObjectId_var server_id
=
153 PortableServer::string_to_ObjectId ("server_id");
155 my_poa
->activate_object_with_id (server_id
.in (),
158 CORBA::Object_var hello
=
159 my_poa
->id_to_reference (server_id
.in ());
161 CORBA::String_var ior
=
162 orb
->object_to_string (hello
.in ());
164 // Get a ref to the IORManipulation object
165 CORBA::Object_var IORM
=
166 orb
->resolve_initial_references (TAO_OBJID_IORMANIPULATION
, 0);
170 TAO_IOP::TAO_IOR_Manipulation::_narrow (IORM
.in());
172 CORBA::Object_var server
= orb
->string_to_object (ior
.in ());
174 CORBA::Object_var iogr
= make_iogr ("Domain_1", 1, 1, server
.in ());
176 CORBA::String_var iorgr_string
=
177 orb
->object_to_string (iogr
.in ());
179 // Output the IOR to the <ior_output_file>
180 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
181 if (output_file
== 0)
182 ACE_ERROR_RETURN ((LM_ERROR
,
183 "Cannot open output file for writing IOR: %s",
186 ACE_OS::fprintf (output_file
, "%s", iorgr_string
.in ());
187 ACE_OS::fclose (output_file
);
189 temp_initializer
->set_server_iogr (iogr
.in ());
191 poa_manager
->activate ();
195 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
197 root_poa
->destroy (true, true);
201 catch (const CORBA::Exception
& ex
)
203 ex
._tao_print_exception ("Exception caught:");