Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / RTCORBA / Diffserv / client.cpp
blob396bf3cbe4f34f1d69cd5f1d4d29e4132be6d161
1 #include "testC.h"
2 #include "tao/RTCORBA/RTCORBA.h"
3 #include "tao/RTCORBA/Network_Priority_Mapping_Manager.h"
4 #include "tao/RTCORBA/Network_Priority_Mapping.h"
5 #include "Custom_Network_Priority_Mapping.h"
6 #include "ace/Get_Opt.h"
7 #include "tao/Policy_ManagerC.h"
8 #include "tao/Policy_CurrentC.h"
10 static const ACE_TCHAR *ior = ACE_TEXT("file://simple_servant.ior");
11 static int iterations = 1;
12 static int corba_priority = RTCORBA::minPriority;
13 static int shutdown_server = 0;
15 enum Priority_Level
17 OBJECT,
18 THREAD,
19 ORB
22 void
23 change_network_priority (int enable_network_priority,
24 Priority_Level level,
25 Test_var &server,
26 CORBA::ORB_ptr orb)
28 try
30 CORBA::Object_var object =
31 orb->resolve_initial_references ("RTORB");
33 RTCORBA::RTORB_var rt_orb =
34 RTCORBA::RTORB::_narrow (object.in ());
36 // Set the tcp protocol properties
37 RTCORBA::TCPProtocolProperties_var tcp_properties =
38 rt_orb->create_tcp_protocol_properties (ACE_DEFAULT_MAX_SOCKET_BUFSIZ,
39 ACE_DEFAULT_MAX_SOCKET_BUFSIZ,
43 enable_network_priority);
45 RTCORBA::ProtocolList protocols;
46 protocols.length (1);
47 protocols[0].protocol_type = 0;
48 protocols[0].transport_protocol_properties =
49 RTCORBA::ProtocolProperties::_duplicate (tcp_properties.in ());
50 protocols[0].orb_protocol_properties =
51 RTCORBA::ProtocolProperties::_nil ();
53 CORBA::PolicyList policy_list;
54 policy_list.length (1);
55 policy_list[0] =
56 rt_orb->create_client_protocol_policy (protocols);
58 switch (level)
60 // Change policy at ORB level
61 case ORB:
63 object = orb->resolve_initial_references ("ORBPolicyManager");
65 CORBA::PolicyManager_var policy_manager =
66 CORBA::PolicyManager::_narrow (object.in ());
68 policy_manager->set_policy_overrides (policy_list,
69 CORBA::SET_OVERRIDE);
71 break;
74 // Change policy at THREAD level
75 case THREAD:
77 object =
78 orb->resolve_initial_references ("PolicyCurrent");
80 CORBA::PolicyCurrent_var policy_current =
81 CORBA::PolicyCurrent::_narrow (object.in ());
83 policy_current->set_policy_overrides (policy_list,
84 CORBA::SET_OVERRIDE);
86 break;
89 // Change policy at OBJECT level
90 case OBJECT:
92 CORBA::Object_var object = server->_set_policy_overrides (policy_list,
93 CORBA::SET_OVERRIDE);
95 server = Test::_narrow (object.in ());
97 break;
101 catch (const CORBA::Exception& ex)
103 ex._tao_print_exception ("Caught exception:");
108 parse_args (int argc, ACE_TCHAR *argv[])
110 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:n:p:x:"));
111 int c;
113 while ((c = get_opts ()) != -1)
114 switch (c)
116 case 'k':
117 ior = get_opts.opt_arg ();
118 break;
120 // number of itarations
121 case 'n':
122 iterations = ACE_OS::atoi (get_opts.opt_arg ());
123 break;
125 // corba priority
126 case 'p':
127 corba_priority = ACE_OS::atoi (get_opts.opt_arg ());
128 break;
130 // shutdown server
131 case 'x':
132 shutdown_server = ACE_OS::atoi (get_opts.opt_arg ());
133 break;
135 default:
136 ACE_ERROR_RETURN ((LM_ERROR,
137 "usage: %s\n"
138 "\t-k <ior> [default is %s]\n"
139 "\t-n <number of invocations> [defaults to %d]\n"
140 "\t-p <corba priority> [defaults to %d]\n"
141 "\t-x <shutdown server> [defaults to %d]\n"
142 "\n",
143 argv [0],
144 ior,
145 iterations,
146 corba_priority,
147 shutdown_server),
148 -1);
151 return 0;
154 void
155 toggle (int &i)
157 if (i == 0)
158 i = 1;
159 else i = 0;
163 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
167 CORBA::ORB_var orb =
168 CORBA::ORB_init (argc, argv);
170 if (parse_args (argc, argv) != 0)
171 return -1;
173 // Initialize and obtain reference to the Test object.
174 CORBA::Object_var client_object =
175 orb->string_to_object (ior);
177 Test_var server =
178 Test::_narrow (client_object.in ());
180 // Resolve the Network priority Mapping Manager
181 CORBA::Object_var object =
182 orb->resolve_initial_references ("NetworkPriorityMappingManager");
184 RTCORBA::NetworkPriorityMappingManager_var mapping_manager =
185 RTCORBA::NetworkPriorityMappingManager::_narrow (object.in ());
187 // Initialize the custom priority mapping
188 Custom_Network_Priority_Mapping *cnpm = 0;
189 ACE_NEW_RETURN (cnpm,
190 Custom_Network_Priority_Mapping,
191 -1);
193 // Set the desired corba priority on the network mapping manager
194 cnpm->corba_priority (corba_priority);
196 // Load the custom network priority mapping object in the
197 // network priority mapping manager. The user can thus add his
198 // own priority mapping.
199 mapping_manager->mapping (cnpm);
201 int enable_network_priority = 1;
203 // Make several invocation,
204 for (int i = 0; i < iterations; ++i)
206 toggle (enable_network_priority);
208 switch (i)
210 case 0:
211 case 1:
212 change_network_priority (enable_network_priority, ORB, server, orb.in ());
213 break;
214 case 2:
215 case 3:
216 change_network_priority (enable_network_priority, THREAD, server, orb.in ());
217 break;
218 default:
219 change_network_priority (enable_network_priority, OBJECT, server, orb.in ());
220 break;
223 server->test_method ();
226 // Shut down Server ORB.
227 if (shutdown_server)
229 server->shutdown ();
232 catch (const CORBA::Exception& ex)
234 ex._tao_print_exception ("Caught exception:");
235 return -1;
238 return 0;