From 18ac7c4644add4db18bcb7cd7cb3560cffe846b3 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Fri, 14 Feb 2014 21:37:04 +0100 Subject: restart RC if it did a fault --- src/RemoteControl.h | 52 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 11 deletions(-) (limited to 'src/RemoteControl.h') diff --git a/src/RemoteControl.h b/src/RemoteControl.h index e76ba68..c0fec8d 100644 --- a/src/RemoteControl.h +++ b/src/RemoteControl.h @@ -67,11 +67,23 @@ class ParameterError : public std::exception class RemoteControllable; -/* Remote controllers (that recieve orders from the user) must implement BaseRemoteController */ +/* Remote controllers (that recieve orders from the user) + * must implement BaseRemoteController + */ class BaseRemoteController { public: /* Add a new controllable under this controller's command */ virtual void enrol(RemoteControllable* controllable) = 0; + + /* When this returns one, the remote controller cannot be + * used anymore, and must be restarted by dabmux + */ + virtual bool fault_detected() = 0; + + /* In case of a fault, the remote controller can be + * restarted. + */ + virtual void restart() = 0; }; /* Objects that support remote control must implement the following class */ @@ -125,33 +137,41 @@ class RemoteControllable { class RemoteControllerTelnet : public BaseRemoteController { public: RemoteControllerTelnet() - : m_running(false), m_port(0) {} + : m_running(false), m_fault(false), + m_port(0) {} RemoteControllerTelnet(int port) - : m_running(true), m_port(port), + : m_running(false), m_fault(false), + m_port(port), m_child_thread(&RemoteControllerTelnet::process, this, 0) {} ~RemoteControllerTelnet() { m_running = false; + m_fault = false; if (m_port) { m_child_thread.interrupt(); m_child_thread.join(); } } - void process(long); - - void dispatch_command(tcp::socket& socket, string command); - - void reply(tcp::socket& socket, string message); - void enrol(RemoteControllable* controllable) { m_cohort.push_back(controllable); } + virtual bool fault_detected() { return m_fault; }; + + virtual void restart(); private: + void restart_thread(long); + + void process(long); + + void dispatch_command(tcp::socket& socket, string command); + + void reply(tcp::socket& socket, string message); + RemoteControllerTelnet& operator=(const RemoteControllerTelnet& other); RemoteControllerTelnet(const RemoteControllerTelnet& other); @@ -192,7 +212,8 @@ class RemoteControllerTelnet : public BaseRemoteController { list< vector > allparams; list params = controllable->get_supported_parameters(); - for (list::iterator it = params.begin(); it != params.end(); ++it) { + for (list::iterator it = params.begin(); + it != params.end(); ++it) { vector item; item.push_back(*it); item.push_back(controllable->get_parameter(*it)); @@ -213,6 +234,11 @@ class RemoteControllerTelnet : public BaseRemoteController { } bool m_running; + + /* This is set to true if a fault occurred */ + bool m_fault; + boost::thread m_restarter_thread; + boost::thread m_child_thread; /* This controller commands the controllables in the cohort */ @@ -225,11 +251,15 @@ class RemoteControllerTelnet : public BaseRemoteController { }; -/* The Dummy remote controller does nothing +/* The Dummy remote controller does nothing, and never fails */ class RemoteControllerDummy : public BaseRemoteController { public: void enrol(RemoteControllable* controllable) {}; + + bool fault_detected() { return false; }; + + virtual void restart() {}; }; #endif -- cgit v1.2.3