summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Scheduler_Factory.cpp
blob: a4b7171a69751c5f8c2d59d19c3d199c5701b38d (plain)
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
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
// $Id$

#include "ace/OS.h"
#include "ace/Singleton.h"
#include "ace/Null_Mutex.h"

#include "orbsvcs/Runtime_Scheduler.h"
#include "orbsvcs/Sched/Reconfig_Scheduler.h"
#include "orbsvcs/Sched/Reconfig_Sched_Utils.h"
#include "orbsvcs/Scheduler_Factory.h"

#if ! defined (__ACE_INLINE__)
#include "orbsvcs/Scheduler_Factory.i"
#endif /* __ACE_INLINE__ */

ACE_RCSID(orbsvcs,
          Scheduler_Factory,
          "$Id$")

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

// Initialize static class members.
RtecScheduler::Scheduler_ptr ACE_Scheduler_Factory::server_ = 0;
ACE_Scheduler_Factory::Factory_Status ACE_Scheduler_Factory::status_ =
  ACE_Scheduler_Factory::UNINITIALIZED;


RtecScheduler::Period_t ACE_Scheduler_Factory::period_default_ = 0;
RtecScheduler::Threads_t ACE_Scheduler_Factory::threads_default_ = 0;
RtecScheduler::Importance_t ACE_Scheduler_Factory::importance_default_ = RtecScheduler::MEDIUM_IMPORTANCE;
RtecScheduler::Criticality_t ACE_Scheduler_Factory::criticality_default_ = RtecScheduler::HIGH_CRITICALITY;
RtecScheduler::RT_Info_Enabled_Type_t ACE_Scheduler_Factory::rt_info_enable_state_default_ = RtecScheduler::RT_INFO_NON_VOLATILE;

RtecScheduler::Period_t ACE_Scheduler_Factory::period_default()
{
   return period_default_;
}

RtecScheduler::Threads_t ACE_Scheduler_Factory::threads_default()
{
   return threads_default_;
}

RtecScheduler::Importance_t ACE_Scheduler_Factory::importance_default()
{
   return importance_default_;
}

RtecScheduler::Criticality_t ACE_Scheduler_Factory::criticality_default()
{
   return criticality_default_;
}

void ACE_Scheduler_Factory::period_default(RtecScheduler::Period_t period_default)
{
   period_default_ = period_default;
}

void ACE_Scheduler_Factory::threads_default(RtecScheduler::Threads_t threads_default)
{
   threads_default_ = threads_default;
}

void ACE_Scheduler_Factory::importance_default(RtecScheduler::Importance_t importance_default)
{
   importance_default_ = importance_default;
}

void ACE_Scheduler_Factory::criticality_default(RtecScheduler::Criticality_t criticality_default)
{
   criticality_default_ = criticality_default;
}

RtecScheduler::RT_Info_Enabled_Type_t ACE_Scheduler_Factory::rt_info_enable_state_default()
{
   return rt_info_enable_state_default_;
}

void ACE_Scheduler_Factory::rt_info_enable_state_default(RtecScheduler::RT_Info_Enabled_Type_t rt_info_enable_state_default)
{
   rt_info_enable_state_default_ = rt_info_enable_state_default;
}

// This symbols are extern because the automatic template
// instantiation mechanism in SunCC gets confused otherwise.
int TAO_SF_config_count = -1;
ACE_Scheduler_Factory::POD_Config_Info* TAO_SF_config_info = 0;
int TAO_SF_entry_count = -1;
ACE_Scheduler_Factory::POD_RT_Info* TAO_SF_rt_info = 0;
int TAO_SF_dependency_count = -1;
ACE_Scheduler_Factory::POD_Dependency_Info* TAO_SF_dep_info = 0;

struct ACE_Scheduler_Factory_Data
{
  // = TITLE
  //   Helper struct, to encapsulate the singleton static server and
  //   ACE_TSS objects.  We can't use ACE_Singleton directly, because
  //   construction of ACE_Runtime_Scheduler takes arguments.

/* WSOA merge - commented out
  ACE_Runtime_Scheduler scheduler_;
  // The static runtime scheduler.
*/

