Add TimerHandler to event loop
Change-Id: I85c9142bcff9bf2cc5b8d003d24b8d77567fbe4a
diff --git a/aos/events/raw-event-loop.h b/aos/events/raw-event-loop.h
index 38ceaec..5a0df1e 100644
--- a/aos/events/raw-event-loop.h
+++ b/aos/events/raw-event-loop.h
@@ -85,6 +85,21 @@
}
};
+// Interface for timers
+class TimerHandler {
+ public:
+ virtual ~TimerHandler() {}
+
+ // Timer should sleep until base, base + offset, base + offset * 2, ...
+ // If repeat_offset isn't set, the timer only expires once.
+ virtual void Setup(monotonic_clock::time_point base,
+ monotonic_clock::duration repeat_offset =
+ ::aos::monotonic_clock::zero()) = 0;
+
+ // Stop future calls to callback().
+ virtual void Disable() = 0;
+};
+
// Virtual base class for all event queue-types.
class RawEventLoop {
public:
@@ -99,6 +114,10 @@
bool is_running() const { return is_running_.load(); }
+ // Creates a timer that executes callback when the timer expires
+ // Returns a TimerHandle for configuration of the timer
+ virtual TimerHandler *AddTimer(::std::function<void()> callback) = 0;
+
// Starts receiving events.
virtual void Run() = 0;