From c029d90d1975e124d237605f1edb2be16bd05b5d Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Tue, 28 Feb 2017 21:50:44 +0100 Subject: Initial commit --- src/looper.hh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/looper.hh (limited to 'src/looper.hh') diff --git a/src/looper.hh b/src/looper.hh new file mode 100644 index 0000000..7315220 --- /dev/null +++ b/src/looper.hh @@ -0,0 +1,41 @@ +// -*- mode: c++; c-basic-offset: 2; -*- + +#ifndef LOOPER_HH +#define LOOPER_HH + +#include +#include + +class Looper { +public: + typedef std::chrono::steady_clock clock; + typedef std::function FdCallback; + typedef std::function ScheduleCallback; + virtual ~Looper() { } + + static const uint8_t EVENT_READ; + static const uint8_t EVENT_WRITE; + // Always reported, need not be set + static const uint8_t EVENT_HUP; + static const uint8_t EVENT_ERROR; + + static Looper* create(); + + virtual void add(int fd, uint8_t events, FdCallback const& callback) = 0; + virtual void modify(int fd, uint8_t events) = 0; + virtual void remove(int fd) = 0; + + virtual void* schedule(float delay_s, ScheduleCallback const& callback) = 0; + virtual void cancel(void* handle) = 0; + + virtual bool run() = 0; + virtual void quit() = 0; + + virtual clock::time_point now() const = 0; + +protected: + Looper() { } + Looper(Looper const&) = delete; +}; + +#endif // LOOPER_HH -- cgit v1.2.3-70-g09d2