  TAO_Reconfig_Scheduler<TAO_MUF_FAIR_Reconfig_Sched_Strategy, ACE_SYNCH_MUTEX> scheduler_;
  // The scheduler.

  ACE_TSS<ACE_TSS_Type_Adapter<RtecScheduler::Preemption_Priority_t> >
  preemption_priority_;
  // The dispatch queue number of the calling thread.  For access by
  // applications; must be set by either the application or Event
  // Channel.

  ACE_Scheduler_Factory_Data (void)
    : scheduler_ (TAO_SF_config_count,
                  TAO_SF_config_info,
                  TAO_SF_entry_count,
                  TAO_SF_rt_info,
                  TAO_SF_dependency_count,
                  TAO_SF_dep_info,
                  0),
      preemption_priority_ ()
  {
  }
};

static ACE_Scheduler_Factory_Data *ace_scheduler_factory_data = 0;

int ACE_Scheduler_Factory::use_runtime (int cc,
                                        POD_Config_Info cfgi[],
                                        int ec,
                                        POD_RT_Info rti[])
{
  if (server_ != 0 || TAO_SF_entry_count != -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT("ACE_Scheduler_Factory::use_runtime - ")
                       ACE_TEXT("server already configured\n")),
                      -1);
  TAO_SF_config_count = cc;
  TAO_SF_config_info = cfgi;
  TAO_SF_entry_count = ec;
  TAO_SF_rt_info = rti;
  status_ = ACE_Scheduler_Factory::RUNTIME;

  return 0;
}

static RtecScheduler::Scheduler_ptr
static_server (void)
{
  RtecScheduler::Scheduler_ptr server_ = 0;

  // This isn't thread safe, but the static instance that it replaces
  // wasn't thread safe either.  Hola, Sr. Sandiego :-) If it needs to
  // be made thread safe, it should be protected using double-checked
  // locking.
  if (! ace_scheduler_factory_data  &&
      (ace_scheduler_factory_data =
         ACE_Singleton<ACE_Scheduler_Factory_Data,
                       ACE_Null_Mutex>::instance ()) == 0)
        return 0;

  ACE_DECLARE_NEW_CORBA_ENV;
  ACE_TRY
    {
      server_ = ace_scheduler_factory_data->scheduler_._this (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_TRY_CHECK;

      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT("ACE_Scheduler_Factory - configured static server\n")));
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                           ACE_TEXT("ACE_Scheduler_Factory::config_runtime - ")
                           ACE_TEXT("cannot allocate server\n"));
    }
  ACE_ENDTRY;

  return server_;
}

int
ACE_Scheduler_Factory::use_config (CosNaming::NamingContext_ptr naming)
{
  return ACE_Scheduler_Factory::use_config (naming,
                                            "ScheduleService");
}

int
ACE_Scheduler_Factory::use_config (CosNaming::NamingContext_ptr naming,
                                   const char* name)
{
  if (server_ != 0 || TAO_SF_entry_count != -1)
    // No errors, runtime execution simply takes precedence over
    // config runs.
    return 0;

  ACE_DECLARE_NEW_CORBA_ENV;
  ACE_TRY
    {
      CosNaming::Name schedule_name (1);
      schedule_name.length (1);
      schedule_name[0].id = CORBA::string_dup (name);
      CORBA::Object_var objref =
        naming->resolve (schedule_name
                         ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      server_ =
        RtecScheduler::Scheduler::_narrow(objref.in ()
                                          ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;
    }
  ACE_CATCHANY
    {
      server_ = 0;
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                           ACE_TEXT("ACE_Scheduler_Factory::use_config - ")
                           ACE_TEXT(" exception while resolving server\n"));
    }
  ACE_ENDTRY;

  status_ = ACE_Scheduler_Factory::CONFIG;
  return 0;
}

int
ACE_Scheduler_Factory::server (RtecScheduler::Scheduler_ptr sptr)
{
  if (server_ != 0 || TAO_SF_entry_count != -1)
    return -1;

  server_ = RtecScheduler::Scheduler::_duplicate (sptr);
  return 0;
}

RtecScheduler::Scheduler_ptr
ACE_Scheduler_Factory::server (void)
{
  if (server_ == 0 && TAO_SF_entry_count != -1)
    server_ = static_server ();

  if (server_ == 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT("ACE_Scheduler_Factor::server - ")
                       ACE_TEXT("no scheduling service configured\n")),
                      0);
  return server_;
}

