Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Event / Basic / Schedule.cpp
blob335ad144b0c4ee226d19a7e6096f88ff0634a67c
1 #include "Schedule.h"
2 #include "Consumer.h"
3 #include "Supplier.h"
4 #include "orbsvcs/Event/EC_Event_Channel.h"
5 #include "orbsvcs/Sched/Config_Scheduler.h"
6 #include "orbsvcs/Event_Utilities.h"
7 #include "orbsvcs/Scheduler_Factory.h"
8 #include "orbsvcs/Time_Utilities.h"
9 #include "ace/Get_Opt.h"
10 #include "ace/Sched_Params.h"
14 int
15 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
17 EC_Schedule driver;
18 return driver.run (argc, argv);
21 // ****************************************************************
23 EC_Schedule::EC_Schedule (void)
24 : scheduler_impl_ (0)
28 int
29 EC_Schedule::parse_args (int& argc, ACE_TCHAR* argv[])
31 if (this->EC_Driver::parse_args (argc, argv) != 0)
32 return -1;
34 return 0;
37 void
38 EC_Schedule::print_args (void) const
40 this->EC_Driver::print_args ();
43 void
44 EC_Schedule::print_usage (void)
46 this->EC_Driver::print_usage ();
49 void
50 EC_Schedule::initialize_ec_impl (void)
52 this->scheduler_impl_ = new ACE_Config_Scheduler;
53 this->scheduler_ = this->scheduler_impl_->_this ();
55 this->EC_Driver::initialize_ec_impl ();
58 void
59 EC_Schedule::modify_attributes (TAO_EC_Event_Channel_Attributes& attr)
61 attr.scheduler = this->scheduler_.in (); // no need to dup
64 void
65 EC_Schedule::cleanup_ec (void)
67 this->EC_Driver::cleanup_ec ();
68 delete this->scheduler_impl_;
71 void
72 EC_Schedule::execute_test (void)
74 CORBA::Long min_priority =
75 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO)
76 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
77 CORBA::Long max_priority =
78 ACE_Sched_Params::priority_max (ACE_SCHED_FIFO);
80 if (this->verbose ())
81 ACE_DEBUG ((LM_DEBUG,
82 "EC_Schedule (%P|%t) computing schedule\n"));
84 RtecScheduler::RT_Info_Set_var infos;
85 RtecScheduler::Dependency_Set_var deps;
86 RtecScheduler::Config_Info_Set_var configs;
87 RtecScheduler::Scheduling_Anomaly_Set_var anomalies;
88 this->scheduler_->compute_scheduling (min_priority, max_priority,
89 infos.out (),
90 deps.out (),
91 configs.out (),
92 anomalies.out ());
94 if (this->verbose ())
95 ACE_DEBUG ((LM_DEBUG,
96 "EC_Schedule (%P|%t) schedule prepared\n"));
98 ACE_Scheduler_Factory::dump_schedule (infos.in (),
99 deps.in (),
100 configs.in (),
101 anomalies.in ());
103 if (this->verbose ())
104 ACE_DEBUG ((LM_DEBUG,
105 "EC_Schedule (%P|%t) schedule dumped\n"));
109 void
110 EC_Schedule::build_consumer_qos (
111 int i,
112 RtecEventChannelAdmin::ConsumerQOS& qos,
113 int& shutdown_event_type)
115 char name[128];
116 ACE_OS::sprintf (name, "EC_Schedule::Consumer::%04x", i);
118 RtecScheduler::handle_t rt_info =
119 this->scheduler_->create (name);
121 // The worst case execution time is far less than 2
122 // milliseconds, but that is a safe estimate....
123 ACE_Time_Value tv (0, 2000);
124 TimeBase::TimeT time;
125 ORBSVCS_Time::Time_Value_to_TimeT (time, tv);
126 this->scheduler_->set (rt_info,
127 RtecScheduler::VERY_HIGH_CRITICALITY,
128 time, time, time,
130 RtecScheduler::VERY_LOW_IMPORTANCE,
131 time,
133 RtecScheduler::OPERATION);
135 int type_start =
136 this->consumer_type_start_
137 + i * this->consumer_type_shift_;
139 shutdown_event_type = type_start + this->consumer_type_count_;
141 ACE_ConsumerQOS_Factory qos_factory;
142 qos_factory.start_disjunction_group ();
143 qos_factory.insert_type (shutdown_event_type, rt_info);
145 for (int j = 0; j != this->consumer_type_count_; ++j)
146 qos_factory.insert_type (type_start + j, rt_info);
148 qos = qos_factory.get_ConsumerQOS ();
151 void
152 EC_Schedule::build_supplier_qos (
153 int i,
154 RtecEventChannelAdmin::SupplierQOS& qos,
155 int& shutdown_event_type)
157 char name[128];
158 ACE_OS::sprintf (name, "EC_Schedule::Supplier::%04x", i);
160 RtecScheduler::handle_t rt_info =
161 this->scheduler_->create (name);
163 ACE_Time_Value tv (0, this->burst_pause_);
164 RtecScheduler::Period_t rate = tv.usec () * 10;
166 // The execution times are set to reasonable values, but
167 // actually they are changed on the real execution, i.e. we
168 // lie to the scheduler to obtain right priorities; but we
169 // don't care if the set is schedulable.
170 tv.set (0, 2000);
171 TimeBase::TimeT time;
172 ORBSVCS_Time::Time_Value_to_TimeT (time, tv);
173 this->scheduler_->set (rt_info,
174 RtecScheduler::VERY_HIGH_CRITICALITY,
175 time, time, time,
176 rate,
177 RtecScheduler::VERY_LOW_IMPORTANCE,
178 time,
180 RtecScheduler::OPERATION);
182 int type_start = this->supplier_type_start_ + i*this->supplier_type_shift_;
183 int supplier_id = i + 1;
184 shutdown_event_type = type_start + this->supplier_type_count_;
186 ACE_SupplierQOS_Factory qos_factory;
187 for (int j = 0; j != this->supplier_type_count_; ++j)
188 qos_factory.insert (supplier_id,
189 type_start + j,
190 rt_info, 1);
192 qos_factory.insert (supplier_id,
193 shutdown_event_type,
194 rt_info, 1);
196 qos = qos_factory.get_SupplierQOS ();
199 void
200 EC_Schedule::dump_results (void)