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 "ServerORBInitializer.h"
8 #include "ServerRequest_Interceptor.h"
10 #include "tao/ORBInitializer_Registry.h"
12 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
13 TAO_IOP::TAO_IOR_Manipulation_var iorm
= 0;
16 parse_args (int argc
, ACE_TCHAR
*argv
[])
18 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
21 while ((c
= get_opts ()) != -1)
25 ior_output_file
= get_opts
.opt_arg ();
30 ACE_ERROR_RETURN ((LM_ERROR
,
37 // Indicates successful parsing of the command line
42 make_iogr (const char* domain_id
, CORBA::ULongLong group_id
, CORBA::ULong group_version
, CORBA::Object_ptr ref
)
44 FT::TagFTGroupTaggedComponent ft_tag_component
;
46 TAO_IOP::TAO_IOR_Manipulation::IORList
iors (1);
48 iors
[0] = CORBA::Object::_duplicate (ref
);
50 CORBA::Object_var new_ref
=
51 iorm
->merge_iors (iors
);
55 // Major and Minor revision numbers
56 ft_tag_component
.component_version
.major
= (CORBA::Octet
) 1;
57 ft_tag_component
.component_version
.minor
= (CORBA::Octet
) 0;
60 //const char *id = "iogr_testing";
61 ft_tag_component
.group_domain_id
= domain_id
;
64 ft_tag_component
.object_group_id
= group_id
;
67 ft_tag_component
.object_group_ref_version
= group_version
;
69 // Construct the IOGR Property class
70 TAO_FT_IOGR_Property
iogr_prop (ft_tag_component
);
73 CORBA::Boolean retval
= iorm
->set_property (&iogr_prop
,
77 // See we are setting the second ior as the primary
80 retval
= iorm
->set_primary (&iogr_prop
,
85 return new_ref
._retn ();
89 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
93 Server_ORBInitializer
*temp_initializer
= 0;
94 ACE_NEW_RETURN (temp_initializer
,
95 Server_ORBInitializer
,
96 -1); // No exceptions yet!
97 PortableInterceptor::ORBInitializer_var orb_initializer
=
100 PortableInterceptor::register_orb_initializer (orb_initializer
.in ());
103 CORBA::ORB_init (argc
, argv
);
105 CORBA::Object_var poa_object
=
106 orb
->resolve_initial_references("RootPOA");
108 PortableServer::POA_var root_poa
=
109 PortableServer::POA::_narrow (poa_object
.in ());
111 if (CORBA::is_nil (root_poa
.in ()))
112 ACE_ERROR_RETURN ((LM_ERROR
,
113 " (%P|%t) Panic: nil RootPOA\n"),
116 PortableServer::POAManager_var poa_manager
=
117 root_poa
->the_POAManager ();
119 CORBA::PolicyList
policies (2);
123 root_poa
->create_id_assignment_policy (PortableServer::USER_ID
);
126 root_poa
->create_lifespan_policy (PortableServer::PERSISTENT
);
128 PortableServer::POA_var my_poa
=
129 root_poa
->create_POA ("my_poa",
133 // Creation of the new POA is over, so destroy the Policy_ptr's.
134 for (CORBA::ULong i
= 0; i
< policies
.length (); ++i
)
136 CORBA::Policy_ptr policy
= policies
[i
];
141 if (parse_args (argc
, argv
) != 0)
144 Hello
*hello_impl
= 0;
145 ACE_NEW_RETURN (hello_impl
,
146 Hello (orb
.in (), Test::Hello::_nil ()),
148 PortableServer::ServantBase_var
owner (hello_impl
);
150 PortableServer::ObjectId_var server_id
=
151 PortableServer::string_to_ObjectId ("server_id");
153 my_poa
->activate_object_with_id (server_id
.in (),
156 CORBA::Object_var hello
=
157 my_poa
->id_to_reference (server_id
.in ());
159 CORBA::String_var ior
=
160 orb
->object_to_string (hello
.in ());
162 // Get a ref to the IORManipulation object
163 CORBA::Object_var IORM
=
164 orb
->resolve_initial_references (TAO_OBJID_IORMANIPULATION
, 0);
168 TAO_IOP::TAO_IOR_Manipulation::_narrow (IORM
.in());
170 CORBA::Object_var server
= orb
->string_to_object (ior
.in ());
172 CORBA::Object_var iogr
= make_iogr ("Domain_1", 1, 1, server
.in ());
174 CORBA::String_var iorgr_string
=
175 orb
->object_to_string (iogr
.in ());
177 // Output the IOR to the <ior_output_file>
178 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
179 if (output_file
== 0)
180 ACE_ERROR_RETURN ((LM_ERROR
,
181 "Cannot open output file for writing IOR: %s",
184 ACE_OS::fprintf (output_file
, "%s", iorgr_string
.in ());
185 ACE_OS::fclose (output_file
);
187 poa_manager
->activate ();
191 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
193 root_poa
->destroy (true, true);
197 catch (const CORBA::Exception
& ex
)
199 ex
._tao_print_exception ("Exception caught:");