1 #include "ace/Get_Opt.h"
4 #include "ace/Sample_History.h"
5 #include "tao/ORB_Core.h"
7 #include "tao/RTPortableServer/RTPortableServer.h"
9 #include "tests/RTCORBA/common_args.cpp"
10 #include "tests/RTCORBA/check_supported_priorities.cpp"
16 test_i (CORBA::ORB_ptr orb
,
17 PortableServer::POA_ptr poa
);
19 void method (CORBA::ULong work
,
20 CORBA::ULong prime_number
);
22 //FUZZ: disable check_for_lack_ACE_OS
24 //FUZZ: enable check_for_lack_ACE_OS
26 PortableServer::POA_ptr
_default_POA ();
30 PortableServer::POA_var poa_
;
33 test_i::test_i (CORBA::ORB_ptr orb
,
34 PortableServer::POA_ptr poa
)
35 : orb_ (CORBA::ORB::_duplicate (orb
)),
36 poa_ (PortableServer::POA::_duplicate (poa
))
41 test_i::method (CORBA::ULong work
,
42 CORBA::ULong prime_number
)
44 if (TAO_debug_level
> 0)
46 "test_i::method: %hd units of work\n",
49 for (; work
!= 0; work
--)
50 ACE::is_prime (prime_number
,
55 PortableServer::POA_ptr
56 test_i::_default_POA ()
58 return PortableServer::POA::_duplicate (this->poa_
.in ());
64 this->orb_
->shutdown (false);
67 static const ACE_TCHAR
*ior_output_file
= ACE_TEXT("ior");
68 static CORBA::ULong static_threads
= 1;
69 static CORBA::ULong dynamic_threads
= 0;
70 static CORBA::ULong number_of_lanes
= 0;
71 static RTCORBA::Priority default_thread_priority
= 0;
72 static RTCORBA::Priority pool_priority
= ACE_INT16_MIN
;
74 static const ACE_TCHAR
*bands_file
= ACE_TEXT("empty-file");
75 static const ACE_TCHAR
*lanes_file
= ACE_TEXT("empty-file");
78 parse_args (int argc
, ACE_TCHAR
*argv
[])
80 ACE_Get_Opt
get_opts (argc
, argv
,
81 "b:f:hl:n:o:s:" // server options
82 "c:e:g:hi:j:k:m:p:q:r:t:u:v:w:x:y:z:" // client options
86 while ((c
= get_opts ()) != -1)
90 bands_file
= get_opts
.opt_arg ();
94 pool_priority
= ACE_OS::atoi (get_opts
.opt_arg ());
98 lanes_file
= get_opts
.opt_arg ();
102 number_of_lanes
= ACE_OS::atoi (get_opts
.opt_arg ());
106 ior_output_file
= get_opts
.opt_arg ();
110 static_threads
= ACE_OS::atoi (get_opts
.opt_arg ());
130 // client options: ignored.
136 ACE_ERROR_RETURN ((LM_ERROR
,
138 "\t-b <bands file> (defaults to %s)\n"
139 "\t-f <pool priority> (defaults to %d)\n"
140 "\t-h <help: shows options menu>\n"
141 "\t-l <lanes file> (defaults to %s)\n"
142 "\t-n <number of lanes> (defaults to %d)\n"
143 "\t-o <ior file> (defaults to %s)\n"
144 "\t-s <static threads> (defaults to %d)\n"
148 default_thread_priority
,
160 write_ior_to_file (const ACE_TCHAR
*ior_file
,
162 CORBA::Object_ptr object
)
164 CORBA::String_var ior
=
165 orb
->object_to_string (object
);
168 ACE_OS::fopen (ior_file
,
171 if (output_file
== 0)
172 ACE_ERROR_RETURN ((LM_ERROR
,
173 "Cannot open output file for writing IOR: %s",
177 ACE_OS::fprintf (output_file
,
181 ACE_OS::fclose (output_file
);
186 class Task
: public ACE_Task_Base
189 Task (ACE_Thread_Manager
&thread_manager
,
197 Task::Task (ACE_Thread_Manager
&thread_manager
,
199 : ACE_Task_Base (&thread_manager
),
200 orb_ (CORBA::ORB::_duplicate (orb
))
209 CORBA::Object_var object
=
210 this->orb_
->resolve_initial_references ("RootPOA");
212 PortableServer::POA_var root_poa
=
213 PortableServer::POA::_narrow (object
.in ());
215 PortableServer::POAManager_var poa_manager
=
216 root_poa
->the_POAManager ();
219 this->orb_
->resolve_initial_references ("RTORB");
221 RTCORBA::RTORB_var rt_orb
=
222 RTCORBA::RTORB::_narrow (object
.in ());
225 this->orb_
->resolve_initial_references ("RTCurrent");
227 RTCORBA::Current_var current
=
228 RTCORBA::Current::_narrow (object
.in ());
230 default_thread_priority
=
231 current
->the_priority ();
234 CORBA::ULong stacksize
= 0;
235 CORBA::Boolean allow_request_buffering
= 0;
236 CORBA::ULong max_buffered_requests
= 0;
237 CORBA::ULong max_request_buffer_size
= 0;
239 CORBA::PolicyList policies
;
241 CORBA::Boolean allow_borrowing
= 0;
242 if (number_of_lanes
!= 0)
244 get_auto_priority_lanes_and_bands (number_of_lanes
,
249 allow_request_buffering
,
250 max_buffered_requests
,
251 max_request_buffer_size
,
256 else if (ACE_OS::strcmp (lanes_file
, ACE_TEXT("empty-file")) != 0)
259 get_priority_lanes ("server",
265 allow_request_buffering
,
266 max_buffered_requests
,
267 max_request_buffer_size
,
276 get_priority_bands ("server",
287 if (pool_priority
== ACE_INT16_MIN
)
289 default_thread_priority
;
291 RTCORBA::ThreadpoolId threadpool_id
=
292 rt_orb
->create_threadpool (stacksize
,
296 allow_request_buffering
,
297 max_buffered_requests
,
298 max_request_buffer_size
);
300 policies
.length (policies
.length () + 1);
301 policies
[policies
.length () - 1] =
302 rt_orb
->create_threadpool_policy (threadpool_id
);
304 if (ACE_OS::strcmp (bands_file
, ACE_TEXT("empty-file")) != 0)
307 get_priority_bands ("server",
318 policies
.length (policies
.length () + 1);
319 policies
[policies
.length () - 1] =
320 root_poa
->create_implicit_activation_policy
321 (PortableServer::IMPLICIT_ACTIVATION
);
323 policies
.length (policies
.length () + 1);
324 policies
[policies
.length () - 1] =
325 rt_orb
->create_priority_model_policy (RTCORBA::CLIENT_PROPAGATED
,
326 default_thread_priority
);
328 PortableServer::POA_var poa
=
329 root_poa
->create_POA ("RT POA",
334 new test_i (this->orb_
.in (),
337 PortableServer::ServantBase_var
safe_servant (servant
);
338 ACE_UNUSED_ARG (safe_servant
);
344 write_ior_to_file (ior_output_file
,
351 poa_manager
->activate ();
355 this->orb_
->destroy ();
357 catch (const CORBA::Exception
& ex
)
359 ex
._tao_print_exception ("Exception caught:");
367 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
372 CORBA::ORB_init (argc
,
376 parse_args (argc
, argv
);
380 // Make sure we can support multiple priorities that are required
382 check_supported_priorities (orb
.in ());
384 // Thread Manager for managing task.
385 ACE_Thread_Manager thread_manager
;
388 Task
task (thread_manager
,
391 // Task activation flags.
395 orb
->orb_core ()->orb_params ()->thread_creation_flags ();
399 task
.activate (flags
);
400 ACE_ASSERT (result
!= -1);
401 ACE_UNUSED_ARG (result
);
403 // Wait for task to exit.
405 thread_manager
.wait ();
406 ACE_ASSERT (result
!= -1);
408 catch (const CORBA::Exception
& ex
)
410 ex
._tao_print_exception ("Exception caught:");