2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_unistd.h"
4 #include "tao/ORB_Core.h"
6 #include "tao/RTPortableServer/RTPortableServer.h"
7 #include "../check_supported_priorities.cpp"
9 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("ior");
11 CORBA::ULong static_threads
= 1;
12 CORBA::ULong dynamic_threads
= 25;
16 parse_args (int argc
, ACE_TCHAR
*argv
[])
18 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:s:d:t:h"));
21 while ((c
= get_opts ()) != -1)
25 ior_output_file
= get_opts
.opt_arg ();
29 static_threads
= ACE_OS::atoi (get_opts
.opt_arg ());
33 dynamic_threads
= ACE_OS::atoi (get_opts
.opt_arg ());
37 nap_time
= ACE_OS::atoi (get_opts
.opt_arg ());
41 ACE_ERROR_RETURN ((LM_ERROR
,
44 "-s <static_threads> "
45 "-d <dynamic_threads> "
52 // Indicates successful parsing of the command line
57 write_ior_to_file (CORBA::ORB_ptr orb
,
60 CORBA::String_var ior
=
61 orb
->object_to_string (test
);
63 char filename
[BUFSIZ
];
64 ACE_OS::sprintf (filename
,
66 ACE_TEXT_ALWAYS_CHAR (ior_output_file
),
70 ACE_OS::fopen (filename
,
74 ACE_ERROR_RETURN ((LM_ERROR
,
75 "Cannot open output file for writing IOR: %s",
79 ACE_OS::fprintf (output_file
,
83 ACE_OS::fclose (output_file
);
89 create_POA_and_register_servant (CORBA::Policy_ptr threadpool_policy
,
91 PortableServer::POAManager_ptr poa_manager
,
92 PortableServer::POA_ptr root_poa
,
94 RTCORBA::RTORB_ptr rt_orb
)
96 // Policies for the firstPOA to be created.
97 CORBA::PolicyList
policies (3); policies
.length (3);
99 // Implicit_activation policy.
101 root_poa
->create_implicit_activation_policy
102 (PortableServer::IMPLICIT_ACTIVATION
);
104 // Thread pool policy.
106 CORBA::Policy::_duplicate (threadpool_policy
);
108 // Priority Model policy.
110 rt_orb
->create_priority_model_policy (RTCORBA::CLIENT_PROPAGATED
,
113 // Create the POA under the RootPOA.
114 PortableServer::POA_var poa
=
115 root_poa
->create_POA (poa_name
,
119 // Creation of POAs is over. Destroy the Policy objects.
120 for (CORBA::ULong i
= 0;
121 i
< policies
.length ();
124 policies
[i
]->destroy ();
132 PortableServer::ServantBase_var
safe_servant (servant
);
133 ACE_UNUSED_ARG (safe_servant
);
135 PortableServer::ObjectId_var id
=
136 poa
->activate_object (servant
);
138 CORBA::Object_var object
= poa
->id_to_reference (id
.in ());
141 test::_narrow (object
.in ());
144 write_ior_to_file (orb
,
150 class Task
: public ACE_Task_Base
154 Task (ACE_Thread_Manager
&thread_manager
,
163 Task::Task (ACE_Thread_Manager
&thread_manager
,
165 : ACE_Task_Base (&thread_manager
),
166 orb_ (CORBA::ORB::_duplicate (orb
))
175 CORBA::Object_var object
=
176 this->orb_
->resolve_initial_references ("RootPOA");
178 PortableServer::POA_var root_poa
=
179 PortableServer::POA::_narrow (object
.in ());
181 PortableServer::POAManager_var poa_manager
=
182 root_poa
->the_POAManager ();
185 this->orb_
->resolve_initial_references ("RTORB");
187 RTCORBA::RTORB_var rt_orb
=
188 RTCORBA::RTORB::_narrow (object
.in ());
191 this->orb_
->resolve_initial_references ("RTCurrent");
193 RTCORBA::Current_var current
=
194 RTCORBA::Current::_narrow (object
.in ());
196 RTCORBA::Priority default_thread_priority
=
197 get_implicit_thread_CORBA_priority (this->orb_
.in ());
199 test_i
servant (this->orb_
.in (),
202 PortableServer::ObjectId_var id
=
203 root_poa
->activate_object (&servant
);
205 CORBA::Object_var object_act
= root_poa
->id_to_reference (id
.in ());
208 test::_narrow (object_act
.in ());
211 write_ior_to_file (this->orb_
.in (),
217 poa_manager
->activate ();
219 CORBA::ULong stacksize
= 0;
220 CORBA::Boolean allow_request_buffering
= 0;
221 CORBA::ULong max_buffered_requests
= 0;
222 CORBA::ULong max_request_buffer_size
= 0;
224 RTCORBA::ThreadpoolId threadpool_id_1
=
225 rt_orb
->create_threadpool (stacksize
,
228 default_thread_priority
,
229 allow_request_buffering
,
230 max_buffered_requests
,
231 max_request_buffer_size
);
233 CORBA::Policy_var threadpool_policy_1
=
234 rt_orb
->create_threadpool_policy (threadpool_id_1
);
236 CORBA::Boolean allow_borrowing
= 0;
237 RTCORBA::ThreadpoolLanes
lanes (1);
240 lanes
[0].lane_priority
= default_thread_priority
;
241 lanes
[0].static_threads
= static_threads
;
242 lanes
[0].dynamic_threads
= dynamic_threads
;
244 RTCORBA::ThreadpoolId threadpool_id_2
=
245 rt_orb
->create_threadpool_with_lanes (stacksize
,
248 allow_request_buffering
,
249 max_buffered_requests
,
250 max_request_buffer_size
);
252 CORBA::Policy_var threadpool_policy_2
=
253 rt_orb
->create_threadpool_policy (threadpool_id_2
);
256 create_POA_and_register_servant (threadpool_policy_1
.in (),
266 create_POA_and_register_servant (threadpool_policy_2
.in (),
277 this->orb_
->destroy ();
279 catch (const CORBA::Exception
& ex
)
281 ex
._tao_print_exception ("Exception caught:");
289 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
294 CORBA::ORB_init (argc
, argv
);
297 parse_args (argc
, argv
);
301 // Make sure we can support multiple priorities that are required
303 if (!check_supported_priorities (orb
.in ()))
306 // Thread Manager for managing task.
307 ACE_Thread_Manager thread_manager
;
310 Task
task (thread_manager
,
313 // Task activation flags.
317 orb
->orb_core ()->orb_params ()->thread_creation_flags ();
321 task
.activate (flags
);
326 ACE_ERROR_RETURN ((LM_ERROR
,
327 "Cannot create thread with scheduling policy %s\n"
328 "because the user does not have the appropriate privileges, terminating program....\n"
329 "Check svc.conf options and/or run as root\n",
330 sched_policy_name (orb
->orb_core ()->orb_params ()->ace_sched_policy ())),
338 // Wait for task to exit.
340 thread_manager
.wait ();
341 ACE_ASSERT (result
!= -1);
343 catch (const CORBA::Exception
& ex
)
345 ex
._tao_print_exception ("Exception caught");