Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_2615_Regression / server.cpp
blob66fc310132dc81fa3b0b4ab63e85391ba0c82898
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"
8 #include "tao/PI/PI.h"
9 #include "tao/ORBInitializer_Registry.h"
10 #include "Hello.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;
16 int
17 parse_args (int argc, ACE_TCHAR *argv[])
19 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:p:"));
20 int c;
22 while ((c = get_opts ()) != -1)
23 switch (c)
25 case 'o':
26 ior_output_file = get_opts.opt_arg ();
27 break;
28 case 'p':
29 iogr_output_file = get_opts.opt_arg ();
30 break;
31 case '?':
32 default:
33 ACE_ERROR_RETURN ((LM_ERROR,
34 "usage: %s "
35 "-o <iorfile>"
36 "-p <iorfile>"
37 "\n",
38 argv [0]),
39 -1);
41 // Indicates successful parsing of the command line
42 return 0;
45 CORBA::Object_ptr
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;
49 // Create the list
50 TAO_IOP::TAO_IOR_Manipulation::IORList iors (1);
51 iors.length(1);
52 iors [0] = CORBA::Object::_duplicate (ref);
54 CORBA::Object_var new_ref =
55 iorm->merge_iors (iors);
57 // Property values
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;
63 // Domain id
64 //const char *id = "iogr_testing";
65 ft_tag_component.group_domain_id = domain_id;
67 // Object group id
68 ft_tag_component.object_group_id = group_id;
70 // Version
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);
76 // Set the property
77 CORBA::Boolean retval = iorm->set_property (&iogr_prop,
78 new_ref.in ());
80 // Set the primary
81 // See we are setting the second ior as the primary
82 if (retval != 0)
84 retval = iorm->set_primary (&iogr_prop,
85 new_ref.in (),
86 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 ());
106 CORBA::ORB_var orb =
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);
124 policies.length (2);
126 policies[0] =
127 root_poa->create_id_assignment_policy (PortableServer::USER_ID);
129 policies[1] =
130 root_poa->create_lifespan_policy (PortableServer::PERSISTENT);
132 PortableServer::POA_var my_poa =
133 root_poa->create_POA ("my_poa",
134 poa_manager.in (),
135 policies);
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];
141 policy->destroy ();
145 if (parse_args (argc, argv) != 0)
146 return 1;
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 (),
158 hello_impl);
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",
170 ior_output_file),
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,
181 // Narrow
182 iorm =
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",
197 iogr_output_file),
199 ACE_OS::fprintf (output_file, "%s", iorgr_string.in ());
200 ACE_OS::fclose (output_file);
202 poa_manager->activate ();
204 orb->run ();
206 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
208 root_poa->destroy (true, true);
210 orb->destroy ();
212 catch (const CORBA::Exception& ex)
214 ex._tao_print_exception ("Exception caught:");
215 return 1;
218 return 0;