Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_3215_Regression / server.cpp
blob3c1da0dded89e9e3ba48dafba1b63f6888027b98
1 #include "Hello.h"
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"
9 #include "tao/PI/PI.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;
17 int
18 parse_args (int argc, ACE_TCHAR *argv[])
20 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
21 int c;
23 while ((c = get_opts ()) != -1)
24 switch (c)
26 case 'o':
27 ior_output_file = get_opts.opt_arg ();
28 break;
30 case '?':
31 default:
32 ACE_ERROR_RETURN ((LM_ERROR,
33 "usage: %s "
34 "-o <iorfile>"
35 "\n",
36 argv [0]),
37 -1);
39 // Indicates successful parsing of the command line
40 return 0;
43 CORBA::Object_ptr
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;
47 // Create the list
48 TAO_IOP::TAO_IOR_Manipulation::IORList iors (1);
49 iors.length(1);
50 iors [0] = CORBA::Object::_duplicate (ref);
52 CORBA::Object_var new_ref =
53 iorm->merge_iors (iors );
55 // Property values
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;
61 // Domain id
62 //const char *id = "iogr_testing";
63 ft_tag_component.group_domain_id = domain_id;
65 // Object group id
66 ft_tag_component.object_group_id = group_id;
68 // Version
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);
74 // Set the property
75 CORBA::Boolean retval = iorm->set_property (&iogr_prop,
76 new_ref.in ()
79 // Set the primary
80 // See we are setting the second ior as the primary
81 if (retval != 0)
83 retval = iorm->set_primary (&iogr_prop,
84 new_ref.in (),
85 new_ref.in ()
89 return new_ref._retn ();
92 int
93 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
95 try
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 =
102 temp_initializer;
104 PortableInterceptor::register_orb_initializer (orb_initializer.in ()
108 CORBA::ORB_var orb =
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);
130 policies.length (2);
132 policies[0] =
133 root_poa->create_id_assignment_policy (PortableServer::USER_ID
137 policies[1] =
138 root_poa->create_lifespan_policy (PortableServer::PERSISTENT
142 PortableServer::POA_var my_poa =
143 root_poa->create_POA ("my_poa",
144 poa_manager.in (),
145 policies
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];
153 policy->destroy ();
158 if (parse_args (argc, argv) != 0)
159 return 1;
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 (),
171 hello_impl
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,
190 // Narrow
191 iorm =
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",
209 ior_output_file),
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 ();
219 orb->run ();
222 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
224 root_poa->destroy (1, 1 );
227 orb->destroy ();
229 catch (const CORBA::Exception& ex)
231 ex._tao_print_exception (
232 "Exception caught:");
233 return 1;
237 return 0;