From 76e7f0f79c908bf7d0a447ea643dbcdde8f064d2 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sat, 21 Mar 2015 14:30:09 +0100 Subject: Start big refactoring Multiplexer in separate object Replace pointers by shared_ptr Switch to C++11 --- src/RemoteControl.h | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'src/RemoteControl.h') diff --git a/src/RemoteControl.h b/src/RemoteControl.h index 16881b4..46a828f 100644 --- a/src/RemoteControl.h +++ b/src/RemoteControl.h @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -104,6 +105,10 @@ class RemoteControllable { controller.enrol(this); } + virtual void enrol_at(boost::shared_ptr controller) { + controller->enrol(this); + } + /* Return a list of possible parameters that can be set */ virtual std::list get_supported_parameters() const { std::list parameterlist; @@ -137,25 +142,23 @@ class RemoteControllable { */ class RemoteControllerTelnet : public BaseRemoteController { public: - RemoteControllerTelnet() - : m_running(false), m_fault(false), + RemoteControllerTelnet() : + m_running(false), + m_io_service(), + m_fault(false), m_port(0) { } - RemoteControllerTelnet(int port) - : m_running(true), m_fault(false), - m_child_thread(&RemoteControllerTelnet::process, this, 0), + RemoteControllerTelnet(int port) : + m_running(false), + m_io_service(), + m_fault(false), m_port(port) - { } - - ~RemoteControllerTelnet() { - m_running = false; - m_fault = false; - if (m_port) { - m_child_thread.interrupt(); - m_child_thread.join(); - } + { + restart(); } + ~RemoteControllerTelnet(); + void enrol(RemoteControllable* controllable) { m_cohort.push_back(controllable); } @@ -174,6 +177,11 @@ class RemoteControllerTelnet : public BaseRemoteController { void reply(boost::asio::ip::tcp::socket& socket, std::string message); + void handle_accept( + const boost::system::error_code& boost_error, + boost::shared_ptr< boost::asio::ip::tcp::socket > socket, + boost::asio::ip::tcp::acceptor& acceptor); + RemoteControllerTelnet& operator=(const RemoteControllerTelnet& other); RemoteControllerTelnet(const RemoteControllerTelnet& other); @@ -237,10 +245,12 @@ class RemoteControllerTelnet : public BaseRemoteController { return controllable->set_parameter(param, value); } - bool m_running; + std::atomic m_running; + + boost::asio::io_service m_io_service; /* This is set to true if a fault occurred */ - bool m_fault; + std::atomic m_fault; boost::thread m_restarter_thread; boost::thread m_child_thread; @@ -248,9 +258,6 @@ class RemoteControllerTelnet : public BaseRemoteController { /* This controller commands the controllables in the cohort */ std::list m_cohort; - std::string m_welcome; - std::string m_prompt; - int m_port; }; -- cgit v1.2.3