diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2018-04-10 22:38:56 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2018-04-10 22:38:56 +0200 |
commit | 766f9f420aae19ecf282a32e7f9e2add275d9b14 (patch) | |
tree | 8c825ca608a9671e2647f5d3ecb6e41d67079412 /src | |
parent | 975c4b40a2e5fbe8f5566f21c49db96a5a939127 (diff) | |
download | dabmod-766f9f420aae19ecf282a32e7f9e2add275d9b14.tar.gz dabmod-766f9f420aae19ecf282a32e7f9e2add275d9b14.tar.bz2 dabmod-766f9f420aae19ecf282a32e7f9e2add275d9b14.zip |
Make telnet RC compile-time dependant on boost
Diffstat (limited to 'src')
-rw-r--r-- | src/ConfigParser.cpp | 8 | ||||
-rw-r--r-- | src/InputReader.h | 1 | ||||
-rw-r--r-- | src/RemoteControl.cpp | 34 | ||||
-rw-r--r-- | src/RemoteControl.h | 14 |
4 files changed, 33 insertions, 24 deletions
diff --git a/src/ConfigParser.cpp b/src/ConfigParser.cpp index 94a960d..350c278 100644 --- a/src/ConfigParser.cpp +++ b/src/ConfigParser.cpp @@ -72,13 +72,14 @@ static void parse_configfile( int line_err = pt.ParseError(); - if (line_err) - { + if (line_err) { std::cerr << "Error, cannot read configuration file '" << configuration_file.c_str() << "'" << std::endl; std::cerr << "At line: " << line_err << std::endl; throw std::runtime_error("Cannot read configuration file"); } - // remote controller: + + // remote controller interfaces: +#if defined(HAVE_BOOST) if (pt.GetInteger("remotecontrol.telnet", 0) == 1) { try { int telnetport = pt.GetInteger("remotecontrol.telnetport", 0); @@ -91,6 +92,7 @@ static void parse_configfile( throw std::runtime_error("Configuration error"); } } +#endif #if defined(HAVE_ZEROMQ) if (pt.GetInteger("remotecontrol.zmqctrl", 0) == 1) { try { diff --git a/src/InputReader.h b/src/InputReader.h index 85bf38b..d229417 100644 --- a/src/InputReader.h +++ b/src/InputReader.h @@ -36,6 +36,7 @@ #include <string> #include <atomic> #include <memory> +#include <thread> #include <unistd.h> #if defined(HAVE_ZEROMQ) # include "zmq.hpp" diff --git a/src/RemoteControl.cpp b/src/RemoteControl.cpp index a346386..6e6a7e9 100644 --- a/src/RemoteControl.cpp +++ b/src/RemoteControl.cpp @@ -28,16 +28,22 @@ #include <string> #include <iostream> #include <string> -#include <boost/asio.hpp> -#include <boost/thread.hpp> - +#include <thread> +#if defined(HAVE_BOOST) +# include <boost/asio.hpp> +# include <boost/thread.hpp> +#endif #include "RemoteControl.h" +#if defined(HAVE_BOOST) using boost::asio::ip::tcp; +#endif + using namespace std; RemoteControllers rcs; +#if defined(HAVE_BOOST) RemoteControllerTelnet::~RemoteControllerTelnet() { m_active = false; @@ -47,10 +53,11 @@ RemoteControllerTelnet::~RemoteControllerTelnet() void RemoteControllerTelnet::restart() { - m_restarter_thread = boost::thread( + m_restarter_thread = std::thread( &RemoteControllerTelnet::restart_thread, this, 0); } +#endif RemoteControllable::~RemoteControllable() { rcs.remove_controllable(this); @@ -89,6 +96,7 @@ void RemoteControllers::set_param( return controllable->set_parameter(param, value); } +#if defined(HAVE_BOOST) // This runs in a separate thread, because // it would take too long to be done in the main loop // thread. @@ -99,7 +107,7 @@ void RemoteControllerTelnet::restart_thread(long) m_child_thread.join(); - m_child_thread = boost::thread(&RemoteControllerTelnet::process, this, 0); + m_child_thread = std::thread(&RemoteControllerTelnet::process, this, 0); } void RemoteControllerTelnet::handle_accept( @@ -319,7 +327,7 @@ void RemoteControllerTelnet::reply(tcp::socket& socket, string message) boost::asio::transfer_all(), ignored_error); } - +#endif #if defined(HAVE_ZEROMQ) @@ -327,15 +335,14 @@ RemoteControllerZmq::~RemoteControllerZmq() { m_active = false; m_fault = false; - if (!m_endpoint.empty()) { - m_child_thread.interrupt(); + if (m_child_thread.joinable()) { m_child_thread.join(); } } void RemoteControllerZmq::restart() { - m_restarter_thread = boost::thread(&RemoteControllerZmq::restart_thread, this); + m_restarter_thread = std::thread(&RemoteControllerZmq::restart_thread, this); } // This runs in a separate thread, because @@ -345,12 +352,11 @@ void RemoteControllerZmq::restart_thread() { m_active = false; - if (!m_endpoint.empty()) { - m_child_thread.interrupt(); + if (m_child_thread.joinable()) { m_child_thread.join(); } - m_child_thread = boost::thread(&RemoteControllerZmq::process, this); + m_child_thread = std::thread(&RemoteControllerZmq::process, this); } void RemoteControllerZmq::recv_all(zmq::socket_t& pSocket, std::vector<std::string> &message) @@ -479,13 +485,9 @@ void RemoteControllerZmq::process() "Unsupported command. commands: list, show, get, set"); } } - - // check if thread is interrupted - boost::this_thread::interruption_point(); } repSocket.close(); } - catch (boost::thread_interrupted&) {} catch (zmq::error_t &e) { etiLog.level(error) << "ZMQ RC error: " << std::string(e.what()); } diff --git a/src/RemoteControl.h b/src/RemoteControl.h index 11cd52c..1d9ea52 100644 --- a/src/RemoteControl.h +++ b/src/RemoteControl.h @@ -43,11 +43,14 @@ #include <string> #include <atomic> #include <iostream> +#include <thread> +#if defined(HAVE_BOOST) #include <boost/bind.hpp> #include <boost/asio.hpp> #include <boost/foreach.hpp> #include <boost/tokenizer.hpp> #include <boost/thread.hpp> +#endif #include <stdexcept> #include "Log.h" @@ -192,7 +195,7 @@ class RemoteControllers { extern RemoteControllers rcs; - +#if defined(HAVE_BOOST) /* Implements a Remote controller based on a simple telnet CLI * that listens on localhost */ @@ -254,12 +257,13 @@ class RemoteControllerTelnet : public BaseRemoteController { /* This is set to true if a fault occurred */ std::atomic<bool> m_fault; - boost::thread m_restarter_thread; + std::thread m_restarter_thread; - boost::thread m_child_thread; + std::thread m_child_thread; int m_port; }; +#endif #if defined(HAVE_ZEROMQ) /* Implements a Remote controller using zmq transportlayer @@ -299,12 +303,12 @@ class RemoteControllerZmq : public BaseRemoteController { /* This is set to true if a fault occurred */ std::atomic<bool> m_fault; - boost::thread m_restarter_thread; + std::thread m_restarter_thread; zmq::context_t m_zmqContext; std::string m_endpoint; - boost::thread m_child_thread; + std::thread m_child_thread; }; #endif |