Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / RTCORBA / Diffserv / server.cpp
blob3e7aaf5ec1d557e19bb966ac5daf7f74a39ee7de
1 #include "testS.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "tao/RTCORBA/RTCORBA.h"
5 #include "tao/RTPortableServer/RTPortableServer.h"
6 #include "tao/RTCORBA/Network_Priority_Mapping_Manager.h"
7 #include "tao/RTCORBA/Network_Priority_Mapping.h"
8 #include "Custom_Network_Priority_Mapping.h"
9 #include "tao/debug.h"
11 class Test_i : public POA_Test
13 public:
14 Test_i (CORBA::ORB_ptr orb);
16 void test_method ();
18 //FUZZ: disable check_for_lack_ACE_OS
19 void shutdown ();
20 //FUZZ: enable check_for_lack_ACE_OS
22 private:
23 CORBA::ORB_var orb_;
26 Test_i::Test_i (CORBA::ORB_ptr orb)
27 : orb_ (CORBA::ORB::_duplicate (orb))
31 void
32 Test_i::test_method ()
34 ACE_DEBUG ((LM_DEBUG,
35 "Test_i::test_method\n"));
38 void
39 Test_i::shutdown ()
41 this->orb_->shutdown (false);
44 static const ACE_TCHAR *simple_servant_ior_file = ACE_TEXT("simple_servant.ior");
45 static const ACE_TCHAR *diffserv_servant_ior_file = ACE_TEXT("diffserv_servant.ior");
46 static RTCORBA::Priority corba_priority = RTCORBA::minPriority;
48 int
49 parse_args (int argc, ACE_TCHAR *argv[])
51 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("p:"));
52 int c;
54 while ((c = get_opts ()) != -1)
55 switch (c)
57 case 'p':
58 corba_priority = ACE_OS::atoi (get_opts.opt_arg ());
59 break;
61 default:
62 ACE_ERROR_RETURN ((LM_ERROR,
63 "usage: %s\n"
64 "\t-p <corba priority> [defaults to %d]\n"
65 "\n",
66 argv [0],
67 corba_priority),
68 -1);
71 return 0;
74 void
75 create_object (PortableServer::POA_ptr poa,
76 CORBA::ORB_ptr orb,
77 PortableServer::Servant servant,
78 const ACE_TCHAR *filename)
80 // Register with poa.
81 PortableServer::ObjectId_var id =
82 poa->activate_object (servant);
84 CORBA::Object_var object =
85 poa->id_to_reference (id.in ());
87 CORBA::String_var ior =
88 orb->object_to_string (object.in ());
90 FILE *output_file= ACE_OS::fopen (filename, "w");
91 ACE_OS::fprintf (output_file, "%s", ior.in ());
92 ACE_OS::fclose (output_file);
95 int
96 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
98 try
100 CORBA::Object_var object;
102 // ORB.
103 CORBA::ORB_var orb =
104 CORBA::ORB_init (argc, argv);
106 // Parse arguments.
107 if (parse_args (argc, argv) != 0)
108 return -1;
110 // RootPOA.
111 object =
112 orb->resolve_initial_references ("RootPOA");
114 PortableServer::POA_var root_poa =
115 PortableServer::POA::_narrow (object.in ());
117 // POAManager.
118 PortableServer::POAManager_var poa_manager =
119 root_poa->the_POAManager ();
121 // Servant.
122 Test_i servant (orb.in ());
124 // Create the first object in Root POA
125 create_object (root_poa.in (),
126 orb.in (),
127 &servant,
128 simple_servant_ior_file);
130 object =
131 orb->resolve_initial_references ("NetworkPriorityMappingManager");
133 RTCORBA::NetworkPriorityMappingManager_var mapping_manager =
134 RTCORBA::NetworkPriorityMappingManager::_narrow (object.in ());
136 Custom_Network_Priority_Mapping *cnpm = 0;
137 ACE_NEW_RETURN (cnpm,
138 Custom_Network_Priority_Mapping,
139 -1);
141 cnpm->corba_priority (corba_priority);
143 mapping_manager->mapping (cnpm);
145 // RTORB.
146 object =
147 orb->resolve_initial_references ("RTORB");
149 RTCORBA::RTORB_var rt_orb =
150 RTCORBA::RTORB::_narrow (object.in ());
152 // Set transport protocol properties
153 RTCORBA::TCPProtocolProperties_var tcp_properties =
154 rt_orb->create_tcp_protocol_properties (ACE_DEFAULT_MAX_SOCKET_BUFSIZ,
155 ACE_DEFAULT_MAX_SOCKET_BUFSIZ,
161 RTCORBA::ProtocolList protocols;
162 protocols.length (1);
163 protocols[0].protocol_type = 0;
164 protocols[0].transport_protocol_properties =
165 RTCORBA::ProtocolProperties::_duplicate (tcp_properties.in ());
166 protocols[0].orb_protocol_properties =
167 RTCORBA::ProtocolProperties::_nil ();
169 CORBA::PolicyList policy_list;
170 policy_list.length (1);
172 policy_list[0] =
173 rt_orb->create_server_protocol_policy (protocols);
175 // Create POA with Diffserv enabled
176 PortableServer::POA_var poa_with_diffserv =
177 root_poa->create_POA ("POA_WITH_DS",
178 poa_manager.in (),
179 policy_list);
181 // Create object 2.
182 create_object (poa_with_diffserv.in (),
183 orb.in (),
184 &servant,
185 diffserv_servant_ior_file);
187 // Activate POA manager.
188 poa_manager->activate ();
190 // Start ORB event loop.
191 orb->run ();
193 ACE_DEBUG ((LM_DEBUG, "Server ORB event loop finished\n\n"));
195 catch (const CORBA::Exception& ex)
197 ex._tao_print_exception ("Unexpected exception caught:");
198 return -1;
201 return 0;