1 #include "ace/Get_Opt.h"
2 #include "tao/ORB_Core.h"
3 #include "tao/RTCORBA/Thread_Pool.h"
4 #include "tao/RTPortableServer/RTPortableServer.h"
5 #include "tao/Strategies/advanced_resource.h"
6 #include "../check_supported_priorities.cpp"
7 #include "../common_args.cpp"
10 static CORBA::ULong stacksize
= 0;
11 static CORBA::ULong static_threads
= 2;
12 static CORBA::ULong dynamic_threads
= 0;
13 static CORBA::Boolean allow_request_buffering
= 0;
14 static CORBA::ULong max_buffered_requests
= 0;
15 static CORBA::ULong max_request_buffer_size
= 0;
16 static CORBA::Boolean allow_borrowing
= 0;
19 static int ior_file_count
= 1;
20 static const ACE_TCHAR
*ior_file_base
= ACE_TEXT ("ior");
21 static const ACE_TCHAR
*bands_file
= ACE_TEXT ("empty_file");
22 static const ACE_TCHAR
*lanes_file
= ACE_TEXT ("empty_file");
28 test_i (CORBA::ORB_ptr orb
,
29 PortableServer::POA_ptr poa
);
33 //FUZZ: disable check_for_lack_ACE_OS
35 //FUZZ: enable check_for_lack_ACE_OS
37 PortableServer::POA_ptr
_default_POA (void);
42 PortableServer::POA_var poa_
;
45 test_i::test_i (CORBA::ORB_ptr orb
,
46 PortableServer::POA_ptr poa
)
47 : orb_ (CORBA::ORB::_duplicate (orb
)),
48 poa_ (PortableServer::POA::_duplicate (poa
))
55 // Get the ORB_Core's TSS resources.
56 TAO_ORB_Core_TSS_Resources
*tss
=
57 this->orb_
->orb_core ()->get_tss_resources ();
59 /// Get the lane attribute in TSS.
60 TAO_Thread_Lane
*lane
=
61 (TAO_Thread_Lane
*) tss
->lane_
;
67 "test_i::method request in thread %t (pool id = %d; lane id = %d)\n",
72 "test_i::method request in thread %t (default thread pool)\n"));
77 test_i::shutdown (void)
81 "test_i::shutdown\n"));
83 this->orb_
->shutdown (false);
86 PortableServer::POA_ptr
87 test_i::_default_POA (void)
89 return PortableServer::POA::_duplicate (this->poa_
.in ());
93 parse_args (int argc
, ACE_TCHAR
**argv
)
95 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("b:d:l:o:"));
98 while ((c
= get_opts ()) != -1)
102 bands_file
= get_opts
.opt_arg ();
106 debug
= ACE_OS::atoi (get_opts
.opt_arg ());
110 lanes_file
= get_opts
.opt_arg ();
114 ior_file_base
= get_opts
.opt_arg ();
119 ACE_ERROR_RETURN ((LM_ERROR
,
121 "\t-b <bands file> (defaults to %s)\n"
122 "\t-b <lanes file> (defaults to %s)\n"
123 "\t-o <ior file base> (defaults to %s)\n"
136 write_iors_to_file (CORBA::Object_ptr object
,
139 char filename
[BUFSIZ
];
140 ACE_OS::sprintf (filename
,
142 ACE_TEXT_ALWAYS_CHAR (ior_file_base
),
147 ACE_OS::fopen (filename
, "w");
148 ACE_ASSERT (file
!= 0);
150 CORBA::String_var ior
=
151 orb
->object_to_string (object
);
155 ACE_OS::fprintf (file
,
159 ACE_ASSERT (result
== ACE_OS::strlen (ior
.in ()));
160 ACE_UNUSED_ARG (result
);
162 ACE_OS::fclose (file
);
166 vanilla_poa (CORBA::ORB_ptr orb
,
167 PortableServer::POA_ptr root_poa
,
168 PortableServer::POAManager_ptr poa_manager
)
170 CORBA::PolicyList policies
;
172 CORBA::Policy_var implicit_activation_policy
=
173 root_poa
->create_implicit_activation_policy (PortableServer::IMPLICIT_ACTIVATION
);
175 policies
.length (policies
.length () + 1);
176 policies
[policies
.length () - 1] =
177 implicit_activation_policy
;
179 PortableServer::POA_var poa
=
180 root_poa
->create_POA ("child",
185 ACE_NEW_THROW_EX (servant
,
188 CORBA::NO_MEMORY ());
190 PortableServer::ServantBase_var
safe_servant (servant
);
192 PortableServer::ObjectId_var id_act
=
193 poa
->activate_object (servant
);
195 CORBA::Object_var object
= poa
->id_to_reference (id_act
.in ());
198 test::_narrow (object
.in ());
200 write_iors_to_file (test
.in (),
205 rt_poa (CORBA::ORB_ptr orb
,
206 RTCORBA::RTORB_ptr rt_orb
,
207 PortableServer::POA_ptr root_poa
,
208 PortableServer::POAManager_ptr poa_manager
)
210 CORBA::PolicyList policies
;
213 get_priority_bands ("server",
220 ACE_ERROR ((LM_ERROR
,
221 "Error in parsing bands data file: %s\n",
227 get_priority_lanes ("server",
233 allow_request_buffering
,
234 max_buffered_requests
,
235 max_request_buffer_size
,
241 ACE_ERROR ((LM_ERROR
,
242 "Error in parsing lanes data file: %s\n",
247 CORBA::Policy_var priority_model_policy
=
248 rt_orb
->create_priority_model_policy (RTCORBA::CLIENT_PROPAGATED
,
251 // Implicit_activation policy.
252 CORBA::Policy_var implicit_activation_policy
=
253 root_poa
->create_implicit_activation_policy (PortableServer::IMPLICIT_ACTIVATION
);
255 policies
.length (policies
.length () + 1);
256 policies
[policies
.length () - 1] =
257 priority_model_policy
;
259 policies
.length (policies
.length () + 1);
260 policies
[policies
.length () - 1] =
261 implicit_activation_policy
;
263 PortableServer::POA_var poa
=
264 root_poa
->create_POA ("rt_poa",
269 ACE_NEW_THROW_EX (servant
,
272 CORBA::NO_MEMORY ());
274 PortableServer::ServantBase_var
safe_servant (servant
);
276 PortableServer::ObjectId_var id_act
=
277 poa
->activate_object (servant
);
279 CORBA::Object_var object
= poa
->id_to_reference (id_act
.in ());
282 test::_narrow (object
.in ());
284 write_iors_to_file (test
.in (),
288 class Task
: public ACE_Task_Base
292 Task (ACE_Thread_Manager
&thread_manager
,
301 Task::Task (ACE_Thread_Manager
&thread_manager
,
303 : ACE_Task_Base (&thread_manager
),
304 orb_ (CORBA::ORB::_duplicate (orb
))
313 CORBA::Object_var object
=
314 this->orb_
->resolve_initial_references ("RTORB");
316 RTCORBA::RTORB_var rt_orb
=
317 RTCORBA::RTORB::_narrow (object
.in ());
320 this->orb_
->resolve_initial_references ("RootPOA");
322 PortableServer::POA_var root_poa
=
323 PortableServer::POA::_narrow (object
.in ());
325 PortableServer::POAManager_var poa_manager
=
326 root_poa
->the_POAManager ();
328 vanilla_poa (this->orb_
.in (),
332 rt_poa (this->orb_
.in (),
337 poa_manager
->activate ();
341 this->orb_
->destroy ();
343 catch (const CORBA::Exception
& ex
)
345 ex
._tao_print_exception ("Exception caught");
353 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
358 CORBA::ORB_init (argc
, argv
);
361 parse_args (argc
, argv
);
365 // Make sure we can support multiple priorities that are required
367 if (!check_supported_priorities (orb
.in ()))
370 // Thread Manager for managing task.
371 ACE_Thread_Manager thread_manager
;
374 Task
task (thread_manager
,
377 // Task activation flags.
381 orb
->orb_core ()->orb_params ()->thread_creation_flags ();
385 task
.activate (flags
);
390 ACE_ERROR_RETURN ((LM_ERROR
,
391 "Cannot create thread with scheduling policy %C\n"
392 "because the user does not have the appropriate privileges, terminating program....\n"
393 "Check svc.conf options and/or run as root\n",
394 sched_policy_name (orb
->orb_core ()->orb_params ()->ace_sched_policy ())),
402 // Wait for task to exit.
404 thread_manager
.wait ();
405 ACE_ASSERT (result
!= -1);
407 catch (const CORBA::Exception
& ex
)
409 ex
._tao_print_exception ("Exception caught");