summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Event/Timer_Module.h
blob: 6e0c39fc0e234f5d16a924bd176ade7abcbb6c0b (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
/* -*- C++ -*- */
//
// $Id$
//

#if !defined(TAO_EC_TIMER_MODULE_H)
#define TAO_EC_TIMER_MODULE_H

#include "ace/ACE.h"
#include "orbsvcs/Event_Service_Constants.h"
#include "orbsvcs/orbsvcs/Event/RT_Task.h"

class TAO_ORBSVCS_Export TAO_EC_Timer_Module
{
  // = TITLE
  //   The timer managment module.
  //
  // = DESCRIPTION
  //   The Event Channel can use several strategies to dispatch
  //   timers, for instance, it can use the ORB reactor or a pool of
  //   reactors running at different priorities or a pool of
  //   Thread_Timer_Queue_Adapters running at different priorities
  //   also.
  //   This class is the abstract base class to abstract this
  //   strategies.
  //
public:
  virtual ~TAO_EC_Timer_Module (void);
  // The dtor

  virtual void activate (void) = 0;
  // Activate the threads, it waits until the threads are up and
  // running.

  virtual void shutdown (void) = 0;
  // Deactivate the threads, it waits until all the threads have
  // terminated.

  virtual RtecScheduler::handle_t
     rt_info (RtecScheduler::OS_Priority priority) = 0;
  // The RT_Info handle for the "task" at <priority>

  virtual int schedule_timer (RtecScheduler::Preemption_Priority priority,
                              ACE_Event_Handler* eh,
                              void* act,
                              const ACE_Time_Value& delta,
                              const ACE_Time_Value& interval) = 0;
  // Add a timer at the given priority, returns the timer ID.

  virtual int cancel_timer (RtecScheduler::Preemption_Priority priority,
                            int id,
                            const void*& act) = 0;
  // Add a timer at the given priority.

  virtual int register_handler (RtecScheduler::Preemption_Priority priority,
				ACE_Event_Handler* eh,
				ACE_HANDLE handle) = 0;
  // Register a handler?????

  virtual ACE_Reactor* reactor (RtecScheduler::Preemption_Priority priority) = 0;
  // Obtain the reactor for the given priority.
  // @@ This may prove tricky to implement with timer queues not based
  // on reactors.
};

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

class TAO_ORBSVCS_Export TAO_EC_ST_Timer_Module : public TAO_EC_Timer_Module
{
  // = TITLE
  //   A single threaded implementation for the timer module.
  //
  // = DESCRIPTION
  //   This timer module uses a single Reactor to implement the timer,
  //   usually the ORB reactor is used for this purposes.
  //
public:
  TAO_EC_ST_Timer_Module (ACE_Reactor* reactor);
  // The ctor.

  virtual ~TAO_EC_ST_Timer_Module (void);
  // The dtor

  // = The TAO_EC_Timer_Module methods.
  virtual void activate (void);
  virtual void shutdown (void);
  virtual RtecScheduler::handle_t
     rt_info (RtecScheduler::Preemption_Priority priority);
  virtual int schedule_timer (RtecScheduler::Preemption_Priority priority,
                              ACE_Event_Handler* eh,
                              void* act,
                              const ACE_Time_Value& delta,
                              const ACE_Time_Value& interval);
  virtual int cancel_timer (RtecScheduler::Preemption_Priority priority,
                            int id,
                            const void*& act);
  virtual int register_handler (RtecScheduler::Preemption_Priority priority,
				ACE_Event_Handler* eh,
				ACE_HANDLE handle);
  virtual ACE_Reactor* reactor (RtecScheduler::Preemption_Priority priority);

private:
  ACE_Reactor* reactor_;
  // The reactor.
};

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

class ACE_ES_Reactor_Task;

class TAO_ORBSVCS_Export TAO_EC_RPT_Timer_Module : public TAO_EC_Timer_Module
{
  //
  // = TITLE
  //   A timer module using reactor-per-thread.
  //
  // = DESCRIPTION
  //   This Timer Module uses a pool of ACE_ReactorTask to handle the
  //   dispatching of timeouts. In real-time multi-threaded enviroments
  //   each Reactor runs at a different priority.
  //
public:
  TAO_EC_RPT_Timer_Module (void);
  // Create the Timer Module

  virtual ~TAO_EC_RPT_Timer_Module (void);
  // The dtor also shutdowns the Task_Manager.

  typedef ACE_ES_Reactor_Task ReactorTask;

  ReactorTask* GetReactorTask(RtecScheduler::Preemption_Priority priority);
  // Obtain the ReactorTask for the given priority.
  // The Task must have been created already.

  ACE_RT_Thread_Manager* ThrMgr();
  // Returns a global ThreadManager for the Task pool.

  // = The TAO_EC_Timer_Module methods.
  virtual void activate (void);
  virtual void shutdown (void);
  virtual RtecScheduler::handle_t
     rt_info (RtecScheduler::Preemption_Priority priority);
  virtual int schedule_timer (RtecScheduler::Preemption_Priority priority,
                              ACE_Event_Handler* eh,
                              void* act,
                              const ACE_Time_Value& delta,
                              const ACE_Time_Value& interval);
  virtual int cancel_timer (RtecScheduler::Preemption_Priority priority,
                            int id,
                            const void*& act);
  virtual int register_handler (RtecScheduler::Preemption_Priority priority,
				ACE_Event_Handler* eh,
				ACE_HANDLE handle);
  virtual ACE_Reactor* reactor (RtecScheduler::Preemption_Priority priority);
  
private:
  int shutdown_;
  // The reactors are shutdown, do not attempt to restart them.
  
  ReactorTask *reactorTasks[ACE_Scheduler_MAX_PRIORITIES];
  // The set of ReactorTasks

  ACE_RT_Thread_Manager thr_mgr;
  // The thread manager.
};

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

#endif /* TAO_EC_TIMER_MODULE_H */