summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Event/ReactorTask.cpp
blob: ca449ff4800eea1bd24a97977318684440bfdfe7 (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
// $Id$

#include "ace/High_Res_Timer.h"
#include "tao/Timeprobe.h"
#include "orbsvcs/orbsvcs/Scheduler_Factory.h"

#include "ReactorTask.h"

ACE_RCSID (Event, 
           ReactorTask, 
           "$Id$")

#if defined (ACE_ENABLE_TIMEPROBES)

static const char *TAO_Reactor_Task_Timeprobe_Description[] =
{
  "Reactor_Task - waiting for events",
  "Reactor_Task - events handled"
};

enum
{
  // Timeprobe description table start key
  TAO_REACTOR_TASK_WAITING_FOR_EVENTS = 5300,
  TAO_REACTOR_TASK_EVENTS_HANDLED
};

// Setup Timeprobes
ACE_TIMEPROBE_EVENT_DESCRIPTIONS (TAO_Reactor_Task_Timeprobe_Description,
                                  TAO_REACTOR_TASK_WAITING_FOR_EVENTS);

#endif /* ACE_ENABLE_TIMEPROBES */

ACE_ES_Reactor_Task::
    ACE_ES_Reactor_Task (RtecScheduler::Scheduler_ptr scheduler)
      :  ACE_RT_Task (scheduler),
         //  reactor_ (0, &timer_queue_),
         done_ (0)
{
  // Change the timer mechanism used by the reactor and the timer
  // queue.
  timer_queue_.gettimeofday (ACE_OS::gettimeofday);
}

ACE_ES_Reactor_Task::~ACE_ES_Reactor_Task (void)
{
}

int
ACE_ES_Reactor_Task::svc_hook(RtecScheduler::OS_Priority)
{
  // Make ourselves owner of the reactor.
  reactor_.owner (ACE_Thread::self());
  return 0;
}

int
ACE_ES_Reactor_Task::open_reactor (RtecScheduler::Period_t &period)
{
  // Create a name for ourselves using the period.  The period is
  // in 100 ns units; first convert to usec by dividing by 10.
  char temp[64];
  ACE_OS::sprintf (temp, "Reactor_Task-%u.us", period / 10);

  // Open the task.  This will query the scheduler for our qos
  // structure.
  int result = this->open_task (temp);

  switch (result)
    {
    case -1:
      // Error.
      ACE_ERROR ((LM_ERROR, "(%t) Scheduler could not find operation %s.\n",
                  temp));
      return -1;

    case 0:
      // @@ TODO handle exceptions
      {
        ACE_DECLARE_NEW_CORBA_ENV;
        ACE_TRY
          {
#if 1
            this->scheduler_->set
              (rt_info_,
               RtecScheduler::VERY_HIGH_CRITICALITY,
               ORBSVCS_Time::zero (),
               ORBSVCS_Time::zero (),
               ORBSVCS_Time::zero (),
               period,
               RtecScheduler::VERY_LOW_IMPORTANCE,
               ORBSVCS_Time::zero (),
               1,
               RtecScheduler::OPERATION
                ACE_ENV_ARG_PARAMETER);
#else
            ACE_Scheduler_Factory::server()->set
              (rt_info_,
               RtecScheduler::VERY_HIGH_CRITICALITY,
               ORBSVCS_Time::zero (),
               ORBSVCS_Time::zero (),
               ORBSVCS_Time::zero (),
               period,
               RtecScheduler::VERY_LOW_IMPORTANCE,
               ORBSVCS_Time::zero (),
               1,
               RtecScheduler::OPERATION
                ACE_ENV_ARG_PARAMETER);
#endif
            ACE_TRY_CHECK;
          }
        ACE_CATCHANY
          {
            ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                                 "set failed\n");
          }
        ACE_ENDTRY;
      }
      break;

    case 1:
      // Found.
      break;
    }

  return this->synch_threads (1);
}

int ACE_ES_Reactor_Task::svc_one()
{
  ACE_TIMEPROBE (" Reactor_Task - waiting for events");
  if (reactor_.handle_events() == -1)
    ACE_ERROR ((LM_ERROR, "(%t) %p.\n", "ACE_ES_Reactor_Task::svc"));
  ACE_TIMEPROBE (" Reactor_Task - events handled");

  if (done_)
    ACE_DEBUG ((LM_DEBUG, "EC (%t) Timer Task is done.\n"));

  return done_;
}

void ACE_ES_Reactor_Task::threads_closed()
{
}

void ACE_ES_Reactor_Task::shutdown_task()
{
  done_ = 1;
  reactor_.notify();
}

ACE_ES_Reactor_Task::Reactor&
ACE_ES_Reactor_Task::get_reactor()
{
  return reactor_;
}