From ca992f4f76d09965e4e62c805daa02b23266a224 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 29 Nov 2018 18:29:34 +0100 Subject: control: begin control interface implementation --- src/control_connection.hpp | 76 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/control_connection.hpp (limited to 'src/control_connection.hpp') diff --git a/src/control_connection.hpp b/src/control_connection.hpp new file mode 100644 index 0000000..e868f99 --- /dev/null +++ b/src/control_connection.hpp @@ -0,0 +1,76 @@ +#ifndef WANDA_CONTROL_CONNECTION_HPP +#define WANDA_CONTROL_CONNECTION_HPP + +#include "keyed.hpp" + +#include + +#include +#include +#include + +namespace wanda +{ + +struct control_connection : keyed, std::enable_shared_from_this +{ + using protocol = boost::asio::local::stream_protocol; + using pointer = std::shared_ptr; + + struct listener + { + virtual void on_close(pointer connection) {} + virtual void on_received(pointer connection, std::string message) {} + virtual void on_error(pointer connection, boost::system::error_code) {} + }; + + /** + * @internal + * @brief Construct a new control connection object + * + * @param socket The socket connected to the remote control endpoint + */ + control_connection(key, protocol::socket socket); + + /** + * @brief Add the given listener to this control connection's listener set + * + * @returns true iff. the listener was not already in the listener set + */ + bool add(std::shared_ptr listener); + + /** + * @brief Remove the given listener from this control connection's listener set + * + * @return true iff. the listener was previously registered with this control connection + */ + bool remove(std::shared_ptr listener); + + /** + * @brief Start I/O processing for this control connection + */ + void start(); + + /** + * @brief Close this control connection + */ + void close(); + + private: + friend pointer make_control_connection(protocol::socket &&socket); + + void perform_read(); + + protocol::socket m_socket; + boost::asio::streambuf m_in{}; + boost::asio::streambuf m_out{}; + std::istream m_input{&m_in}; + std::set> m_listeners{}; + bool m_running{}; +}; + +control_connection::pointer make_control_connection(control_connection::protocol::socket &&socket); + +} // namespace wanda + +#endif \ No newline at end of file -- cgit v1.2.3