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) {
111 clock->CurrentTime(&now);
112 m_next = now + m_interval;
115 virtual bool Trigger() = 0;
117 void UpdateTime(
const TimeStamp &now) {
118 m_next = now + m_interval;
121 TimeStamp NextTime()
const {
return m_next; }
124 TimeInterval m_interval;
129 class SingleEvent:
public Event {
131 SingleEvent(
const TimeInterval &interval,
134 Event(interval, clock),
138 virtual ~SingleEvent() {
160 class RepeatingEvent:
public Event {
162 RepeatingEvent(
const TimeInterval &interval,
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 0 arg, single use callback that returns void.
Definition: Callback.h:157
Manages timer events.
Definition: TimeoutManager.h:45
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.
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:221
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
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
TimeoutManager(ola::ExportMap *export_map, Clock *clock)
Create a new TimeoutManager.
Definition: TimeoutManager.cpp:39