21 #ifndef COMMON_IO_TIMEOUTMANAGER_H_ 22 #define COMMON_IO_TIMEOUTMANAGER_H_ 29 #include "ola/Clock.h" 32 #include "ola/thread/SchedulerInterface.h" 92 return !m_events.empty();
103 static const char K_TIMER_VAR[];
109 : m_interval(interval) {
112 m_next = now + m_interval;
115 virtual bool Trigger() = 0;
118 m_next = now + m_interval;
121 TimeStamp NextTime()
const {
return m_next; }
129 class SingleEvent:
public Event {
134 Event(interval, clock),
138 virtual ~SingleEvent() {
160 class RepeatingEvent:
public Event {
165 Event(interval, clock),
174 return m_closure->Run();
182 bool operator()(Event *e1, Event *e2)
const {
183 return e1->NextTime() > e2->NextTime();
187 typedef std::priority_queue<Event*, std::vector<Event*>, ltevent>
193 event_queue_t m_events;
194 std::set<ola::thread::timeout_id> m_removed_timeouts;
200 #endif // COMMON_IO_TIMEOUTMANAGER_H_ A time interval, with usecond accuracy.
Definition: Clock.h:138
A 0 arg, single use callback that returns void.
Definition: Callback.h:157
Manages timer events.
Definition: TimeoutManager.h:45
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Creates dummy copy constructor and assignment operator declarations.
Definition: Macro.h:44
A container for the exported variables.
Definition: ExportMap.h:324
A 0 argument callback which can be called multiple times.
Definition: Callback.h:129
Export variables on the http server.
virtual void CurrentMonotonicTime(TimeStamp *timestamp) const
Sets timestamp to the current monotonic time.
Definition: Clock.cpp:270
void * timeout_id
A timeout handle which can later be used to cancel a timeout.
Definition: SchedulerInterface.h:34
ola::thread::timeout_id RegisterRepeatingTimeout(const ola::TimeInterval &interval, ola::Callback0< bool > *closure)
Register a repeating timeout. Returning false from the Callback will cancel this timer.
Definition: TimeoutManager.cpp:57
Used to get the current time.
Definition: Clock.h:242
ola::thread::timeout_id RegisterSingleTimeout(const ola::TimeInterval &interval, ola::SingleUseCallback0< void > *closure)
Register a single use timeout function.
Definition: TimeoutManager.cpp:71
void CancelTimeout(ola::thread::timeout_id id)
Cancel a timeout.
Definition: TimeoutManager.cpp:85
TimeInterval ExecuteTimeouts(TimeStamp *now)
Execute any expired timeouts.
Definition: TimeoutManager.cpp:95
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
TimeoutManager(ola::ExportMap *export_map, Clock *clock)
Create a new TimeoutManager.
Definition: TimeoutManager.cpp:39
Represents a point in time with microsecond accuracy.
Definition: Clock.h:191
bool EventsPending() const
Check if there are any events in the queue. Events remain in the queue even if they have been cancell...
Definition: TimeoutManager.h:91