Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_2287_Regression / server.cpp
blobcd96b6ae3300e3ff0c52daf30563cd6731e53f50
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 ());
78 // Set the primary
79 // See we are setting the second ior as the primary
80 if (retval != 0)
82 retval = iorm->set_primary (&iogr_prop,
83 new_ref.in (),
84 new_ref.in ());
87 return new_ref._retn ();
90 int
91 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
93 try
95 Server_ORBInitializer2 *temp_initializer = 0;
96 ACE_NEW_RETURN (temp_initializer,
97 Server_ORBInitializer2,
98 -1); // No exceptions yet!
99 PortableInterceptor::ORBInitializer_var orb_initializer =
100 temp_initializer;
102 PortableInterceptor::register_orb_initializer (orb_initializer.in ());
104 CORBA::ORB_var orb =
105 CORBA::ORB_init (argc, argv);
107 CORBA::Object_var poa_object =
108 orb->resolve_initial_references("RootPOA");
110 PortableServer::POA_var root_poa =
111 PortableServer::POA::_narrow (poa_object.in ());
113 if (CORBA::is_nil (root_poa.in ()))
114 ACE_ERROR_RETURN ((LM_ERROR,
115 " (%P|%t) Panic: nil RootPOA\n"),
118 PortableServer::POAManager_var poa_manager =
119 root_poa->the_POAManager ();
121 CORBA::PolicyList policies (2);
122 policies.length (2);
124 policies[0] =
125 root_poa->create_id_assignment_policy (PortableServer::USER_ID);
127 policies[1] =
128 root_poa->create_lifespan_policy (PortableServer::PERSISTENT);
130 PortableServer::POA_var my_poa =
131 root_poa->create_POA ("my_poa",
132 poa_manager.in (),
133 policies);
135 // Creation of the new POA is over, so destroy the Policy_ptr's.
136 for (CORBA::ULong i = 0; i < policies.length (); ++i)
138 CORBA::Policy_ptr policy = policies[i];
139 policy->destroy ();
143 if (parse_args (argc, argv) != 0)
144 return 1;
146 Hello *hello_impl = 0;
147 ACE_NEW_RETURN (hello_impl,
148 Hello (orb.in (), Test::Hello::_nil ()),
150 PortableServer::ServantBase_var owner (hello_impl);
152 PortableServer::ObjectId_var server_id =
153 PortableServer::string_to_ObjectId ("server_id");
155 my_poa->activate_object_with_id (server_id.in (),
156 hello_impl);
158 CORBA::Object_var hello =
159 my_poa->id_to_reference (server_id.in ());
161 CORBA::String_var ior =
162 orb->object_to_string (hello.in ());
164 // Get a ref to the IORManipulation object
165 CORBA::Object_var IORM =
166 orb->resolve_initial_references (TAO_OBJID_IORMANIPULATION, 0);
168 // Narrow
169 iorm =
170 TAO_IOP::TAO_IOR_Manipulation::_narrow (IORM.in());
172 CORBA::Object_var server = orb->string_to_object (ior.in ());
174 CORBA::Object_var iogr = make_iogr ("Domain_1", 1, 1, server.in ());
176 CORBA::String_var iorgr_string =
177 orb->object_to_string (iogr.in ());
179 // Output the IOR to the <ior_output_file>
180 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
181 if (output_file == 0)
182 ACE_ERROR_RETURN ((LM_ERROR,
183 "Cannot open output file for writing IOR: %s",
184 ior_output_file),
186 ACE_OS::fprintf (output_file, "%s", iorgr_string.in ());
187 ACE_OS::fclose (output_file);
189 temp_initializer->set_server_iogr (iogr.in ());
191 poa_manager->activate ();
193 orb->run ();
195 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
197 root_poa->destroy (true, true);
199 orb->destroy ();
201 catch (const CORBA::Exception& ex)
203 ex._tao_print_exception ("Exception caught:");
204 return 1;
207 return 0;