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

#include "orbsvcs/orbsvcs/Event/ReactorTask.h"
#include "orbsvcs/orbsvcs/Event/Timer_Module.h"

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

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

// ****************************************************************

TAO_EC_Timer_Module::~TAO_EC_Timer_Module (void)
{
}

// ****************************************************************

TAO_EC_ST_Timer_Module::TAO_EC_ST_Timer_Module (ACE_Reactor* r)
  :  reactor_ (r)
{
}

TAO_EC_ST_Timer_Module::~TAO_EC_ST_Timer_Module (void)
{
}

void
TAO_EC_ST_Timer_Module::activate (void)
{
}

void
TAO_EC_ST_Timer_Module::shutdown (void)
{
}

RtecScheduler::handle_t
TAO_EC_ST_Timer_Module::rt_info (RtecScheduler::Preemption_Priority)
{
  // @@ TODO......
  return 0;
}

int
TAO_EC_ST_Timer_Module::schedule_timer (RtecScheduler::Preemption_Priority,
                                        ACE_Event_Handler* eh,
                                        void* act,
                                        const ACE_Time_Value& delta,
                                        const ACE_Time_Value& interval)
{
  return this->reactor_->schedule_timer (eh, act, delta, interval);
}

int
TAO_EC_ST_Timer_Module::cancel_timer (RtecScheduler::Preemption_Priority,
                                      int id,
                                      const void*& act)
{
  return this->reactor_->cancel_timer (id, &act);
}

int
TAO_EC_ST_Timer_Module::register_handler (RtecScheduler::Preemption_Priority,
                                          ACE_Event_Handler* eh,
                                          ACE_HANDLE handle)
{
  return this->reactor_->register_handler (eh, handle);
}

ACE_Reactor*
TAO_EC_ST_Timer_Module::reactor (RtecScheduler::Preemption_Priority)
{
  return this->reactor_;
}

// ****************************************************************

TAO_EC_RPT_Timer_Module::TAO_EC_RPT_Timer_Module (void)
  : shutdown_ (0)
{
  for (int i = 0; i < ACE_Scheduler_MAX_PRIORITIES; ++i)
    this->reactorTasks[i] = 0;
}

TAO_EC_RPT_Timer_Module::~TAO_EC_RPT_Timer_Module (void)
{
  this->shutdown ();

  for (int i = 0; i < ACE_Scheduler_MAX_PRIORITIES; ++i)
    {
      if (this->reactorTasks[i] != 0)
	{
	  delete this->reactorTasks[i];
	  this->reactorTasks[i] = 0;
	}
    }
}

void TAO_EC_RPT_Timer_Module::activate (void)
{
  for (int i = 0; i < ACE_Scheduler_MAX_PRIORITIES; ++i)
    {
      if (this->reactorTasks[i] != 0)
	continue;

      // Convert ACE_Scheduler_Rate (it's really a period, not a rate!)
      // to a form we can easily work with.
      ACE_Time_Value period_tv;
      ORBSVCS_Time::TimeT_to_Time_Value (period_tv, ACE_Scheduler_Rates[i]);

      RtecScheduler::Period period = period_tv.sec () * 10000000 +
                                     period_tv.usec () * 10;

      ACE_NEW (this->reactorTasks[i], ReactorTask);

      if (!this->shutdown_)
	{
	  this->reactorTasks[i]->thr_mgr (this->ThrMgr ());
	  if (this->reactorTasks[i]->open_reactor (period) == -1)
	    {
	      ACE_ERROR ((LM_ERROR, "%p\n",
			  "EC (%t) Timer_Module - open reactor"));
	    }
	}
    }
}

void
TAO_EC_RPT_Timer_Module::shutdown (void)
{
  if (this->shutdown_)
    return;

  this->shutdown_ = 1;
  for (int i = 0; i < ACE_Scheduler_MAX_PRIORITIES; ++i)
    {
      if (this->reactorTasks[i] != 0)
	this->reactorTasks[i]->shutdown_task ();
    }

  if (this->ThrMgr ()->wait () == -1)
    ACE_ERROR ((LM_DEBUG, "%p\n", "EC (%t) Timer_Module wait"));
}

RtecScheduler::handle_t
TAO_EC_RPT_Timer_Module::rt_info (RtecScheduler::Preemption_Priority priority)
{
  return this->GetReactorTask (priority)->rt_info ();
}

int
TAO_EC_RPT_Timer_Module::schedule_timer (RtecScheduler::Preemption_Priority priority,
                                         ACE_Event_Handler* eh,
                                         void* act,
                                         const ACE_Time_Value& delta,
                                         const ACE_Time_Value& interval)
{
  return this->GetReactorTask (priority)->get_reactor ().schedule_timer (eh, act, delta, interval);
}

int
TAO_EC_RPT_Timer_Module::cancel_timer (RtecScheduler::Preemption_Priority priority,
                                       int id,
                                       const void*& act)
{
  return this->GetReactorTask (priority)->get_reactor ().cancel_timer (id, &act);
}

int
TAO_EC_RPT_Timer_Module::register_handler (RtecScheduler::Preemption_Priority priority,
                                           ACE_Event_Handler* eh,
                                           ACE_HANDLE handle)
{
  return this->GetReactorTask (priority)->get_reactor ().register_handler (eh, handle);
}

ACE_Reactor*
TAO_EC_RPT_Timer_Module::reactor (RtecScheduler::Preemption_Priority priority)
{
  return &this->GetReactorTask (priority)->get_reactor ();
}