aboutsummaryrefslogtreecommitdiffstats
path: root/src/RemoteControl.h
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2014-02-14 21:37:04 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2014-02-14 21:37:47 +0100
commit18ac7c4644add4db18bcb7cd7cb3560cffe846b3 (patch)
tree4cb0d3d26d338d5b857023024c401cbfb6c5a09b /src/RemoteControl.h
parentcba2e4929392272ce09219d1a691c059a580ab41 (diff)
downloaddabmux-18ac7c4644add4db18bcb7cd7cb3560cffe846b3.tar.gz
dabmux-18ac7c4644add4db18bcb7cd7cb3560cffe846b3.tar.bz2
dabmux-18ac7c4644add4db18bcb7cd7cb3560cffe846b3.zip
restart RC if it did a fault
Diffstat (limited to 'src/RemoteControl.h')
-rw-r--r--src/RemoteControl.h52
1 files changed, 41 insertions, 11 deletions
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<string> > allparams;
list<string> params = controllable->get_supported_parameters();
- for (list<string>::iterator it = params.begin(); it != params.end(); ++it) {
+ for (list<string>::iterator it = params.begin();
+ it != params.end(); ++it) {
vector<string> 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