static char header[] =
"// $Id $\n\n"
"// This file was automatically generated by the Scheduler_Factory.\n"
"// Before editing the file please consider generating it again.\n"
"\n"
"#include \"orbsvcs/Scheduler_Factory.h\"\n"
"\n";

static char footer[] =
"\n"
"// This sets up Scheduler_Factory to use the runtime version.\n"
"int scheduler_factory_setup = \n"
"  ACE_Scheduler_Factory::use_runtime (configs_size, configs, infos_size, infos);\n"
"\n"
"// EOF\n";

static char start_anomalies_found[] =
"\n// The following scheduling anomalies were detected:\n";

static char start_anomalies_none[] =
"\n// There were no scheduling anomalies.\n";

static char start_infos[] =
"\n\nstatic ACE_Scheduler_Factory::POD_RT_Info infos[] = {\n";

static char end_infos[] =
"};\n\n"
"static int infos_size = sizeof(infos)/sizeof(infos[0]);\n\n";

static char end_infos_empty[] =
"};\n\n"
"static int infos_size = 0;\n\n";

static char start_dependencies[] =
"\n\nstatic ACE_Scheduler_Factory::POD_Dependency_Info dependencies[] = {\n";

static char end_dependencies[] =
"};\n\n"
"static int dependencies_size = sizeof(dependencies)/sizeof(dependencies[0]);\n\n";

static char end_dependencies_empty[] =
"};\n\n"
"static int dependencies_size = 0;\n\n";

static char start_configs[] =
"\nstatic ACE_Scheduler_Factory::POD_Config_Info configs[] = {\n";

static char end_configs[] =
"};\n\n"
"static int configs_size = sizeof(configs)/sizeof(configs[0]);\n\n";

static char end_configs_empty[] =
"};\n\n"
"static int configs_size = 0;\n\n";

