1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
// $Id$
#include "testC.h"
#include "tao/RTCORBA/RTCORBA.h"
#include "tao/RTCORBA/Network_Priority_Mapping_Manager.h"
#include "tao/RTCORBA/Network_Priority_Mapping.h"
#include "Custom_Network_Priority_Mapping.h"
#include "ace/Get_Opt.h"
#include "tao/Policy_ManagerC.h"
#include "tao/Policy_CurrentC.h"
static const char *ior = "file://simple_servant.ior";
static int iterations = 1;
static int corba_priority = RTCORBA::minPriority;
static int shutdown_server = 0;
enum Priority_Level
{
OBJECT,
THREAD,
ORB
};
void
change_network_priority (int enable_network_priority,
Priority_Level level,
Test_var &server,
CORBA::ORB_ptr orb)
{
try
{
CORBA::Object_var object =
orb->resolve_initial_references ("RTORB");
RTCORBA::RTORB_var rt_orb =
RTCORBA::RTORB::_narrow (object.in ());
// Set the tcp protocol properties
RTCORBA::TCPProtocolProperties_var tcp_properties =
rt_orb->create_tcp_protocol_properties (ACE_DEFAULT_MAX_SOCKET_BUFSIZ,
ACE_DEFAULT_MAX_SOCKET_BUFSIZ,
1,
0,
1,
enable_network_priority);
RTCORBA::ProtocolList protocols;
protocols.length (1);
protocols[0].protocol_type = 0;
protocols[0].transport_protocol_properties =
RTCORBA::ProtocolProperties::_duplicate (tcp_properties.in ());
protocols[0].orb_protocol_properties =
RTCORBA::ProtocolProperties::_nil ();
CORBA::PolicyList policy_list;
policy_list.length (1);
policy_list[0] =
rt_orb->create_client_protocol_policy (protocols);
switch (level)
{
// Change policy at ORB level
case ORB:
{
object = orb->resolve_initial_references ("ORBPolicyManager");
CORBA::PolicyManager_var policy_manager =
CORBA::PolicyManager::_narrow (object.in ());
policy_manager->set_policy_overrides (policy_list,
CORBA::SET_OVERRIDE);
break;
}
// Change policy at THREAD level
case THREAD:
{
object =
orb->resolve_initial_references ("PolicyCurrent");
CORBA::PolicyCurrent_var policy_current =
CORBA::PolicyCurrent::_narrow (object.in ());
policy_current->set_policy_overrides (policy_list,
CORBA::SET_OVERRIDE);
break;
}
// Change policy at OBJECT level
case OBJECT:
{
CORBA::Object_var object = server->_set_policy_overrides (policy_list,
CORBA::SET_OVERRIDE);
server = Test::_narrow (object.in ());
break;
}
}
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception ("Caught exception:");
}
}
int
parse_args (int argc, char *argv[])
{
ACE_Get_Opt get_opts (argc, argv, "k:n:p:x:");
int c;
while ((c = get_opts ()) != -1)
switch (c)
{
case 'k':
ior = get_opts.opt_arg ();
break;
// number of itarations
case 'n':
iterations = ACE_OS::atoi (get_opts.opt_arg ());
break;
// corba priority
case 'p':
corba_priority = ACE_OS::atoi (get_opts.opt_arg ());
break;
// shutdown server
case 'x':
shutdown_server = ACE_OS::atoi (get_opts.opt_arg ());
break;
default:
ACE_ERROR_RETURN ((LM_ERROR,
"usage: %s\n"
"\t-k <ior> [default is %s]\n"
"\t-n <number of invocations> [defaults to %d]\n"
"\t-p <corba priority> [defaults to %d]\n"
"\t-x <shutdown server> [defaults to %d]\n"
"\n",
argv [0],
ior,
iterations,
corba_priority,
shutdown_server),
-1);
}
return 0;
}
void
toggle (int &i)
{
if (i == 0)
i = 1;
else i = 0;
}
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
try
{
CORBA::ORB_var orb =
CORBA::ORB_init (argc, argv);
if (parse_args (argc, argv) != 0)
return -1;
// Initialize and obtain reference to the Test object.
CORBA::Object_var client_object =
orb->string_to_object (ior);
Test_var server =
Test::_narrow (client_object.in ());
// Resolve the Network priority Mapping Manager
CORBA::Object_var object =
orb->resolve_initial_references ("NetworkPriorityMappingManager");
RTCORBA::NetworkPriorityMappingManager_var mapping_manager =
RTCORBA::NetworkPriorityMappingManager::_narrow (object.in ());
// Initialize the custom priority mapping
Custom_Network_Priority_Mapping *cnpm = 0;
ACE_NEW_RETURN (cnpm,
Custom_Network_Priority_Mapping,
-1);
// Set the desired corba priority on the network mapping manager
cnpm->corba_priority (corba_priority);
// Load the custom network priority mapping object in the
// network priority mapping manager. The user can thus add his
// own priority mapping.
mapping_manager->mapping (cnpm);
int enable_network_priority = 1;
// Make several invocation,
for (int i = 0; i < iterations; ++i)
{
toggle (enable_network_priority);
switch (i)
{
case 0:
case 1:
change_network_priority (enable_network_priority, ORB, server, orb.in ());
break;
case 2:
case 3:
change_network_priority (enable_network_priority, THREAD, server, orb.in ());
break;
default:
change_network_priority (enable_network_priority, OBJECT, server, orb.in ());
break;
}
server->test_method ();
}
// Shut down Server ORB.
if (shutdown_server)
{
server->shutdown ();
}
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception ("Caught exception:");
return -1;
}
return 0;
}
|