Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_2285_Regression / server.cpp
blob968cfa836caae62daed9d79a9d574b8fae02f9fb
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 "ServerORBInitializer.h"
8 #include "ServerRequest_Interceptor.h"
9 #include "tao/PI/PI.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;
15 int
16 parse_args (int argc, ACE_TCHAR *argv[])
18 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
19 int c;
21 while ((c = get_opts ()) != -1)
22 switch (c)
24 case 'o':
25 ior_output_file = get_opts.opt_arg ();
26 break;
28 case '?':
29 default:
30 ACE_ERROR_RETURN ((LM_ERROR,
31 "usage: %s "
32 "-o <iorfile>"
33 "\n",
34 argv [0]),
35 -1);
37 // Indicates successful parsing of the command line
38 return 0;
41 CORBA::Object_ptr
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;
45 // Create the list
46 TAO_IOP::TAO_IOR_Manipulation::IORList iors (1);
47 iors.length(1);
48 iors [0] = CORBA::Object::_duplicate (ref);
50 CORBA::Object_var new_ref =
51 iorm->merge_iors (iors);
53 // Property values
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;
59 // Domain id
60 //const char *id = "iogr_testing";
61 ft_tag_component.group_domain_id = domain_id;
63 // Object group id
64 ft_tag_component.object_group_id = group_id;
66 // Version
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);
72 // Set the property
73 CORBA::Boolean retval = iorm->set_property (&iogr_prop,
74 new_ref.in ());
76 // Set the primary
77 // See we are setting the second ior as the primary
78 if (retval != 0)
80 retval = iorm->set_primary (&iogr_prop,
81 new_ref.in (),
82 new_ref.in ());
85 return new_ref._retn ();
88 int
89 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
91 try
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 =
98 temp_initializer;
100 PortableInterceptor::register_orb_initializer (orb_initializer.in ());
102 CORBA::ORB_var orb =
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);
120 policies.length (2);
122 policies[0] =
123 root_poa->create_id_assignment_policy (PortableServer::USER_ID);
125 policies[1] =
126 root_poa->create_lifespan_policy (PortableServer::PERSISTENT);
128 PortableServer::POA_var my_poa =
129 root_poa->create_POA ("my_poa",
130 poa_manager.in (),
131 policies);
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];
137 policy->destroy ();
141 if (parse_args (argc, argv) != 0)
142 return 1;
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 (),
154 hello_impl);
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);
166 // Narrow
167 iorm =
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",
182 ior_output_file),
184 ACE_OS::fprintf (output_file, "%s", iorgr_string.in ());
185 ACE_OS::fclose (output_file);
187 poa_manager->activate ();
189 orb->run ();
191 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
193 root_poa->destroy (true, true);
195 orb->destroy ();
197 catch (const CORBA::Exception& ex)
199 ex._tao_print_exception ("Exception caught:");
200 return 1;
203 return 0;