=default for generated implementation copy ctor
[ACE_TAO.git] / TAO / examples / RTScheduling / MIF_Scheduler / test.cpp
blob1fd1c748dc3696979a3df2797db2b98ecec75ab5
1 #include "test.h"
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
15 public:
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);
24 #endif
27 ~TestShutdown ()
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);
34 #endif
37 virtual int handle_signal (int, siginfo_t*, ucontext_t*)
39 ACE_DEBUG ((LM_DEBUG, "Shutting down...\n"));
40 this->orb_->shutdown ();
41 return 0;
44 private:
45 CORBA::ORB_var orb_;
47 ACE_Sig_Handler shutdown_;
50 DT_Test::DT_Test ()
54 int
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");
74 current_ =
75 RTScheduling::Current::_narrow (object.in ());
77 return 0;
80 void
81 DT_Test::run (int argc, ACE_TCHAR* argv [])
83 init (argc,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)
89 return;
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 ();
99 ACE_DEBUG ((LM_DEBUG,
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"));
113 void
114 DT_Test::dt_creator (MIF_DT_Creator* dt_creator)
116 this->dt_creator_ = dt_creator;
120 MIF_Scheduler*
121 DT_Test::scheduler ()
123 return this->scheduler_.in ();
127 DT_Test::activate_task ()
129 long flags;
130 flags = THR_NEW_LWP | THR_JOINABLE;
131 flags |=
132 orb_->orb_core ()->orb_params ()->scope_policy () |
133 orb_->orb_core ()->orb_params ()->sched_policy ();
135 if (this->activate (flags,
136 1) == -1)
138 if (ACE_OS::last_error () == EPERM)
139 ACE_ERROR_RETURN ((LM_ERROR,
140 ACE_TEXT ("Insufficient privilege to run this test.\n")),
141 -1);
143 return 0;
147 DT_Test::svc ()
151 dt_creator_->create_distributable_threads (current_.in ());
153 catch (const CORBA::Exception& ex)
155 ex._tao_print_exception ("Caught exception:");
156 return -1;
159 return 0;
164 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
166 int status = 0;
168 ACE_Service_Config::static_svcs ()->insert (&ace_svc_desc_MIF_DT_Creator);
172 ACE_DEBUG ((LM_DEBUG,
173 "%t Main Thread\n"));
174 DT_TEST::instance ()->run (argc, argv);
176 catch (const CORBA::Exception& ex)
178 ex._tao_print_exception ("Caught exception:");
179 status = 1;
182 ACE_Service_Config::static_svcs ()->remove (ACE_TEXT ("MIF_DT_Creator"));
184 ACE_DEBUG ((LM_DEBUG, "END\n"));
185 return status;
188 ACE_SINGLETON_TEMPLATE_INSTANTIATE(ACE_Singleton, DT_Test, TAO_SYNCH_MUTEX);