blob: cf09e14c031e19c572a9401265c5a790d531236d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
|