2 #include "../Task_Stats.h"
3 #include "../Synch_i.h"
5 #include "tao/RTScheduling/RTScheduler_Manager.h"
6 #include "tao/ORB_Core.h"
8 #include "ace/Arg_Shifter.h"
10 #include "ace/Event_Handler.h"
11 #include "ace/Sig_Handler.h"
13 class TestShutdown
: public ACE_Event_Handler
16 TestShutdown (CORBA::ORB_ptr orb
)
17 : orb_(CORBA::ORB::_duplicate (orb
))
19 #if !defined(ACE_LACKS_UNIX_SIGNALS)
20 this->shutdown_
.register_handler (SIGTERM
, this);
21 this->shutdown_
.register_handler (SIGINT
, this);
22 #elif defined(ACE_WIN32)
23 this->shutdown_
.register_handler (SIGINT
, this);
29 #if !defined(ACE_LACKS_UNIX_SIGNALS)
30 this->shutdown_
.remove_handler (SIGTERM
);
31 this->shutdown_
.remove_handler (SIGINT
);
32 #elif defined(ACE_WIN32)
33 this->shutdown_
.remove_handler (SIGINT
);
37 virtual int handle_signal (int, siginfo_t
*, ucontext_t
*)
39 ACE_DEBUG ((LM_DEBUG
, "Shutting down...\n"));
40 this->orb_
->shutdown ();
47 ACE_Sig_Handler shutdown_
;
50 DT_Test::DT_Test (void)
55 DT_Test::init (int argc
, ACE_TCHAR
*argv
[])
57 orb_
= CORBA::ORB_init (argc
, argv
);
59 dt_creator_
->orb (orb_
.in ());
61 CORBA::Object_var manager_obj
= orb_
->resolve_initial_references ("RTSchedulerManager");
63 TAO_RTScheduler_Manager_var manager
= TAO_RTScheduler_Manager::_narrow (manager_obj
.in ());
66 ACE_NEW_RETURN (scheduler_
,
67 MIF_Scheduler (orb_
.in ()), -1);
69 manager
->rtscheduler (scheduler_
.in ());
71 CORBA::Object_var object
=
72 orb_
->resolve_initial_references ("RTScheduler_Current");
75 RTScheduling::Current::_narrow (object
.in ());
81 DT_Test::run (int argc
, ACE_TCHAR
* argv
[])
85 TestShutdown
killer (this->orb_
.in ());
87 TASK_STATS::instance ()->init (this->dt_creator_
->total_load ());
88 if (this->dt_creator_
->resolve_naming_service () == -1)
91 this->dt_creator_
->activate_root_poa ();
93 this->dt_creator_
->activate_poa_list ();
94 this->dt_creator_
->activate_job_list ();
95 this->dt_creator_
->activate_schedule ();
97 this->dt_creator_
->register_synch_obj ();
100 "Registered Synch Object\n"));
102 this->dt_creator_
->create_distributable_threads (current_
.in ());
104 ACE_Thread_Manager::instance ()->wait ();
106 this->orb_
->destroy ();
108 ACE_DEBUG ((LM_DEBUG
,
109 "Test Terminating......\n"));
114 DT_Test::dt_creator (MIF_DT_Creator
* dt_creator
)
116 this->dt_creator_
= dt_creator
;
121 DT_Test::scheduler (void)
123 return this->scheduler_
.in ();
127 DT_Test::activate_task (void)
131 flags = THR_NEW_LWP | THR_JOINABLE;
133 orb_->orb_core ()->orb_params ()->scope_policy () |
134 orb_->orb_core ()->orb_params ()->sched_policy ();
136 if (this->activate (flags,
139 if (ACE_OS::last_error () == EPERM)
140 ACE_ERROR_RETURN ((LM_ERROR,
141 ACE_TEXT ("Insufficient privilege to run this test.\n")),
152 dt_creator_->create_distributable_threads (current_.in ());
155 catch (const CORBA::Exception& ex)
157 ex._tao_print_exception ("Caught exception:");
166 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
170 ACE_Service_Config::static_svcs ()->insert (&ace_svc_desc_MIF_DT_Creator
);
174 ACE_DEBUG ((LM_DEBUG
,
175 "%t Main Thread\n"));
176 DT_TEST::instance ()->run (argc
, argv
);
178 catch (const CORBA::Exception
& ex
)
180 ex
._tao_print_exception ("Caught exception:");
184 ACE_Service_Config::static_svcs ()->remove (ACE_TEXT ("MIF_DT_Creator"));
186 ACE_DEBUG ((LM_DEBUG
, "END\n"));
190 ACE_SINGLETON_TEMPLATE_INSTANTIATE(ACE_Singleton
, DT_Test
, TAO_SYNCH_MUTEX
);