blob: d7ca73dfd0ffb897a1d2f5b5545528d32ff04e05 (
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#ifndef WANDA_CONTROL_COMMANDER_HPP
#define WANDA_CONTROL_COMMANDER_HPP
#include "wanda/control/connection.hpp"
#include "wanda/proto/command.hpp"
#include "wanda/proto/message.hpp"
#include <boost/asio/io_context.hpp>
#include <boost/asio/io_service.hpp>
#include <filesystem>
#include <memory>
#include <optional>
#include <string>
#include <vector>
namespace wanda::control
{
/**
* @brief The remote control client
*
*/
struct commander : connection::listener
{
/**
* @brief The interface to be implemented by remote control listeners
*/
struct listener
{
virtual void on_connected(commander & commander){};
virtual void on_response(commander & commander, std::string response){};
virtual void on_error(commander & commander, std::string error){};
};
/**
* @brief Construct a new commander
*/
commander(boost::asio::io_context & service, std::filesystem::path socket, listener & listener);
/**
* @brief Start communication with the remote daemon endpoint
*/
void start();
/**
* @brief Stop communication with the remote daemon endpoint
*/
void stop();
/**
* @brief Send a command to the remote daemon endpoint
*/
void send(proto::command command);
void on_error(connection::pointer connection, std::error_code error) override;
void on_received(connection::pointer connection, proto::message message) override;
private:
boost::asio::io_context & m_service;
wanda::control::connection::protocol::endpoint m_endpoint;
wanda::control::connection::protocol::socket m_socket;
wanda::control::connection::pointer m_connection;
listener & m_listener;
};
} // namespace wanda::control
#endif
|