From 766f9f420aae19ecf282a32e7f9e2add275d9b14 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Tue, 10 Apr 2018 22:38:56 +0200 Subject: Make telnet RC compile-time dependant on boost --- src/ConfigParser.cpp | 8 +++++--- src/InputReader.h | 1 + src/RemoteControl.cpp | 34 ++++++++++++++++++---------------- src/RemoteControl.h | 14 +++++++++----- 4 files changed, 33 insertions(+), 24 deletions(-) (limited to 'src') 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 #include #include +#include #include #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 #include #include -#include -#include - +#include +#if defined(HAVE_BOOST) +# include +# include +#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 &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 #include #include +#include +#if defined(HAVE_BOOST) #include #include #include #include #include +#endif #include #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 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 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 -- cgit v1.2.3