1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
|
#include "orbsvcs/Sched/Reconfig_Scheduler.h"
#include "orbsvcs/Runtime_Scheduler.h"
//#include "orbsvcs/Event/Module_Factory.h"
//#include "orbsvcs/Event/Event_Channel.h"
#include "orbsvcs/Event_Service_Constants.h"
#include "orbsvcs/Event_Utilities.h"
#include "orbsvcs/Scheduler_Factory.h"
#include "orbsvcs/Event/EC_Event_Channel.h"
#include "orbsvcs/Event/EC_Default_Factory.h"
#include "orbsvcs/Event/EC_Kokyu_Factory.h"
#include "Consumer.h"
#include "Supplier.h"
#include "ace/Get_Opt.h"
#include "ace/Sched_Params.h"
#include "ace/Auto_Ptr.h"
#include "ace/SString.h"
#include "ace/OS_NS_strings.h"
#include "ace/Thread.h"
namespace
{
int config_run = 0;
ACE_CString sched_type ="rms";
}
inline RtecScheduler::Period_t time_val_to_period (const ACE_Time_Value &tv)
{
//100s of nanoseconds
return static_cast<RtecScheduler::Period_t> (tv.sec () * 1000000 + tv.usec ())*10;
}
int parse_args (int argc, ACE_TCHAR *argv[]);
typedef TAO_Reconfig_Scheduler<TAO_RMS_FAIR_Reconfig_Sched_Strategy, TAO_SYNCH_MUTEX> RECONFIG_RMS_SCHED_TYPE;
typedef TAO_Reconfig_Scheduler<TAO_MUF_FAIR_Reconfig_Sched_Strategy, TAO_SYNCH_MUTEX> RECONFIG_MUF_SCHED_TYPE;
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
ACE_UNUSED_ARG (config_run);
//TAO_EC_Default_Factory::init_svcs ();
TAO_EC_Kokyu_Factory::init_svcs ();
try
{
// ORB initialization boiler plate...
CORBA::ORB_var orb =
CORBA::ORB_init (argc, argv);
if (parse_args (argc, argv) == -1)
{
ACE_ERROR ((LM_ERROR,
"Usage: Service [-o IOR_file_name]\n"));
return 1;
}
CORBA::Object_var object =
orb->resolve_initial_references ("RootPOA");
PortableServer::POA_var poa =
PortableServer::POA::_narrow (object.in ());
PortableServer::POAManager_var poa_manager =
poa->the_POAManager ();
poa_manager->activate ();
// ****************************************************************
// Create an scheduling service
POA_RtecScheduler::Scheduler* sched_impl = 0;
if (ACE_OS::strcasecmp(sched_type.c_str(), "rms") == 0)
{
ACE_DEBUG ((LM_DEBUG, "Creating RMS scheduler\n"));
ACE_NEW_RETURN (sched_impl,
RECONFIG_RMS_SCHED_TYPE,
1);
}
else if (ACE_OS::strcasecmp(sched_type.c_str(), "muf") == 0)
{
ACE_DEBUG ((LM_DEBUG, "Creating MUF scheduler\n"));
ACE_NEW_RETURN (sched_impl,
RECONFIG_MUF_SCHED_TYPE,
1);
}
RtecScheduler::Scheduler_var scheduler =
sched_impl->_this ();
// ****************************************************************
TAO_EC_Event_Channel_Attributes attributes (poa.in (),
poa.in ());
attributes.scheduler = scheduler.in (); // no need to dup
TAO_EC_Event_Channel ec_impl (attributes);
RtecEventChannelAdmin::EventChannel_var event_channel =
ec_impl._this ();
// ****************************************************************
// Create a consumer, intialize its RT_Info structures, and
// connnect to the event channel....
Consumer consumer_impl1, consumer_impl2;
RtecScheduler::handle_t consumer1_rt_info =
scheduler->create ("consumer1");
RtecScheduler::handle_t consumer2_rt_info =
scheduler->create ("consumer2");
//consumer's rate will get propagated from the supplier.
//so no need to specify a period here. Specifying
//criticality is crucial since it propagates from
//consumer to supplier.
ACE_Time_Value tv (0,0);
TimeBase::TimeT tmp;
ORBSVCS_Time::Time_Value_to_TimeT (tmp, tv);
scheduler->set (consumer1_rt_info,
RtecScheduler::VERY_LOW_CRITICALITY,
tmp, tmp, tmp,
time_val_to_period (tv),
RtecScheduler::VERY_LOW_IMPORTANCE,
tmp,
0,
RtecScheduler::OPERATION);
scheduler->set (consumer2_rt_info,
RtecScheduler::VERY_HIGH_CRITICALITY,
tmp, tmp, tmp,
time_val_to_period (tv),
RtecScheduler::VERY_HIGH_IMPORTANCE,
tmp,
0,
RtecScheduler::OPERATION);
ACE_ConsumerQOS_Factory consumer_qos1, consumer_qos2;
//consumer_qos.start_disjunction_group ();
// The types int the range [0,ACE_ES_EVENT_UNDEFINED) are
// reserved for the EC...
consumer_qos1.insert_type (ACE_ES_EVENT_UNDEFINED,
consumer1_rt_info);
RtecEventChannelAdmin::ConsumerQOS qos =
consumer_qos1.get_ConsumerQOS ();
/*
for (int i=0;i<qos.dependencies.length (); ++i)
{
ACE_DEBUG ((LM_DEBUG,
"consumer_qos1[%d] event.header.type = %d, "
"consumer_qos1[%d] rt_info = %d, "
"consumer_qos1[%d] event.header.source = %d\n",
i,qos.dependencies[i].event.header.type,
i,qos.dependencies[i].rt_info,
i,qos.dependencies[i].event.header.source));
}
*/
consumer_qos2.insert_type (ACE_ES_EVENT_UNDEFINED + 1,
consumer2_rt_info);
// The canonical protocol to connect to the EC
RtecEventChannelAdmin::ConsumerAdmin_var consumer_admin =
event_channel->for_consumers ();
RtecEventChannelAdmin::ProxyPushSupplier_var supplier_proxy1 =
consumer_admin->obtain_push_supplier ();
RtecEventChannelAdmin::ProxyPushSupplier_var supplier_proxy2 =
consumer_admin->obtain_push_supplier ();
RtecEventComm::PushConsumer_var consumer1 =
consumer_impl1._this ();
RtecEventComm::PushConsumer_var consumer2 =
consumer_impl2._this ();
ACE_DEBUG ((LM_DEBUG, "connecting consumers\n"));
ACE_DEBUG ((LM_DEBUG, "connecting consumer1\n"));
supplier_proxy1->connect_push_consumer (consumer1.in (),
consumer_qos1.get_ConsumerQOS ());
ACE_DEBUG ((LM_DEBUG, "connecting consumer2\n"));
supplier_proxy2->connect_push_consumer (consumer2.in (),
consumer_qos2.get_ConsumerQOS ());
ACE_DEBUG ((LM_DEBUG, "consumers connected\n"));
// ****************************************************************
RtecScheduler::handle_t supplier1_rt_info =
scheduler->create ("supplier1");
RtecScheduler::handle_t supplier2_rt_info =
scheduler->create ("supplier2");
RtecEventComm::EventSourceID supplier_id1 = 1, supplier_id2 = 2;
ACE_SupplierQOS_Factory supplier_qos1, supplier_qos2;
supplier_qos1.insert (supplier_id1,
ACE_ES_EVENT_UNDEFINED,
supplier1_rt_info,
1 /* number of calls, but what does that mean? */);
supplier_qos2.insert (supplier_id2,
ACE_ES_EVENT_UNDEFINED + 1,
supplier2_rt_info,
1 /* number of calls, but what does that mean? */);
// The canonical protocol to connect to the EC
RtecEventChannelAdmin::SupplierAdmin_var supplier_admin =
event_channel->for_suppliers ();
RtecEventChannelAdmin::ProxyPushConsumer_var consumer_proxy1 =
supplier_admin->obtain_push_consumer ();
RtecEventChannelAdmin::ProxyPushConsumer_var consumer_proxy2 =
supplier_admin->obtain_push_consumer ();
Supplier supplier_impl1(supplier_id1, consumer_proxy1.in ());
Supplier supplier_impl2(supplier_id2, consumer_proxy2.in ());
RtecEventComm::PushSupplier_var supplier1 =
supplier_impl1._this ();
RtecEventComm::PushSupplier_var supplier2 =
supplier_impl2._this ();
ACE_DEBUG ((LM_DEBUG, "connecting suppliers\n"));
ACE_DEBUG ((LM_DEBUG, "connecting supplier1\n"));
consumer_proxy1->connect_push_supplier (supplier1.in (),
supplier_qos1.get_SupplierQOS ());
ACE_DEBUG ((LM_DEBUG, "connecting supplier2\n"));
consumer_proxy2->connect_push_supplier (supplier2.in (),
supplier_qos2.get_SupplierQOS ());
ACE_DEBUG ((LM_DEBUG, "suppliers connected\n"));
// ****************************************************************
//Timer Registration part
//Timeout consumers for the two suppliers.
Timeout_Consumer timeout_consumer_impl1(&supplier_impl1);
Timeout_Consumer timeout_consumer_impl2(&supplier_impl2);
RtecScheduler::handle_t supplier1_timeout_consumer_rt_info =
scheduler->create ("supplier1_timeout_consumer");
//Period = 1sec
tv.set (1,0);
ORBSVCS_Time::Time_Value_to_TimeT (tmp, tv);
scheduler->set (supplier1_timeout_consumer_rt_info,
RtecScheduler::VERY_LOW_CRITICALITY,
tmp, tmp, tmp,
time_val_to_period (tv),
RtecScheduler::VERY_LOW_IMPORTANCE,
tmp,
0,
RtecScheduler::OPERATION);
RtecScheduler::handle_t supplier2_timeout_consumer_rt_info =
scheduler->create ("supplier2_timeout_consumer");
//Period = 3sec
tv.set (3, 0);
ORBSVCS_Time::Time_Value_to_TimeT (tmp, tv);
scheduler->set (supplier2_timeout_consumer_rt_info,
RtecScheduler::VERY_HIGH_CRITICALITY,
tmp, tmp, tmp,
time_val_to_period (tv),
RtecScheduler::VERY_HIGH_IMPORTANCE,
tmp,
0,
RtecScheduler::OPERATION);
ACE_ConsumerQOS_Factory timer_qos1, timer_qos2;
timer_qos1.insert_time (ACE_ES_EVENT_INTERVAL_TIMEOUT,
10000000, //in 100s of nanosec
supplier1_timeout_consumer_rt_info);
timer_qos2.insert_time (ACE_ES_EVENT_INTERVAL_TIMEOUT,
30000000, //in 100s of nanosec
supplier2_timeout_consumer_rt_info);
RtecEventChannelAdmin::ProxyPushSupplier_var timeout_supplier_proxy1 =
consumer_admin->obtain_push_supplier ();
RtecEventChannelAdmin::ProxyPushSupplier_var timeout_supplier_proxy2 =
consumer_admin->obtain_push_supplier ();
RtecEventComm::PushConsumer_var safe_timeout_consumer1 =
timeout_consumer_impl1._this ();
RtecEventComm::PushConsumer_var safe_timeout_consumer2 =
timeout_consumer_impl2._this ();
ACE_DEBUG ((LM_DEBUG, "connecting timeout consumers\n"));
timeout_supplier_proxy1->
connect_push_consumer (safe_timeout_consumer1.in (),
timer_qos1.get_ConsumerQOS ());
timeout_supplier_proxy2->
connect_push_consumer (safe_timeout_consumer2.in (),
timer_qos2.get_ConsumerQOS ());
ACE_DEBUG ((LM_DEBUG, "timeout consumers connected\n"));
// ****************************************************************
//Registering dependency between timeout consumers and our suppliers
//with the scheduler
scheduler->add_dependency (supplier1_timeout_consumer_rt_info,
supplier1_rt_info,
1,
RtecBase::TWO_WAY_CALL);
scheduler->add_dependency (supplier2_timeout_consumer_rt_info,
supplier2_rt_info,
1,
RtecBase::TWO_WAY_CALL);
// ****************************************************************
// At this point the consumer and supplier are connected to the
// EC, they have provided their QoS info to the Scheduling
// Service and the EC has informed the Scheduler about the
// dependencies between them.
// We can now compute the schedule for this configuration...
// The schedule is returned in this variables....
ACE_DEBUG ((LM_DEBUG, "Computing schedule\n"));
RtecScheduler::RT_Info_Set_var infos;
RtecScheduler::Config_Info_Set_var configs;
RtecScheduler::Dependency_Set_var dependencies;
RtecScheduler::Scheduling_Anomaly_Set unsafe_anomalies;
RtecScheduler::Scheduling_Anomaly_Set_var anomalies;
scheduler->get_rt_info_set (infos.out() );
scheduler->get_dependency_set (dependencies.out() );
scheduler->get_config_info_set (configs.out() );
ACE_DEBUG ((LM_DEBUG, "Printing intermediate results\n"));
ACE_Scheduler_Factory::dump_schedule (infos.in (),
dependencies.in (),
configs.in (),
unsafe_anomalies,
ACE_TEXT("schedule.out"));
// Obtain the range of valid priorities in the current
// platform, the scheduler hard-code this values in the
// generated file, but in the future we may just use the
// "logical" priorities and define the mapping to OS
// priorities at run-time.
int min_os_priority =
ACE_Sched_Params::priority_min (ACE_SCHED_FIFO,
ACE_SCOPE_THREAD);
int max_os_priority =
ACE_Sched_Params::priority_max (ACE_SCHED_FIFO,
ACE_SCOPE_THREAD);
scheduler->compute_scheduling (min_os_priority,
max_os_priority,
infos.out (),
dependencies.out (),
configs.out (),
anomalies.out ());
// Dump the schedule to a file..
ACE_Scheduler_Factory::dump_schedule (infos.in (),
dependencies.in (),
configs.in (),
anomalies.in (),
ACE_TEXT("schedule.out"));
// ****************************************************************
ACE_DEBUG ((LM_DEBUG, "Pushing events\n"));
ACE_hthread_t thr_handle;
ACE_Thread::self (thr_handle);
int prio = ACE_Sched_Params::priority_max (ACE_SCHED_FIFO);
ACE_OS::thr_setprio (thr_handle, prio);
// // Generate a few events....
// RtecEventComm::EventSet event1 (1);
// event1.length (1);
// event1[0].header.type = ACE_ES_EVENT_UNDEFINED;
// event1[0].header.source = supplier_id1;
// event1[0].header.ttl = 1;
// RtecEventComm::EventSet event2 (1);
// event2.length (1);
// event2[0].header.type = ACE_ES_EVENT_UNDEFINED + 1;
// event2[0].header.source = supplier_id2;
// event2[0].header.ttl = 1;
// for (int i = 0; i != 200; ++i)
// {
// if (i % 2 == 0)
// {
// consumer_proxy1->push (event1);
// }
// else
// {
// consumer_proxy2->push (event2);
// }
// ACE_Time_Value rate (0, 10000);
// ACE_OS::sleep (rate);
// }
ACE_DEBUG ((LM_DEBUG, "(%t) activating EC\n"));
ec_impl.activate ();
ACE_DEBUG ((LM_DEBUG, "EC activated\n"));
orb->run ();
// ****************************************************************
// We should do a lot of cleanup (disconnect from the EC,
// deactivate all the objects with the POA, etc.) but this is
// just a simple demo so we are going to be lazy.
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception ("Service");
return 1;
}
return 0;
}
// ****************************************************************
int parse_args (int argc, ACE_TCHAR *argv[])
{
ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("cs:"));
int c;
while ((c = get_opts ()) != -1)
switch (c)
{
case 's':
sched_type = ACE_TEXT_ALWAYS_CHAR(get_opts.opt_arg ());
break;
case '?':
default:
ACE_ERROR_RETURN ((LM_ERROR,
"usage: %s %s"
"\n",
argv [0],
"-s <rms|muf>"),
-1);
}
// Indicates successful parsing of the command line
return 0;
}
|