1 // This program performa a simple scheduler configuration run,
2 // and dumps the results of one scheduling into a C++ header file.
4 #include "ace/Sched_Params.h"
5 #include "ace/Get_Opt.h"
8 #include "orbsvcs/CosNamingC.h"
9 #include "orbsvcs/Scheduler_Factory.h"
10 #include "orbsvcs/Naming/Naming_Server.h"
13 const char* service_name
= "ScheduleService";
15 const char* format_string
= "{%-12s, %d, %d, %d, %d, %8d, "
16 "static_cast<RtecScheduler::Criticality_t> (%d), "
17 "static_cast<RtecScheduler::Importance_t> (%d), "
18 "%d, %d, %3d, %d, %d, "
19 "static_cast<RtecScheduler::Info_Type_t> (%d)}\n";
22 parse_args (int argc
, ACE_TCHAR
*argv
[])
24 ACE_Get_Opt
get_opt (argc
, argv
, ACE_TEXT("n:"));
27 while ((opt
= get_opt ()) != EOF
)
32 service_name
= get_opt
.opt_arg ();
49 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
51 if (parse_args (argc
, argv
) != 0)
56 // create initial data for supplier and consumer operations
57 const int operation_count
= 8;
58 ACE_Scheduler_Factory::POD_RT_Info config_infos
[operation_count
] = {
59 // good supplier (no unresolved dependencies)
60 { "good_supplier", // entry point
62 5000, // worst case execution time
63 5000, // typical execution time (unused)
64 5000, // cached execution time
65 500000, // period (100 ns)
66 RtecScheduler::HIGH_CRITICALITY
, // criticality
67 RtecScheduler::LOW_IMPORTANCE
, // importance
68 0, // quantum (unused)
71 0, // Preemption subpriority
72 0, // Preemption priority
73 RtecScheduler::OPERATION
// info type
75 // good consumer (no unresolved dependencies)
76 { "good_consumer", // entry point
78 5000, // worst case execution time
79 5000, // typical execution time (unused)
80 5000, // cached execution time
82 RtecScheduler::HIGH_CRITICALITY
, // criticality
83 RtecScheduler::LOW_IMPORTANCE
, // importance
84 0, // quantum (unused)
87 0, // Preemption subpriority
88 0, // Preemption priority
89 RtecScheduler::OPERATION
// info type
91 // supplier with unresolved remote dependencies
92 { "unresolved_remote_supplier", // entry point
94 5000, // worst case execution time
95 5000, // typical execution time (unused)
96 5000, // cached execution time
98 RtecScheduler::HIGH_CRITICALITY
, // criticality
99 RtecScheduler::LOW_IMPORTANCE
, // importance
100 0, // quantum (unused)
103 0, // Preemption subpriority
104 0, // Preemption priority
105 RtecScheduler::REMOTE_DEPENDANT
// info type
107 // consumer with unresolved remote dependencies
108 { "unresolved_remote_consumer", // entry point
110 5000, // worst case execution time
111 5000, // typical execution time (unused)
112 5000, // cached execution time
113 0, // period (100 ns)
114 RtecScheduler::HIGH_CRITICALITY
, // criticality
115 RtecScheduler::LOW_IMPORTANCE
, // importance
116 0, // quantum (unused)
119 0, // Preemption subpriority
120 0, // Preemption priority
121 RtecScheduler::OPERATION
// info type
123 // supplier with unresolved local dependencies
124 { "unresolved_local_supplier", // entry point
126 5000, // worst case execution time
127 5000, // typical execution time (unused)
128 5000, // cached execution time
129 0, // period (100 ns)
130 RtecScheduler::HIGH_CRITICALITY
, // criticality
131 RtecScheduler::LOW_IMPORTANCE
, // importance
132 0, // quantum (unused)
135 0, // Preemption subpriority
136 0, // Preemption priority
137 RtecScheduler::OPERATION
// info type
139 // consumer with unresolved local dependencies
140 { "unresolved_local_consumer", // entry point
142 5000, // worst case execution time
143 5000, // typical execution time (unused)
144 5000, // cached execution time
145 0, // period (100 ns)
146 RtecScheduler::HIGH_CRITICALITY
, // criticality
147 RtecScheduler::LOW_IMPORTANCE
, // importance
148 0, // quantum (unused)
151 0, // Preemption subpriority
152 0, // Preemption priority
153 RtecScheduler::OPERATION
// info type
155 // consumer with unresolved local and remote dependencies
156 { "both_unresolved_consumer_1", // entry point
158 5000, // worst case execution time
159 5000, // typical execution time (unused)
160 5000, // cached execution time
161 0, // period (100 ns)
162 RtecScheduler::HIGH_CRITICALITY
, // criticality
163 RtecScheduler::LOW_IMPORTANCE
, // importance
164 0, // quantum (unused)
167 0, // Preemption subpriority
168 0, // Preemption priority
169 RtecScheduler::OPERATION
// info type
171 // another consumer with unresolved
172 // local and remote dependencies
173 { "both_unresolved_consumer_2", // entry point
175 5000, // worst case execution time
176 5000, // typical execution time (unused)
177 5000, // cached execution time
178 0, // period (100 ns)
179 RtecScheduler::HIGH_CRITICALITY
, // criticality
180 RtecScheduler::LOW_IMPORTANCE
, // importance
181 0, // quantum (unused)
184 0, // Preemption subpriority
185 0, // Preemption priority
186 RtecScheduler::OPERATION
// info type
194 CORBA::ORB_init (argc
, argv
, "internet");
196 CORBA::Object_var poa_object
=
197 orb
->resolve_initial_references("RootPOA");
199 if (CORBA::is_nil(poa_object
.in ()))
200 ACE_ERROR_RETURN ((LM_ERROR
,
201 " (%P|%t) Unable to initialize the POA.\n"),
204 PortableServer::POA_var root_poa
=
205 PortableServer::POA::_narrow (poa_object
.in());
207 PortableServer::POAManager_var poa_manager
=
208 root_poa
->the_POAManager ();
210 // Initialize the naming services
211 TAO_Naming_Client my_name_client
;
212 if (my_name_client
.init (orb
.in ()) != 0)
213 ACE_ERROR_RETURN ((LM_ERROR
,
214 " (%P|%t) Unable to initialize "
215 "the TAO_Naming_Client.\n"),
218 CosNaming::NamingContext_var context
=
219 my_name_client
.get_context ();
221 if (ACE_Scheduler_Factory::use_config (context
.in (),
223 ACE_ERROR_RETURN ((LM_ERROR
,
224 " (%P|%t) Unable to bind to the scheduling service.\n"),
227 // create and initialize RT_Infos in the scheduler,
228 // make second half of array depend on first half.
229 for (int i
= 0; i
< operation_count
; ++i
)
231 // create the RT_Info
232 config_infos
[i
].handle
=
233 ACE_Scheduler_Factory::server ()->create (config_infos
[i
].entry_point
);
235 // initialize the RT_Info
236 ACE_Scheduler_Factory::server ()->
237 set (config_infos
[i
].handle
,
238 static_cast<RtecScheduler::Criticality_t
> (config_infos
[i
].criticality
),
239 config_infos
[i
].worst_case_execution_time
,
240 config_infos
[i
].typical_execution_time
,
241 config_infos
[i
].cached_execution_time
,
242 config_infos
[i
].period
,
243 static_cast<RtecScheduler::Importance_t
> (config_infos
[i
].importance
),
244 config_infos
[i
].quantum
,
245 config_infos
[i
].threads
,
246 static_cast<RtecScheduler::Info_Type_t
> (config_infos
[i
].info_type
));
250 // register dependency of good consumer on good supplier
251 ACE_Scheduler_Factory::server ()->
252 add_dependency (config_infos
[1].handle
,
253 config_infos
[0].handle
,
254 1, // number of calls
255 RtecBase::ONE_WAY_CALL
); // type of dependency
257 // register dependency of consumer that will have unresolved remote
258 // dependencies on supplier with unresolved remote dependencies
259 ACE_Scheduler_Factory::server ()->
260 add_dependency (config_infos
[3].handle
,
261 config_infos
[2].handle
,
262 1, // number of calls
263 RtecBase::ONE_WAY_CALL
); // type of dependency
265 // register dependency of consumer that will have unresolved local
266 // dependencies on supplier with unresolved local dependencies
267 ACE_Scheduler_Factory::server ()->
268 add_dependency (config_infos
[5].handle
,
269 config_infos
[4].handle
,
270 1, // number of calls
271 RtecBase::ONE_WAY_CALL
); // type of dependency
273 // register dependencies on each supplier of first consumer that will
274 // have both unresolved local and unresolved remote dependencies.
275 ACE_Scheduler_Factory::server ()->
276 add_dependency (config_infos
[6].handle
,
277 config_infos
[0].handle
,
278 1, // number of calls
279 RtecBase::ONE_WAY_CALL
); // type of dependency
281 ACE_Scheduler_Factory::server ()->
282 add_dependency (config_infos
[6].handle
,
283 config_infos
[2].handle
,
284 1, // number of calls
285 RtecBase::ONE_WAY_CALL
); // type of dependency
287 ACE_Scheduler_Factory::server ()->
288 add_dependency (config_infos
[6].handle
,
289 config_infos
[4].handle
,
290 1, // number of calls
291 RtecBase::ONE_WAY_CALL
); // type of dependency
293 // Register dependencies on each of the other consumers by second
294 // consumer that will have both unresolved local and unresolved remote
296 ACE_Scheduler_Factory::server ()->
297 add_dependency (config_infos
[7].handle
,
298 config_infos
[1].handle
,
299 1, // number of calls
300 RtecBase::ONE_WAY_CALL
); // type of dependency
302 ACE_Scheduler_Factory::server ()->
303 add_dependency (config_infos
[7].handle
,
304 config_infos
[3].handle
,
305 1, // number of calls
306 RtecBase::ONE_WAY_CALL
); // type of dependency
308 ACE_Scheduler_Factory::server ()->
309 add_dependency (config_infos
[7].handle
,
310 config_infos
[5].handle
,
311 1, // number of calls
312 RtecBase::ONE_WAY_CALL
); // type of dependency
314 ACE_Scheduler_Factory::server ()->
315 add_dependency (config_infos
[7].handle
,
316 config_infos
[6].handle
,
317 1, // number of calls
318 RtecBase::ONE_WAY_CALL
); // type of dependency
320 RtecScheduler::RT_Info_Set_var infos
;
321 RtecScheduler::Dependency_Set_var deps
;
322 RtecScheduler::Config_Info_Set_var configs
;
323 RtecScheduler::Scheduling_Anomaly_Set_var anomalies
;
325 ACE_Scheduler_Factory::server ()->compute_scheduling
326 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO
,
328 ACE_Sched_Params::priority_max (ACE_SCHED_FIFO
,
330 infos
.out (), deps
.out (),
331 configs
.out (), anomalies
.out ());
333 ACE_Scheduler_Factory::dump_schedule (infos
.in (),
337 "Sched_Conf_Anomalies_Runtime.h",
340 catch (const CORBA::Exception
& ex
)
342 ex
._tao_print_exception ("SYS_EX");