-
Notifications
You must be signed in to change notification settings - Fork 0
/
configserver.h
72 lines (57 loc) · 3.4 KB
/
configserver.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
#ifndef CONFIGSERVER_H
#define CONFIGSERVER_H
// STL
#include <memory>
#include <list>
#include <string>
#include <unordered_map>
// PUT
#include <put/socket.h>
#include <put/cxxutils/posix_helpers.h>
#include <put/cxxutils/vfifo.h>
#include <put/cxxutils/hashing.h>
#include <put/cxxutils/configmanip.h>
#include <put/specialized/fileevent.h>
class ConfigServer : public ServerSocket
{
public:
ConfigServer(void) noexcept;
~ConfigServer(void) noexcept;
private:
bool valueSet (const posix::fd_t socket, const std::string& key, const std::string& value) const noexcept;
bool valueUnset (const posix::fd_t socket, const std::string& key) const noexcept;
bool syncReturn (const posix::fd_t socket, const posix::error_t errcode) const noexcept;
bool unsetReturn(const posix::fd_t socket, const posix::error_t errcode, const std::string& key) const noexcept;
bool setReturn (const posix::fd_t socket, const posix::error_t errcode, const std::string& key) const noexcept;
bool getReturn (const posix::fd_t socket, const posix::error_t errcode, const std::string& key, const std::string& value, const std::list<std::string>& children) const noexcept;
void syncCall (posix::fd_t socket) noexcept;
void unsetCall (posix::fd_t socket, const std::string& key) noexcept;
void setCall (posix::fd_t socket, const std::string& key, const std::string& value) noexcept;
void getCall (posix::fd_t socket, const std::string& key) noexcept;
bool peerChooser(posix::fd_t socket, const proccred_t& cred) noexcept;
void receive(posix::fd_t socket, vfifo buffer, posix::fd_t fd) noexcept;
void request(posix::fd_t socket, posix::sockaddr_t addr, proccred_t cred) noexcept;
void removePeer(posix::fd_t socket) noexcept;
void fileUpdated(std::string filename, FileEvent::Flags_t flags) noexcept;
struct configfile_t
{
std::unique_ptr<FileEvent> fevent;
ConfigManip config;
};
std::unordered_map<pid_t, posix::fd_t> m_endpoints;
std::unordered_map<posix::fd_t, configfile_t> m_configfiles;
};
inline bool ConfigServer::valueSet(const posix::fd_t socket, const std::string& key, const std::string& value) const noexcept
{ return write(socket, vfifo("RPC", "valueSet", key, value), posix::invalid_descriptor); }
inline bool ConfigServer::valueUnset(const posix::fd_t socket, const std::string& key) const noexcept
{ return write(socket, vfifo("RPC", "valueUnset", key), posix::invalid_descriptor); }
inline bool ConfigServer::syncReturn(const posix::fd_t socket, const posix::error_t errcode) const noexcept
{ return write(socket, vfifo("RPC", "syncReturn", errcode), posix::invalid_descriptor); }
inline bool ConfigServer::unsetReturn(const posix::fd_t socket, const posix::error_t errcode, const std::string& key) const noexcept
{ return write(socket, vfifo("RPC", "unsetReturn", errcode, key), posix::invalid_descriptor); }
inline bool ConfigServer::setReturn(const posix::fd_t socket, const posix::error_t errcode, const std::string& key) const noexcept
{ return write(socket, vfifo("RPC", "setReturn", errcode, key), posix::invalid_descriptor); }
inline bool ConfigServer::getReturn(const posix::fd_t socket, const posix::error_t errcode, const std::string& /*key*/,
const std::string& value, const std::list<std::string>& children) const noexcept
{ return write(socket, vfifo("RPC", "getReturn", errcode, value, children), posix::invalid_descriptor); }
#endif // CONFIGSERVER_H