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 ();
41 PortableServer::POA_var poa_
;
44 test_i::test_i (CORBA::ORB_ptr orb
,
45 PortableServer::POA_ptr poa
)
46 : orb_ (CORBA::ORB::_duplicate (orb
)),
47 poa_ (PortableServer::POA::_duplicate (poa
))
54 // Get the ORB_Core's TSS resources.
55 TAO_ORB_Core_TSS_Resources
*tss
=
56 this->orb_
->orb_core ()->get_tss_resources ();
58 /// Get the lane attribute in TSS.
59 TAO_Thread_Lane
*lane
=
60 (TAO_Thread_Lane
*) tss
->lane_
;
66 "test_i::method request in thread %t (pool id = %d; lane id = %d)\n",
71 "test_i::method request in thread %t (default thread pool)\n"));
80 "test_i::shutdown\n"));
82 this->orb_
->shutdown (false);
85 PortableServer::POA_ptr
86 test_i::_default_POA ()
88 return PortableServer::POA::_duplicate (this->poa_
.in ());
92 parse_args (int argc
, ACE_TCHAR
**argv
)
94 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("b:d:l:o:"));
97 while ((c
= get_opts ()) != -1)
101 bands_file
= get_opts
.opt_arg ();
105 debug
= ACE_OS::atoi (get_opts
.opt_arg ());
109 lanes_file
= get_opts
.opt_arg ();
113 ior_file_base
= get_opts
.opt_arg ();
118 ACE_ERROR_RETURN ((LM_ERROR
,
120 "\t-b <bands file> (defaults to %s)\n"
121 "\t-b <lanes file> (defaults to %s)\n"
122 "\t-o <ior file base> (defaults to %s)\n"
135 write_iors_to_file (CORBA::Object_ptr object
,
138 char filename
[BUFSIZ
];
139 ACE_OS::sprintf (filename
,
141 ACE_TEXT_ALWAYS_CHAR (ior_file_base
),
146 ACE_OS::fopen (filename
, "w");
147 ACE_ASSERT (file
!= 0);
149 CORBA::String_var ior
=
150 orb
->object_to_string (object
);
154 ACE_OS::fprintf (file
,
158 ACE_ASSERT (result
== ACE_OS::strlen (ior
.in ()));
159 ACE_UNUSED_ARG (result
);
161 ACE_OS::fclose (file
);
165 vanilla_poa (CORBA::ORB_ptr orb
,
166 PortableServer::POA_ptr root_poa
,
167 PortableServer::POAManager_ptr poa_manager
)
169 CORBA::PolicyList policies
;
171 CORBA::Policy_var implicit_activation_policy
=
172 root_poa
->create_implicit_activation_policy (PortableServer::IMPLICIT_ACTIVATION
);
174 policies
.length (policies
.length () + 1);
175 policies
[policies
.length () - 1] =
176 implicit_activation_policy
;
178 PortableServer::POA_var poa
=
179 root_poa
->create_POA ("child",
184 ACE_NEW_THROW_EX (servant
,
187 CORBA::NO_MEMORY ());
189 PortableServer::ServantBase_var
safe_servant (servant
);
191 PortableServer::ObjectId_var id_act
=
192 poa
->activate_object (servant
);
194 CORBA::Object_var object
= poa
->id_to_reference (id_act
.in ());
197 test::_narrow (object
.in ());
199 write_iors_to_file (test
.in (),
204 rt_poa (CORBA::ORB_ptr orb
,
205 RTCORBA::RTORB_ptr rt_orb
,
206 PortableServer::POA_ptr root_poa
,
207 PortableServer::POAManager_ptr poa_manager
)
209 CORBA::PolicyList policies
;
212 get_priority_bands ("server",
219 ACE_ERROR ((LM_ERROR
,
220 "Error in parsing bands data file: %s\n",
226 get_priority_lanes ("server",
232 allow_request_buffering
,
233 max_buffered_requests
,
234 max_request_buffer_size
,
240 ACE_ERROR ((LM_ERROR
,
241 "Error in parsing lanes data file: %s\n",
246 CORBA::Policy_var priority_model_policy
=
247 rt_orb
->create_priority_model_policy (RTCORBA::CLIENT_PROPAGATED
,
250 // Implicit_activation policy.
251 CORBA::Policy_var implicit_activation_policy
=
252 root_poa
->create_implicit_activation_policy (PortableServer::IMPLICIT_ACTIVATION
);
254 policies
.length (policies
.length () + 1);
255 policies
[policies
.length () - 1] =
256 priority_model_policy
;
258 policies
.length (policies
.length () + 1);
259 policies
[policies
.length () - 1] =
260 implicit_activation_policy
;
262 PortableServer::POA_var poa
=
263 root_poa
->create_POA ("rt_poa",
268 ACE_NEW_THROW_EX (servant
,
271 CORBA::NO_MEMORY ());
273 PortableServer::ServantBase_var
safe_servant (servant
);
275 PortableServer::ObjectId_var id_act
=
276 poa
->activate_object (servant
);
278 CORBA::Object_var object
= poa
->id_to_reference (id_act
.in ());
281 test::_narrow (object
.in ());
283 write_iors_to_file (test
.in (),
287 class Task
: public ACE_Task_Base
290 Task (ACE_Thread_Manager
&thread_manager
,
298 Task::Task (ACE_Thread_Manager
&thread_manager
,
300 : ACE_Task_Base (&thread_manager
),
301 orb_ (CORBA::ORB::_duplicate (orb
))
310 CORBA::Object_var object
=
311 this->orb_
->resolve_initial_references ("RTORB");
313 RTCORBA::RTORB_var rt_orb
=
314 RTCORBA::RTORB::_narrow (object
.in ());
317 this->orb_
->resolve_initial_references ("RootPOA");
319 PortableServer::POA_var root_poa
=
320 PortableServer::POA::_narrow (object
.in ());
322 PortableServer::POAManager_var poa_manager
=
323 root_poa
->the_POAManager ();
325 vanilla_poa (this->orb_
.in (),
329 rt_poa (this->orb_
.in (),
334 poa_manager
->activate ();
338 this->orb_
->destroy ();
340 catch (const CORBA::Exception
& ex
)
342 ex
._tao_print_exception ("Exception caught");
350 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
355 CORBA::ORB_init (argc
, argv
);
358 parse_args (argc
, argv
);
362 // Make sure we can support multiple priorities that are required
364 if (!check_supported_priorities (orb
.in ()))
367 // Thread Manager for managing task.
368 ACE_Thread_Manager thread_manager
;
371 Task
task (thread_manager
,
374 // Task activation flags.
378 orb
->orb_core ()->orb_params ()->thread_creation_flags ();
382 task
.activate (flags
);
387 ACE_ERROR_RETURN ((LM_ERROR
,
388 "Cannot create thread with scheduling policy %C\n"
389 "because the user does not have the appropriate privileges, terminating program....\n"
390 "Check svc.conf options and/or run as root\n",
391 sched_policy_name (orb
->orb_core ()->orb_params ()->ace_sched_policy ())),
399 // Wait for task to exit.
401 thread_manager
.wait ();
402 ACE_ASSERT (result
!= -1);
404 catch (const CORBA::Exception
& ex
)
406 ex
._tao_print_exception ("Exception caught");