int ACE_Scheduler_Factory::dump_schedule
   (const RtecScheduler::RT_Info_Set& infos,
    const RtecScheduler::Dependency_Set& dependencies,
    const RtecScheduler::Config_Info_Set& configs,
    const RtecScheduler::Scheduling_Anomaly_Set& anomalies,
    const char* file_name,
    const char* rt_info_format,
    const char* dependency_format,
    const char* config_info_format,
    int dump_disabled_infos,
    int dump_disabled_dependencies)
{
  u_int i;
  char entry_point [BUFSIZ];

  // Default format for printing RT_Info output.
  if (rt_info_format == 0)
    rt_info_format = "{%20s, /* entry_point */\n"
                     "%10d, /* handle */\n"
                     "%10d, /* worst_case_execution_time */,\n"
                     "%10d, /* typical_execution_time */,\n"
                     "%10d, /* cached_execution_time */,\n"
                     "%10d, /* period */\n"
                     "(RtecScheduler::Criticality_t) %d, /* [ VL_C = 0, L_C = 1, M_C = 2, H_C = 3, VH_C = 4] */\n"
                     "(RtecScheduler::Importance_t) %d, /* [ VL_I = 0, L_I = 1, M_I = 2, H_I = 3, VH_I = 4] */\n"
                     "%10d, /* quantum */\n"
                     "%10d, /* threads */\n"
                     "%10d, /* priority */\n"
                     "%10d, /* preemption_subpriority */\n"
                     "%10d, /* preemption_priority */\n"
                     "(RtecScheduler::Info_Type_t) %d, /* [OPERATION = 0, CONJUNCTION = 1, DISJUNCTION = 2, REMOTE_DEPENDANT = 3] */\n"
                     "(RtecScheduler::RT_Info_Enabled_Type_t) %d } /* [RT_INFO_DISABLED = 0, RT_INFO_ENABLED = 1, RT_INFO_NON_VOLATILE = 2] */\n";


  // Default format for printing dependency output.
  if (dependency_format == 0)
      dependency_format = "  { (RtecScheduler::Dependency_Type_t) %d, %10d, "
                          "%10d, %10d,"
                          "(RtecScheduler::Dependency_Enabled_Type_t) %d }";

  // Default format for printing Config_Info output.
  if (config_info_format == 0)
    config_info_format = "  { %10d, %10d, "
                         "(RtecScheduler::Dispatching_Type_t) %d }";

  FILE* file = stdout;
  if (file_name != 0)
    {
      file = ACE_OS::fopen (ACE_TEXT_TO_TCHAR_IN(file_name), ACE_TEXT("w"));
      if (file == 0)
          return -1;
    }
  ACE_OS::fprintf (file, header);

  // Indicate anomalies encountered during scheduling.

  ACE_OS::fprintf(file, (anomalies.length () > 0
                         ? start_anomalies_found
                         : start_anomalies_none));

  for (i = 0; i < anomalies.length (); ++i)
    {
      const RtecScheduler::Scheduling_Anomaly& anomaly = anomalies[i];
      switch (anomaly.severity)
        {
          case RtecScheduler::ANOMALY_FATAL:
            ACE_OS::fprintf(file, "FATAL: ");
            break;

          case RtecScheduler::ANOMALY_ERROR:
            ACE_OS::fprintf(file, "ERROR: ");
            break;

          case RtecScheduler::ANOMALY_WARNING:
            ACE_OS::fprintf(file, "// WARNING: ");
            break;

          default:
            ACE_OS::fprintf(file, "// UNKNOWN: ");
            break;
        }

      ACE_OS::fprintf (file,
                       "%s\n",
                       (const char *) anomaly.description);
    }

  // Print out banner indicating which infos are dumped.
  if (dump_disabled_infos)
    {
      ACE_OS::fprintf (file, "\n// Both enabled and disabled RT_Infos were dumped to this file.\n\n");
    }
  else
    {
      ACE_OS::fprintf (file, "\n// Only enabled RT_Infos were dumped to this file.\n\n");
    }

  // Print out operation QoS info.
  ACE_OS::fprintf (file, start_infos);

  for (i = 0;
       i < infos.length ();
       ++i)
    {
      const RtecScheduler::RT_Info& info = infos[i];

      if (dump_disabled_infos
          || info.enabled == RtecScheduler::RT_INFO_ENABLED
          || info.enabled == RtecScheduler::RT_INFO_NON_VOLATILE)
        {
      if (i != 0)
        // Finish previous line.
        ACE_OS::fprintf(file, ",\n");

      const RtecScheduler::RT_Info& info = infos[i];

      // Put quotes around the entry point name, exactly as it is stored.
      ACE_OS::sprintf (entry_point,
                       "\"%s\"",
                       (const char *) info.entry_point);

      // @@ TODO Eventually the TimeT structure will be a 64-bit
      // unsigned int, we will have to change this dump method then.
      ACE_OS::fprintf (file,
                       rt_info_format,
                       entry_point,
                       info.handle,
                       ACE_CU64_TO_CU32 (info.worst_case_execution_time),
                       ACE_CU64_TO_CU32 (info.typical_execution_time),
                       ACE_CU64_TO_CU32 (info.cached_execution_time),
                       info.period,
                       info.criticality,
                       info.importance,
                       ACE_CU64_TO_CU32 (info.quantum),
                       info.threads,
                       info.priority,
                       info.preemption_subpriority,
                           info.preemption_priority,
                           info.info_type,
                           info.enabled);
    }
    }

  // Finish last line.
  ACE_OS::fprintf(file, "\n");

  if (infos.length () > 0)
    ACE_OS::fprintf (file, end_infos);
  else
    ACE_OS::fprintf (file, end_infos_empty);

  // Print out banner indicating which dependencies are dumped.
  if (dump_disabled_dependencies)
    {
      ACE_OS::fprintf (file, "\n// Both enabled and disabled dependencies were dumped to this file.\n\n");
    }
  else
    {
      ACE_OS::fprintf (file, "\n// Only enabled dependencies were dumped to this file.\n\n");
    }

  // Print out operation dependency info.
  ACE_OS::fprintf (file, start_dependencies);

  for (i = 0;
       i < dependencies.length ();
       ++i)
    {
      const RtecScheduler::Dependency_Info& dep = dependencies[i];

      if (dump_disabled_infos
          || dep.enabled == RtecBase::DEPENDENCY_ENABLED
          || dep.enabled == RtecBase::DEPENDENCY_NON_VOLATILE)
        {
          // Finish previous line.
          if (i != 0)
            {
              ACE_OS::fprintf (file, ",\n");
            }

          ACE_OS::fprintf (file,
                           dependency_format,
                           dep.dependency_type,
                           dep.number_of_calls,
                           dep.rt_info,
                           dep.rt_info_depended_on,
                           dep.enabled);
        }
    }

  // Finish last line.
  ACE_OS::fprintf (file, "\n");

  if (dependencies.length () > 0)
    ACE_OS::fprintf (file, end_dependencies);
  else
    ACE_OS::fprintf (file, end_dependencies_empty);


  // Print out queue configuration info.
  ACE_OS::fprintf (file, start_configs);

  for (i = 0;
       i < configs.length ();
       ++i)
    {
      if (i != 0)
        // Finish previous line.
        ACE_OS::fprintf (file, ",\n");

      const RtecScheduler::Config_Info& config = configs[i];
      ACE_OS::fprintf (file,
                       config_info_format,
                       config.preemption_priority,
                       config.thread_priority,
                       config.dispatching_type);
    }

  // Finish last line.
  ACE_OS::fprintf (file, "\n");

  if (configs.length () > 0)
    ACE_OS::fprintf (file, end_configs);
  else
    ACE_OS::fprintf (file, end_configs_empty);

  ACE_OS::fprintf (file, footer);
  ACE_OS::fclose (file);
  return 0;
}

