diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2015-03-21 14:30:09 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2015-06-19 10:43:35 +0200 |
commit | 76e7f0f79c908bf7d0a447ea643dbcdde8f064d2 (patch) | |
tree | 214230901ec43d923e1696c54005a123278df086 /src/RemoteControl.h | |
parent | 0ac177534620caa13864f9bfcd804004e3e538fd (diff) | |
download | dabmux-76e7f0f79c908bf7d0a447ea643dbcdde8f064d2.tar.gz dabmux-76e7f0f79c908bf7d0a447ea643dbcdde8f064d2.tar.bz2 dabmux-76e7f0f79c908bf7d0a447ea643dbcdde8f064d2.zip |
Start big refactoring
Multiplexer in separate object
Replace pointers by shared_ptr
Switch to C++11
Diffstat (limited to 'src/RemoteControl.h')
-rw-r--r-- | src/RemoteControl.h | 45 |
1 files changed, 26 insertions, 19 deletions
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 <list> #include <map> #include <string> +#include <atomic> #include <iostream> #include <boost/bind.hpp> #include <boost/shared_ptr.hpp> @@ -104,6 +105,10 @@ class RemoteControllable { controller.enrol(this); } + virtual void enrol_at(boost::shared_ptr<BaseRemoteController> controller) { + controller->enrol(this); + } + /* Return a list of possible parameters that can be set */ virtual std::list<std::string> get_supported_parameters() const { std::list<std::string> 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<bool> m_running; + + boost::asio::io_service m_io_service; /* This is set to true if a fault occurred */ - bool m_fault; + std::atomic<bool> 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<RemoteControllable*> m_cohort; - std::string m_welcome; - std::string m_prompt; - int m_port; }; |