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;
23 change_network_priority (int enable_network_priority
,
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
;
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);
56 rt_orb
->create_client_protocol_policy (protocols
);
60 // Change policy at ORB level
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
,
74 // Change policy at THREAD level
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
,
89 // Change policy at OBJECT level
92 CORBA::Object_var object
= server
->_set_policy_overrides (policy_list
,
95 server
= Test::_narrow (object
.in ());
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:"));
113 while ((c
= get_opts ()) != -1)
117 ior
= get_opts
.opt_arg ();
120 // number of itarations
122 iterations
= ACE_OS::atoi (get_opts
.opt_arg ());
127 corba_priority
= ACE_OS::atoi (get_opts
.opt_arg ());
132 shutdown_server
= ACE_OS::atoi (get_opts
.opt_arg ());
136 ACE_ERROR_RETURN ((LM_ERROR
,
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"
163 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
168 CORBA::ORB_init (argc
, argv
);
170 if (parse_args (argc
, argv
) != 0)
173 // Initialize and obtain reference to the Test object.
174 CORBA::Object_var client_object
=
175 orb
->string_to_object (ior
);
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
,
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
);
212 change_network_priority (enable_network_priority
, ORB
, server
, orb
.in ());
216 change_network_priority (enable_network_priority
, THREAD
, server
, orb
.in ());
219 change_network_priority (enable_network_priority
, OBJECT
, server
, orb
.in ());
223 server
->test_method ();
226 // Shut down Server ORB.
232 catch (const CORBA::Exception
& ex
)
234 ex
._tao_print_exception ("Caught exception:");