void ACE_Scheduler_Factory::log_scheduling_entry(TAO_Reconfig_Scheduler_Entry * entry, FILE* file)
{

   if( entry == 0 )
   {
      ACE_OS::fprintf (file, "Entry is NULL");
      return;
   }

   // Print out the actual rt_info data
   const char* rt_info_format = "{%20s, /* entry_point */\n"
                                 "%10d, /* handle */\n"
                                 "%10d, /* period */\n"
                                 "%10d, /* criticality */\n"
                                 "%10d, /* threads */\n"
                                 "%10d, /* priority */\n"
                                 "%10d, /* preemption_subpriority */\n"
                                 "%10d, /* preemption_priority */\n"
                                 "%10d  /* enabled */\n";

   TAO_RT_Info_Ex* actual_info = entry->actual_rt_info();

   ACE_OS::fprintf (file,
                    rt_info_format,
                    actual_info->entry_point.in(),
                    actual_info->handle,
                    actual_info->period,
                    actual_info->criticality,
                    actual_info->threads,
                    actual_info->priority,
                    actual_info->preemption_subpriority,
                    actual_info->preemption_priority,
                    actual_info->enabled);


   // Print out the current admitted tuple
   const char* admitted_tuple_format = "             {"
                                       "%13d, /* handle */\n"
                                       "%13d, /* rate_index */\n"
                                       "%13d, /* period */\n"
                                       "%13d, /* criticality */\n"
                                       "%13d, /* priority */\n"
                                       "%13d, /* preemption_subpriority */\n"
                                       "%13d, /* preemption_priority */\n"
                                       "%13d } /* enabled */\n";

   TAO_RT_Info_Tuple* current_admitted_tuple = entry->current_admitted_tuple();

   ACE_OS::fprintf(file, "\n   Current admitted Tuple:\n");
   if( current_admitted_tuple == 0 )
   {
      ACE_OS::fprintf (file, "   =>NONE_ADMITTED\n");
   }
   else
   {
      ACE_OS::fprintf (file,
                       admitted_tuple_format,
                       current_admitted_tuple->handle,
                       current_admitted_tuple->rate_index,
                       current_admitted_tuple->period,
                       current_admitted_tuple->criticality,
                       current_admitted_tuple->priority,
                       current_admitted_tuple->preemption_subpriority,
                       current_admitted_tuple->preemption_priority,
                       current_admitted_tuple->enabled);
   }

   // Print out the orig_tuple_subset_
   ACE_OS::fprintf(file, "\n      Original Tuple Subset\n   {\n");
   log_tuple_subset(entry->orig_tuple_subset(), file);
   ACE_OS::fprintf(file, "\n   }");

   // Print out the prop_tuple_subset_
   ACE_OS::fprintf(file, "\n      Propagated Tuple Subset\n   {\n");
   log_tuple_subset(entry->prop_tuple_subset(), file);
   ACE_OS::fprintf(file, "\n   }\n}");


}

