aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2018-11-29 23:42:34 +0100
committerFelix Morgner <felix.morgner@gmail.com>2018-11-29 23:42:34 +0100
commit543e91dc65d839864b42114b353d0c30db4dcdd1 (patch)
treed28b5c83adb4e5ff7aa027c5c0ce32d197e762c2 /src
parentc307f09ca63f5dd609be0b3f1c077cd3bc1a9266 (diff)
downloadwanda-543e91dc65d839864b42114b353d0c30db4dcdd1.tar.xz
wanda-543e91dc65d839864b42114b353d0c30db4dcdd1.zip
wanda: begin basic control command
Diffstat (limited to 'src')
-rw-r--r--src/wandac.cpp65
1 files changed, 65 insertions, 0 deletions
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 <boost/asio.hpp>
+
+#include <filesystem>
+#include <iostream>
+#include <memory>
+
+namespace
+{
+struct commander : wanda::control_connection::listener, std::enable_shared_from_this<commander>
+{
+ 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