This repository was archived by the owner on May 11, 2026. It is now read-only.
forked from Dmitry666/HTTPCommandService
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttpservice.h
More file actions
97 lines (76 loc) · 2.15 KB
/
Copy pathhttpservice.h
File metadata and controls
97 lines (76 loc) · 2.15 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef HTTPSERVICE_H
#define HTTPSERVICE_H
#include "common.h"
namespace openrc {
/**
* @brief Argument container from service.
*/
struct HttpServiceArguments
{
typedef std::map<std::string, std::string> ArgumentsContainer;
HttpServiceArguments()
{}
HttpServiceArguments(const HttpServiceArguments& ca)
: _argumentMap(ca._argumentMap)
{}
HttpServiceArguments(const ArgumentsContainer& argumentMap)
: _argumentMap(argumentMap)
{}
std::string operator [](const std::string& key) const
{
auto it = _argumentMap.find(key);
if(it != _argumentMap.end())
{
return it->second;
}
return "";
}
void Push(const std::string& key, const std::string& value)
{
_argumentMap.insert(std::make_pair(key, value));
}
const std::map<std::string, std::string>& ToArgumentMap() const { return _argumentMap; }
// From stl.
ArgumentsContainer::iterator begin() {return _argumentMap.begin();}
ArgumentsContainer::const_iterator begin() const {return _argumentMap.begin();}
ArgumentsContainer::iterator end() {return _argumentMap.end();}
ArgumentsContainer::const_iterator end() const {return _argumentMap.end();}
ArgumentsContainer::iterator find(const std::string& key) {return _argumentMap.find(key);}
ArgumentsContainer::const_iterator find(const std::string& key) const {return _argumentMap.find(key);}
private:
ArgumentsContainer _argumentMap;
};
/**
* @brief Http service manager.
*/
class HttpService
{
public:
HCORE_API HttpService(const HttpServiceArguments& arguments);
HCORE_API ~HttpService();
/**
* @brief Start service by address and port.
* @param address
* @param port server port.
* @return started.
*/
HCORE_API bool Start(const std::string& address, const std::string& port);
/**
* @brief Stop service.
* @return stoped.
*/
HCORE_API bool Stop();
/**
* @brief Wait stoped service.
* @return
*/
HCORE_API bool Join(float time = 0.f);
private:
//void Run();
private:
HttpServiceArguments _arguments;
std::string _address;
std::string _port;
};
} // End http.
#endif // HTTPSERVICE_H