void ACE_Scheduler_Factory::log_tuple_subset(TUPLE_SET & tuple_subset,
                      FILE* file)
{
   TAO_RT_Info_Tuple **tuple_ptr_ptr;
   const char* subset_tuple_format = "             {\n"
                                     "%13d, /* handle */\n"
                                     "%13d, /* rate_index */\n"
                                     "%13d, /* period */\n"
                                     "%13d, /* criticality */\n"
                                     "%13d, /* threads */\n"
                                     "%13d, /* priority */\n"
                                     "%13d, /* preemption_subpriority */\n"
                                     "%13d, /* preemption_priority */\n"
                                     "%13d } /* enabled */\n";

   TUPLE_SET_ITERATOR
      tuple_iter (tuple_subset);


   while (tuple_iter.done () == 0)
   {
      // Get a pointer to the tuple COPY under the iterator.
      if (tuple_iter.next (tuple_ptr_ptr) == 0
         || tuple_ptr_ptr == 0 || ((*tuple_ptr_ptr) == 0) )
      {
         ACE_OS::fprintf (file, "{ NULL TUPLE POINTER }\n");
      }
      else
      {

      ACE_OS::fprintf (file,
         subset_tuple_format,
         (*tuple_ptr_ptr)->handle,
         (*tuple_ptr_ptr)->rate_index,
         (*tuple_ptr_ptr)->period,
         (*tuple_ptr_ptr)->criticality,
         (*tuple_ptr_ptr)->threads,
         (*tuple_ptr_ptr)->priority,
         (*tuple_ptr_ptr)->preemption_subpriority,
         (*tuple_ptr_ptr)->preemption_priority,
         (*tuple_ptr_ptr)->enabled);
      }

      tuple_iter.advance ();
   }
}

int
ACE_Scheduler_Factory::log_scheduling_entries(TAO_Reconfig_Scheduler_Entry ** entry_ptr_array,
                                              long entry_ptr_array_size,
                                              const char* file_name)
{
   // Open the file
   FILE* file = stdout;
   if (file_name != 0)
   {
      file = ACE_OS::fopen (file_name, ACE_TEXT ("w"));
      if (file == 0)
        return -1;
    }


   // Iterate through the array.  The index is the (handle - 1) of the rt_info in the array
   for(int index = 0; index < entry_ptr_array_size; ++index)
   {
      ACE_OS::fprintf(file, "\n\nScheduler Entry Array contents\n");
      TAO_Reconfig_Scheduler_Entry * entry = entry_ptr_array[index];

      log_scheduling_entry(entry, file);


   }


   ACE_OS::fclose (file);
   return 0;

}

