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
, new_ref
.in ());
76 // See we are setting the second ior as the primary
79 retval
= iorm
->set_primary (&iogr_prop
, new_ref
.in (), new_ref
.in ());
82 return new_ref
._retn ();
86 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
90 Server_ORBInitializer
*temp_initializer
= 0;
91 ACE_NEW_RETURN (temp_initializer
,
92 Server_ORBInitializer
,
93 -1); // No exceptions yet!
94 PortableInterceptor::ORBInitializer_var orb_initializer
=
97 PortableInterceptor::register_orb_initializer (orb_initializer
.in ());
100 CORBA::ORB_init (argc
, argv
);
102 CORBA::Object_var poa_object
=
103 orb
->resolve_initial_references("RootPOA");
105 PortableServer::POA_var root_poa
=
106 PortableServer::POA::_narrow (poa_object
.in ());
108 if (CORBA::is_nil (root_poa
.in ()))
109 ACE_ERROR_RETURN ((LM_ERROR
,
110 " (%P|%t) Panic: nil RootPOA\n"),
113 PortableServer::POAManager_var poa_manager
=
114 root_poa
->the_POAManager ();
116 CORBA::PolicyList
policies (2);
120 root_poa
->create_id_assignment_policy (PortableServer::USER_ID
);
123 root_poa
->create_lifespan_policy (PortableServer::PERSISTENT
);
125 PortableServer::POA_var my_poa
=
126 root_poa
->create_POA ("my_poa", poa_manager
.in (), policies
);
128 // Creation of the new POA is over, so destroy the Policy_ptr's.
129 for (CORBA::ULong i
= 0; i
< policies
.length (); ++i
)
131 CORBA::Policy_ptr policy
= policies
[i
];
135 if (parse_args (argc
, argv
) != 0)
138 Hello
*hello_impl
= 0;
139 ACE_NEW_RETURN (hello_impl
,
142 PortableServer::ServantBase_var
owner (hello_impl
);
144 PortableServer::ObjectId_var server_id
=
145 PortableServer::string_to_ObjectId ("server_id");
147 my_poa
->activate_object_with_id (server_id
.in (),hello_impl
);
149 CORBA::Object_var hello
= my_poa
->id_to_reference (server_id
.in ());
151 CORBA::String_var ior
= orb
->object_to_string (hello
.in ());
153 // Get a ref to the IORManipulation object
154 CORBA::Object_var IORM
=
155 orb
->resolve_initial_references (TAO_OBJID_IORMANIPULATION
, 0);
159 TAO_IOP::TAO_IOR_Manipulation::_narrow (IORM
.in());
161 CORBA::Object_var server
= orb
->string_to_object (ior
.in ());
163 CORBA::Object_var iogr
= make_iogr ("Domain_1", 1, 1, server
.in ());
165 CORBA::String_var iorgr_string
=
166 orb
->object_to_string (iogr
.in ());
168 // Output the IOR to the <ior_output_file>
169 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
170 if (output_file
== 0)
171 ACE_ERROR_RETURN ((LM_ERROR
,
172 "Cannot open output file for writing IOR: %s",
175 ACE_OS::fprintf (output_file
, "%s", iorgr_string
.in ());
176 ACE_OS::fclose (output_file
);
178 poa_manager
->activate ();
183 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
185 root_poa
->destroy (true, true);
189 catch (const CORBA::Exception
& ex
)
191 ex
._tao_print_exception (
192 "Exception caught:");