summaryrefslogtreecommitdiff
path: root/ACE/ace/Timer_Queue_Iterator.h
blob: d550397791bc3b7839c576d8be1aee2123afe4c6 (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
#ifndef ACE_TIMER_QUEUE_ITERATOR_H
#define ACE_TIMER_QUEUE_ITERATOR_H

#include /**/ "ace/pre.h"

/**
 * @file Timer_Queue_Iterator.h
 *
 * Re-factored from Timer_Queue_T.h
 */

#include "ace/Time_Value.h"

ACE_BEGIN_VERSIONED_NAMESPACE_DECL

/**
 * @class ACE_Timer_Node_Dispatch_Info_T
 *
 * @brief Maintains generated dispatch information for Timer nodes.
 */
template <class TYPE>
class ACE_Timer_Node_Dispatch_Info_T
{
public:
  /// The type of object held in the queue
  TYPE type_;

  /// Asynchronous completion token associated with the timer.
  const void *act_;

  /// Flag to check if the timer is recurring.
  int recurring_timer_;
};

/**
 * @class ACE_Timer_Node_T
 *
 * @brief Maintains the state associated with a Timer entry.
 */
template <class TYPE>
class ACE_Timer_Node_T
{
public:
  /// Default constructor
  ACE_Timer_Node_T ();

  /// Destructor
  ~ACE_Timer_Node_T ();

  /// Useful typedef ..
  typedef ACE_Timer_Node_Dispatch_Info_T <TYPE> DISPATCH_INFO;

  /// Singly linked list
  void set (const TYPE &type,
            const void *a,
            const ACE_Time_Value &t,
            const ACE_Time_Value &i,
            ACE_Timer_Node_T<TYPE> *n,
            long timer_id);

  /// Doubly linked list version
  void set (const TYPE &type,
            const void *a,
            const ACE_Time_Value &t,
            const ACE_Time_Value &i,
            ACE_Timer_Node_T<TYPE> *p,
            ACE_Timer_Node_T<TYPE> *n,
            long timer_id);

  // = Accessors

  /// Get the type.
  TYPE &get_type ();

  /// Set the type.
  void set_type (TYPE &type);

  /// Get the asynchronous completion token.
  const void *get_act ();

  /// Set the asynchronous completion token.
  void set_act (void *act);

  /// Get the timer value.
  const ACE_Time_Value &get_timer_value () const;

  /// Set the timer value.
  void set_timer_value (const ACE_Time_Value &timer_value);

  /// Get the timer interval.
  const ACE_Time_Value &get_interval () const;

  /// Set the timer interval.
  void set_interval (const ACE_Time_Value &interval);

  /// Get the previous pointer.
  ACE_Timer_Node_T<TYPE> *get_prev ();

  /// Set the previous pointer.
  void set_prev (ACE_Timer_Node_T<TYPE> *prev);

  /// Get the next pointer.
  ACE_Timer_Node_T<TYPE> *get_next ();

  /// Set the next pointer.
  void set_next (ACE_Timer_Node_T<TYPE> *next);

  /// Get the timer_id.
  long get_timer_id () const;

  /// Set the timer_id.
  void set_timer_id (long timer_id);

  /// Get the dispatch info. The dispatch information is got
  /// through @a info. This form helps us in preventing allocation and
  /// deleting data along the criticl path.
  /// @todo We may want to have a copying version too, so that our
  /// interface will be complete..
  void get_dispatch_info (ACE_Timer_Node_Dispatch_Info_T <TYPE> &info);

  /// Dump the state of an TYPE.
  void dump () const;

  /// Declare the dynamic allocation hooks.
  ACE_ALLOC_HOOK_DECLARE;

private:
  /// Type of object stored in the Queue
  TYPE type_;

  /// Asynchronous completion token associated with the timer.
  const void *act_;

  /// Time until the timer expires.
  ACE_Time_Value timer_value_;

  /// If this is a periodic timer this holds the time until the next
  /// timeout.
  ACE_Time_Value interval_;

  /// Pointer to previous timer.
  ACE_Timer_Node_T<TYPE> *prev_;

  /// Pointer to next timer.
  ACE_Timer_Node_T<TYPE> *next_;

  /// Id of this timer (used to cancel timers before they expire).
  long timer_id_;
};

/**
 * @class ACE_Timer_Queue_Iterator_T
 *
 * @brief Generic interface for iterating over a subclass of
 * ACE_Timer_Queue.
 *
 * This is a generic iterator that can be used to visit every
 * node of a timer queue.  Be aware that it isn't guaranteed
 * that the transversal will be in order of timeout values.
 */
template <class TYPE>
class ACE_Timer_Queue_Iterator_T
{
public:
  /// Constructor.
  ACE_Timer_Queue_Iterator_T () = default;

  /// Destructor.
  virtual ~ACE_Timer_Queue_Iterator_T ();

  /// Positions the iterator at the earliest node in the Timer Queue
  virtual void first () = 0;

  /// Positions the iterator at the next node in the Timer Queue
  virtual void next () = 0;

  /// Returns true when there are no more nodes in the sequence
  virtual bool isdone () const = 0;

  /// Returns the node at the current position in the sequence
  virtual ACE_Timer_Node_T<TYPE> *item () = 0;
};

ACE_END_VERSIONED_NAMESPACE_DECL

#if defined (__ACE_INLINE__)
#include "ace/Timer_Queue_Iterator.inl"
#endif /* __ACE_INLINE__ */

#include "ace/Timer_Queue_Iterator.cpp"

#include /**/ "ace/post.h"
#endif /* ACE_TIMER_QUEUE_ITERATOR_H */