void
ACE_Scheduler_Factory::log_scheduling_tuples(
  TAO_RT_Info_Tuple ** tuple_ptr_array,
  long tuple_ptr_array_size,
  const char* file_name)
{
   // Open the file
   FILE* file = stdout;
   if (file_name != 0)
   {
      file = ACE_OS::fopen (file_name, ACE_TEXT ("w"));
      if (file == 0)
        return;
    }

   static const char subset_tuple_format[] =
     "             {\n"
     "%13d, /* handle */\n"
     "%13lu, /* rate_index */\n"
     "%13d, /* period */\n"
     "%13d, /* criticality */\n"
     "%13d, /* priority */\n"
     "%13d, /* preemption_subpriority */\n"
     "%13d, /* preemption_priority */\n"
     "%13d } /* enabled */\n";

   for (int ndx = 0; ndx < tuple_ptr_array_size; ndx++)
     {
       fprintf(file,
               subset_tuple_format,
               tuple_ptr_array[ndx]->handle,
               tuple_ptr_array[ndx]->rate_index,
               tuple_ptr_array[ndx]->period,
               tuple_ptr_array[ndx]->criticality,
               tuple_ptr_array[ndx]->priority,
               tuple_ptr_array[ndx]->preemption_subpriority,
               tuple_ptr_array[ndx]->preemption_priority,
               tuple_ptr_array[ndx]->enabled);
     }

   ACE_OS::fclose (file);
}
#if defined (HPUX) && !defined (__GNUG__)
  // aCC can't handle RtecScheduler::Preemption_Priority_t used as an operator
  // name.
  typedef CORBA::Long RtecScheduler_Preemption_Priority_t;
#endif /* HPUX && !g++ */

RtecScheduler::Preemption_Priority_t
ACE_Scheduler_Factory::preemption_priority (void)
{
  // Return whatever we've got.  The application or Event Channel is
  // responsible for making sure that it was set.
  if (ace_scheduler_factory_data->preemption_priority_.ts_object ())
    {
      ACE_TSS_Type_Adapter<RtecScheduler::Preemption_Priority_t> *tss =
        ace_scheduler_factory_data->preemption_priority_;
      // egcs 1.0.1 raises an internal compiler error if we implicitly
      // call the type conversion operator.  So, call it explicitly.
#if defined (HPUX) && !defined (__GNUG__)
      const RtecScheduler::Preemption_Priority_t preemption_priority =
        static_cast<RtecScheduler::Preemption_Priority_t> (tss->operator RtecScheduler_Preemption_Priority_t ());
#else
      const RtecScheduler::Preemption_Priority_t preemption_priority =
        static_cast<RtecScheduler::Preemption_Priority_t> (tss->operator RtecScheduler::Preemption_Priority_t ());
#endif /* HPUX && !g++ */
      return preemption_priority;
    }
  else
    return static_cast<RtecScheduler::Preemption_Priority_t> (-1);
}

void
ACE_Scheduler_Factory::set_preemption_priority
  (const RtecScheduler::Preemption_Priority_t preemption_priority)
{
  // Probably don't need this, because it should be safe to assume
  // that static_server () was called before this function.  But just
  // in case . . .
  if (!ace_scheduler_factory_data
      && (ace_scheduler_factory_data =
          ACE_Singleton<ACE_Scheduler_Factory_Data,
          ACE_Null_Mutex>::instance ()) == 0)
        return;

  ace_scheduler_factory_data->preemption_priority_->
#if defined (HPUX) && !defined (__GNUG__)
    // aCC can't handle the typedef.
    operator RtecScheduler_Preemption_Priority_t & () = preemption_priority;
#else
    operator RtecScheduler::Preemption_Priority_t & () = preemption_priority;
#endif /* HPUX && !g++ */
}

#if defined (ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION)
template ACE_Singleton<ACE_Scheduler_Factory_Data, ACE_Null_Mutex> *ACE_Singleton<ACE_Scheduler_Factory_Data, ACE_Null_Mutex>::singleton_;
#endif /* ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION */

TAO_END_VERSIONED_NAMESPACE_DECL