-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.hpp
51 lines (38 loc) · 1010 Bytes
/
command.hpp
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
#ifndef COMMAND_HPP__
#define COMMAND_HPP__
#include "eventhandler.hpp"
#include <string>
#include <map>
#include <functional>
#include <vector>
#include <cstddef>
class EventHandler;
class Remote;
class Command : public EventHandled
{
public:
Command();
void set_remote(Remote &remote);
protected:
std::string parse_command(EventHandler &handler, const std::string &cmd);
Remote *remote;
private:
void init_command_map();
std::map<std::string,
std::function<std::string (EventHandler &, std::vector<std::string>)>> command_map;
};
class SocketReply : public EventHandled
{
public:
SocketReply(int fd,
std::string &&data, std::function<void (bool)> end_cb);
void operator=(const SocketReply &) = delete;
void handle(EventHandler &handler);
EventHandled::PollList pollfds() const;
private:
int fd;
std::string data;
std::size_t ptr;
std::function<void (bool)> end_cb;
};
#endif