1 #include "ace/Get_Opt.h"
2 #include "ace/OS_NS_stdio.h"
3 #include "tao/IORManipulation/IORManip_Loader.h"
4 #include "tao/PortableServer/PortableServer.h"
5 #include "orbsvcs/FaultTolerance/FT_IOGR_Property.h"
6 #include "ServerORBInitializer2.h"
7 #include "ServerRequest_Interceptor2.h"
9 #include "tao/ORBInitializer_Registry.h"
12 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("ior.ior");
13 const ACE_TCHAR
*iogr_output_file
= ACE_TEXT("iogr.ior");
14 TAO_IOP::TAO_IOR_Manipulation_var iorm
= 0;
17 parse_args (int argc
, ACE_TCHAR
*argv
[])
19 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:p:"));
22 while ((c
= get_opts ()) != -1)
26 ior_output_file
= get_opts
.opt_arg ();
29 iogr_output_file
= get_opts
.opt_arg ();
33 ACE_ERROR_RETURN ((LM_ERROR
,
41 // Indicates successful parsing of the command line
46 make_iogr (const char* domain_id
, CORBA::ULongLong group_id
, CORBA::ULong group_version
, CORBA::Object_ptr ref
)
48 FT::TagFTGroupTaggedComponent ft_tag_component
;
50 TAO_IOP::TAO_IOR_Manipulation::IORList
iors (1);
52 iors
[0] = CORBA::Object::_duplicate (ref
);
54 CORBA::Object_var new_ref
=
55 iorm
->merge_iors (iors
);
59 // Major and Minor revision numbers
60 ft_tag_component
.component_version
.major
= (CORBA::Octet
) 1;
61 ft_tag_component
.component_version
.minor
= (CORBA::Octet
) 0;
64 //const char *id = "iogr_testing";
65 ft_tag_component
.group_domain_id
= domain_id
;
68 ft_tag_component
.object_group_id
= group_id
;
71 ft_tag_component
.object_group_ref_version
= group_version
;
73 // Construct the IOGR Property class
74 TAO_FT_IOGR_Property
iogr_prop (ft_tag_component
);
77 CORBA::Boolean retval
= iorm
->set_property (&iogr_prop
,
81 // See we are setting the second ior as the primary
84 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 ());
107 CORBA::ORB_init (argc
, argv
);
109 CORBA::Object_var poa_object
=
110 orb
->resolve_initial_references("RootPOA");
112 PortableServer::POA_var root_poa
=
113 PortableServer::POA::_narrow (poa_object
.in ());
115 if (CORBA::is_nil (root_poa
.in ()))
116 ACE_ERROR_RETURN ((LM_ERROR
,
117 " (%P|%t) Panic: nil RootPOA\n"),
120 PortableServer::POAManager_var poa_manager
=
121 root_poa
->the_POAManager ();
123 CORBA::PolicyList
policies (2);
127 root_poa
->create_id_assignment_policy (PortableServer::USER_ID
);
130 root_poa
->create_lifespan_policy (PortableServer::PERSISTENT
);
132 PortableServer::POA_var my_poa
=
133 root_poa
->create_POA ("my_poa",
137 // Creation of the new POA is over, so destroy the Policy_ptr's.
138 for (CORBA::ULong i
= 0; i
< policies
.length (); ++i
)
140 CORBA::Policy_ptr policy
= policies
[i
];
145 if (parse_args (argc
, argv
) != 0)
148 Hello
*hello_impl
= 0;
149 ACE_NEW_RETURN (hello_impl
,
150 Hello (orb
.in (), Test::Hello::_nil ()),
152 PortableServer::ServantBase_var
owner (hello_impl
);
154 PortableServer::ObjectId_var server_id
=
155 PortableServer::string_to_ObjectId ("server_id");
157 my_poa
->activate_object_with_id (server_id
.in (),
160 CORBA::Object_var hello
=
161 my_poa
->id_to_reference (server_id
.in ());
163 CORBA::String_var ior
=
164 orb
->object_to_string (hello
.in ());
166 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
167 if (output_file
== 0)
168 ACE_ERROR_RETURN ((LM_ERROR
,
169 "Cannot open output file for writing IOR: %s",
172 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
173 ACE_OS::fclose (output_file
);
176 // Get a ref to the IORManipulation object
177 CORBA::Object_var IORM
=
178 orb
->resolve_initial_references (TAO_OBJID_IORMANIPULATION
,
183 TAO_IOP::TAO_IOR_Manipulation::_narrow (IORM
.in());
185 CORBA::Object_var server
= orb
->string_to_object (ior
.in ());
187 CORBA::Object_var iogr
= make_iogr ("Domain_1", 1, 1, server
.in ());
189 CORBA::String_var iorgr_string
=
190 orb
->object_to_string (iogr
.in ());
192 // Output the IOR to the <iogr_output_file>
193 output_file
= ACE_OS::fopen (iogr_output_file
, "w");
194 if (output_file
== 0)
195 ACE_ERROR_RETURN ((LM_ERROR
,
196 "Cannot open output file for writing IOR: %s",
199 ACE_OS::fprintf (output_file
, "%s", iorgr_string
.in ());
200 ACE_OS::fclose (output_file
);
202 poa_manager
->activate ();
206 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
208 root_poa
->destroy (true, true);
212 catch (const CORBA::Exception
& ex
)
214 ex
._tao_print_exception ("Exception caught:");