From 543e91dc65d839864b42114b353d0c30db4dcdd1 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 29 Nov 2018 23:42:34 +0100 Subject: wanda: begin basic control command --- src/wandac.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/wandac.cpp (limited to 'src/wandac.cpp') diff --git a/src/wandac.cpp b/src/wandac.cpp new file mode 100644 index 0000000..8e068ae --- /dev/null +++ b/src/wandac.cpp @@ -0,0 +1,65 @@ +#include "control_connection.hpp" + +#include + +#include +#include +#include + +namespace +{ +struct commander : wanda::control_connection::listener, std::enable_shared_from_this +{ + commander(boost::asio::io_service &service, std::filesystem::path socket) + : m_endpoint{socket.string()}, + m_socket{service} + { + } + + void start() + { + m_socket.async_connect(m_endpoint, [&](auto const &error) { + if (error) + { + std::cerr << "[commander::start] error occured: " << error.message() << '\n'; + } + else + { + m_connection = wanda::make_control_connection(std::move(m_socket)); + m_connection->start(); + send("C:HELLO:1.0.0\n"); + m_connection->close(); + } + }); + } + + void send(std::string message) + { + if (m_connection) + { + std::clog << "[commander::send] sending message: " << message; + m_connection->send(std::move(message)); + } + } + + void on_error(wanda::control_connection::pointer connection, boost::system::error_code error) override + { + std::cerr << "[commander::on_error] error occured: " << error.message() << '\n'; + } + + private: + wanda::control_connection::protocol::endpoint m_endpoint; + wanda::control_connection::protocol::socket m_socket; + wanda::control_connection::pointer m_connection; +}; +} // namespace + +int main() +{ + auto service = boost::asio::io_service{}; + auto command_processor = commander{service, std::filesystem::path{".wanda_interface"}}; + + command_processor.start(); + + service.run(); +} \ No newline at end of file -- cgit v1.2.3