-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathHttpContainer.h
executable file
·76 lines (56 loc) · 1.24 KB
/
HttpContainer.h
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#pragma once
#include "httpCommon.h"
#include "AbstractServer.h"
#include "Configure.h"
using namespace std;
class HttpContainer {
public:
HttpContainer(){
servers.clear();
};
virtual ~HttpContainer(){
for (unsigned int i=0; i<servers.size(); i++) {
delete servers[i];
}
servers.clear();
if (_base) {event_base_free(_base);}
};
struct event_base *getEventBase() {
return _base;
}
void setEventBase(struct event_base *base) {
_base = base;
}
virtual void loop() = 0;
virtual void initContainer()=0;
void addServer(AbstractServer *server) {
servers.push_back(server);
}
AbstractServer *getServer(unsigned int idx) {
if (idx >= servers.size())
return NULL;
return servers[idx];
}
void startServers(struct event_base *base) {
for (unsigned int i=0; i<servers.size(); i++) {
servers[i]->run(base);
}
}
private:
struct event_base* _base;
vector<AbstractServer *> servers;
};
//sub class
class PersistHttpContainer : public HttpContainer {
public:
PersistHttpContainer(){
initContainer();
};
virtual ~PersistHttpContainer() {
delete config;
};
void initContainer();
void loop();
private:
Configure *config;;
};