1 #include "ace/Read_Buffer.h"
2 #include "ace/Array_Base.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "ace/OS_NS_math.h"
5 #include "ace/OS_NS_stdlib.h"
7 typedef ACE_Array_Base
<CORBA::ULong
> ULong_Array
;
10 get_priority_bands (const char *test_type
,
11 const ACE_TCHAR
*bands_file
,
12 RTCORBA::RTORB_ptr rt_orb
,
13 CORBA::PolicyList
&policies
,
17 // Read bands from a file.
20 ACE_OS::fopen (bands_file
, "r");
23 ACE_ERROR_RETURN ((LM_ERROR
,
24 "Cannot open file %s\n",
28 ACE_Read_Buffer
reader (file
, 1);
31 reader
.read (EOF
, ' ', '\0');
33 // Check for empty bands file.
38 "\n%s: No bands set!\n\n",
43 CORBA::ULong bands_length
=
44 (reader
.replaced () + 1) / 2;
46 RTCORBA::PriorityBands bands
;
47 bands
.length (bands_length
);
51 "\n%s: There are %d bands: ",
56 char* working_string
= string
;
57 for (CORBA::ULong i
= 0; i
< bands_length
; ++i
)
59 result
= ::sscanf (working_string
,
62 if (result
== 0 || result
== EOF
)
65 working_string
+= ACE_OS::strlen (working_string
);
68 result
= ::sscanf (working_string
,
71 if (result
== 0 || result
== EOF
)
74 working_string
+= ACE_OS::strlen (working_string
);
84 reader
.alloc ()->free (string
);
86 if (result
== 0 || result
== EOF
)
87 ACE_ERROR_RETURN ((LM_ERROR
,
88 "Parsing error in file %s\n",
96 CORBA::Policy_var banded_connection_policy
=
97 rt_orb
->create_priority_banded_connection_policy (bands
);
99 policies
.length (policies
.length () + 1);
100 policies
[policies
.length () - 1] =
101 banded_connection_policy
;
107 get_values (const char *test_type
,
108 const ACE_TCHAR
*file_name
,
114 // Read lanes from a file.
117 ACE_OS::fopen (file_name
, "r");
120 ACE_ERROR_RETURN ((LM_ERROR
,
121 "Cannot open file %s\n",
125 ACE_Read_Buffer
reader (file
, 1);
128 reader
.read (EOF
, ' ', '\0');
130 // Check for empty lanes file.
134 ACE_DEBUG ((LM_DEBUG
,
135 "\n%s: No %s set!\n\n",
142 reader
.replaced () + 1;
144 values
.size (length
);
147 ACE_DEBUG ((LM_DEBUG
,
148 "\n%s: There are %d %s: ",
154 char* working_string
= string
;
155 for (CORBA::ULong i
= 0; i
< length
; ++i
)
157 // sscanf with "%ul" doesn't seem to work properly on HP-UX. So,
158 // we will use strtoul instead.
160 values
[i
] = ACE_OS::strtoul (working_string
, &endptr
, 10);
162 if (endptr
!= working_string
&& endptr
!= 0 && *endptr
!= '\0')
168 working_string
+= ACE_OS::strlen (working_string
);
172 ACE_DEBUG ((LM_DEBUG
,
177 reader
.alloc ()->free (string
);
179 if (result
== 0 || result
== EOF
)
180 ACE_ERROR_RETURN ((LM_ERROR
,
181 "Parsing error in file %s\n",
186 ACE_DEBUG ((LM_DEBUG
,
193 get_priority_lanes (const char *test_type
,
194 const ACE_TCHAR
*lanes_file
,
195 RTCORBA::RTORB_ptr rt_orb
,
196 CORBA::ULong stacksize
,
197 CORBA::ULong static_threads
,
198 CORBA::ULong dynamic_threads
,
199 CORBA::Boolean allow_request_buffering
,
200 CORBA::ULong max_buffered_requests
,
201 CORBA::ULong max_request_buffer_size
,
202 CORBA::Boolean allow_borrowing
,
203 CORBA::PolicyList
&policies
,
206 ULong_Array priorities
;
208 get_values (test_type
,
214 priorities
.size () == 0)
217 RTCORBA::ThreadpoolLanes lanes
;
218 lanes
.length (priorities
.size ());
220 for (CORBA::ULong i
= 0;
221 i
< priorities
.size ();
224 lanes
[i
].lane_priority
= priorities
[i
];
225 lanes
[i
].static_threads
= static_threads
;
226 lanes
[i
].dynamic_threads
= dynamic_threads
;
229 RTCORBA::ThreadpoolId threadpool_id
=
230 rt_orb
->create_threadpool_with_lanes (stacksize
,
233 allow_request_buffering
,
234 max_buffered_requests
,
235 max_request_buffer_size
);
237 CORBA::Policy_var threadpool_policy
=
238 rt_orb
->create_threadpool_policy (threadpool_id
);
240 policies
.length (policies
.length () + 1);
241 policies
[policies
.length () - 1] =
248 get_protocols (const char *test_type
,
249 const ACE_TCHAR
*lanes_file
,
250 RTCORBA::RTORB_ptr rt_orb
,
251 CORBA::PolicyList
&policies
,
254 ULong_Array protocol_values
;
256 get_values (test_type
,
262 protocol_values
.size () == 0)
265 RTCORBA::ProtocolList protocols
;
266 protocols
.length (protocol_values
.size ());
268 for (CORBA::ULong i
= 0;
269 i
< protocol_values
.size ();
272 protocols
[i
].protocol_type
=
274 protocols
[i
].transport_protocol_properties
=
275 RTCORBA::ProtocolProperties::_nil ();
276 protocols
[i
].orb_protocol_properties
=
277 RTCORBA::ProtocolProperties::_nil ();
280 CORBA::Policy_var protocol_policy
=
281 rt_orb
->create_client_protocol_policy (protocols
);
283 policies
.length (policies
.length () + 1);
284 policies
[policies
.length () - 1] =
291 get_auto_priority_lanes_and_bands (CORBA::ULong number_of_lanes
,
292 RTCORBA::RTORB_ptr rt_orb
,
293 CORBA::ULong stacksize
,
294 CORBA::ULong static_threads
,
295 CORBA::ULong dynamic_threads
,
296 CORBA::Boolean allow_request_buffering
,
297 CORBA::ULong max_buffered_requests
,
298 CORBA::ULong max_request_buffer_size
,
299 CORBA::Boolean allow_borrowing
,
300 CORBA::PolicyList
&policies
,
303 RTCORBA::ThreadpoolLanes lanes
;
304 lanes
.length (number_of_lanes
);
306 RTCORBA::PriorityBands bands
;
307 bands
.length (number_of_lanes
);
309 CORBA::Short priority_range
=
310 RTCORBA::maxPriority
- RTCORBA::minPriority
;
313 ACE_DEBUG ((LM_DEBUG
,
314 "\nUsing %d lanes\n",
317 for (CORBA::ULong i
= 0;
321 CORBA::Short high_priority
=
323 ACE_OS::floor ((priority_range
/
324 double (number_of_lanes
)) *
327 CORBA::Short low_priority
=
329 ACE_OS::ceil ((priority_range
/
330 double (number_of_lanes
)) *
333 lanes
[i
].lane_priority
= high_priority
;
334 lanes
[i
].static_threads
= static_threads
;
335 lanes
[i
].dynamic_threads
= dynamic_threads
;
337 bands
[i
].high
= high_priority
;
338 bands
[i
].low
= low_priority
;
341 ACE_DEBUG ((LM_DEBUG
,
349 ACE_DEBUG ((LM_DEBUG
,
352 RTCORBA::ThreadpoolId threadpool_id
=
353 rt_orb
->create_threadpool_with_lanes (stacksize
,
356 allow_request_buffering
,
357 max_buffered_requests
,
358 max_request_buffer_size
);
360 policies
.length (policies
.length () + 1);
361 policies
[policies
.length () - 1] =
362 rt_orb
->create_priority_banded_connection_policy (bands
);
364 policies
.length (policies
.length () + 1);
365 policies
[policies
.length () - 1] =
366 rt_orb
->create_threadpool_policy (threadpool_id
);