summaryrefslogtreecommitdiff
path: root/src/looper.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/looper.hh')
-rw-r--r--src/looper.hh41
1 files changed, 41 insertions, 0 deletions
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 <chrono>
+#include <functional>
+
+class Looper {
+public:
+ typedef std::chrono::steady_clock clock;
+ typedef std::function<void(int, uint8_t)> FdCallback;
+ typedef std::function<void(void*)> 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