aboutsummaryrefslogtreecommitdiff
path: root/src/EventManager.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/EventManager.hpp')
-rw-r--r--src/EventManager.hpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/EventManager.hpp b/src/EventManager.hpp
new file mode 100644
index 0000000..cf09e14
--- /dev/null
+++ b/src/EventManager.hpp
@@ -0,0 +1,49 @@
+#ifndef EVENT_MANAGER_H
+#define EVENT_MANAGER_H 1
+
+#include "ContentManager.hpp"
+#include "Filesystem.hpp"
+
+#include <event2/buffer.h>
+#include <event2/event.h>
+#include <event2/http.h>
+
+#include <functional>
+#include <string>
+#include <vector>
+
+using EvUserData = void *;
+using EvFunction = std::function<void(struct evhttp_request *, EvUserData)>;
+
+struct ev_callback
+{
+ EvFunction cb;
+ EvUserData ud;
+};
+
+using EvUrlCallback = std::tuple<std::string, struct ev_callback>;
+
+class EventManager
+{
+public:
+ EventManager(std::shared_ptr<ContentManager> & cmgr);
+ ~EventManager();
+
+ bool Init(std::string = "127.0.0.1", uint16_t port = 9000);
+ void SetDefaultCallback(EvFunction fn, EvUserData dat);
+ void AddCallback(std::string url, EvFunction fn, EvUserData dat);
+
+private:
+ std::shared_ptr<ContentManager> m_ContentManager;
+ struct ev_callback m_DefaultCallback;
+ std::vector<EvUrlCallback> m_UrlCallbacks;
+
+ struct event_config * m_EvConfig = nullptr;
+ struct event_base * m_EvBase = nullptr;
+ struct evhttp * m_EvHttp = nullptr;
+ struct evhttp_bound_socket * m_EvSocket = nullptr;
+ struct evconnlistener * m_EvListener = nullptr;
+ struct event * m_EvTermEvent = nullptr;
+};
+
+#endif