summaryrefslogtreecommitdiff
path: root/src/looper.hh
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2025-10-08 00:58:42 +0200
committerJoel Klinghed <the_jk@spawned.biz>2025-10-19 00:13:47 +0200
commit86ec0b5386fc2078891a829026844d2ec21ea7db (patch)
tree5f3ed650bc2957e06fd3c8c1ecfa7c6e7fc825b6 /src/looper.hh
parent3a002fb9c23fc9a6384bc1b30a8e364924bb574e (diff)
Add http module and implement basic http server
Diffstat (limited to 'src/looper.hh')
-rw-r--r--src/looper.hh46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/looper.hh b/src/looper.hh
new file mode 100644
index 0000000..2f4c672
--- /dev/null
+++ b/src/looper.hh
@@ -0,0 +1,46 @@
+#ifndef LOOPER_HH
+#define LOOPER_HH
+
+#include <cstdint>
+#include <functional>
+#include <memory>
+
+namespace logger {
+class Logger;
+} // namespace logger
+
+namespace looper {
+
+constexpr static uint8_t EVENT_READ = 1;
+constexpr static uint8_t EVENT_WRITE = 2;
+constexpr static uint8_t EVENT_ERROR = 4;
+
+class Looper {
+ public:
+ virtual ~Looper() = default;
+
+ virtual void add(int fd, uint8_t events,
+ std::function<void(uint8_t)> callback) = 0;
+ virtual void update(int fd, uint8_t events) = 0;
+ virtual void remove(int fd) = 0;
+
+ // Returned id is never 0
+ virtual uint32_t schedule(double delay,
+ std::function<void(uint32_t)> callback) = 0;
+ virtual void cancel(uint32_t id) = 0;
+
+ virtual bool run(logger::Logger& logger) = 0;
+ virtual void quit() = 0;
+
+ protected:
+ Looper() = default;
+ Looper(Looper const&) = delete;
+ Looper& operator=(Looper const&) = delete;
+};
+
+[[nodiscard]]
+std::unique_ptr<Looper> create();
+
+} // namespace looper
+
+#endif // LOOPER_HH