From dd428769ba5587e913cb2d768e2bca4b70f98c5d Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Thu, 17 Apr 2014 20:14:27 +0200 Subject: Update Remotecontrol with changes from ODR-DabMod --- src/RemoteControl.cpp | 2 ++ src/RemoteControl.h | 62 +++++++++++++++++++++++++-------------------------- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/src/RemoteControl.cpp b/src/RemoteControl.cpp index 62527bd..c8fb0e8 100644 --- a/src/RemoteControl.cpp +++ b/src/RemoteControl.cpp @@ -24,6 +24,7 @@ */ #include #include +#include #include #include #include @@ -32,6 +33,7 @@ #include "RemoteControl.h" using boost::asio::ip::tcp; +using namespace std; void RemoteControllerTelnet::restart() diff --git a/src/RemoteControl.h b/src/RemoteControl.h index a9da7d7..16881b4 100644 --- a/src/RemoteControl.h +++ b/src/RemoteControl.h @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include #include @@ -44,25 +44,22 @@ #define RC_ADD_PARAMETER(p, desc) { \ - vector p; \ + std::vector p; \ p.push_back(#p); \ p.push_back(desc); \ m_parameters.push_back(p); \ } -using namespace std; -using boost::asio::ip::tcp; - class ParameterError : public std::exception { public: - ParameterError(string message) : m_message(message) {} + ParameterError(std::string message) : m_message(message) {} ~ParameterError() throw() {} const char* what() const throw() { return m_message.c_str(); } private: - string m_message; + std::string m_message; }; class RemoteControllable; @@ -92,7 +89,7 @@ class BaseRemoteController { class RemoteControllable { public: - RemoteControllable(string name) : m_name(name) {} + RemoteControllable(std::string name) : m_name(name) {} virtual ~RemoteControllable() {} @@ -108,9 +105,9 @@ class RemoteControllable { } /* Return a list of possible parameters that can be set */ - virtual list get_supported_parameters() const { - list parameterlist; - for (list< vector >::const_iterator it = m_parameters.begin(); + virtual std::list get_supported_parameters() const { + std::list parameterlist; + for (std::list< std::vector >::const_iterator it = m_parameters.begin(); it != m_parameters.end(); ++it) { parameterlist.push_back((*it)[0]); } @@ -124,11 +121,11 @@ class RemoteControllable { } /* Base function to set parameters. */ - virtual void set_parameter(const string& parameter, - const string& value) = 0; + virtual void set_parameter(const std::string& parameter, + const std::string& value) = 0; /* Getting a parameter always returns a string. */ - virtual const string get_parameter(const string& parameter) const = 0; + virtual const std::string get_parameter(const std::string& parameter) const = 0; protected: std::string m_name; @@ -172,26 +169,27 @@ class RemoteControllerTelnet : public BaseRemoteController { void process(long); - void dispatch_command(tcp::socket& socket, string command); + void dispatch_command(boost::asio::ip::tcp::socket& socket, + std::string command); - void reply(tcp::socket& socket, string message); + void reply(boost::asio::ip::tcp::socket& socket, std::string message); RemoteControllerTelnet& operator=(const RemoteControllerTelnet& other); RemoteControllerTelnet(const RemoteControllerTelnet& other); - vector tokenise_(string message) { - vector all_tokens; + std::vector tokenise_(std::string message) { + std::vector all_tokens; boost::char_separator sep(" "); boost::tokenizer< boost::char_separator > tokens(message, sep); - BOOST_FOREACH (const string& t, tokens) { + BOOST_FOREACH (const std::string& t, tokens) { all_tokens.push_back(t); } return all_tokens; } - RemoteControllable* get_controllable_(string name) { - for (list::iterator it = m_cohort.begin(); + RemoteControllable* get_controllable_(std::string name) { + for (std::list::iterator it = m_cohort.begin(); it != m_cohort.end(); ++it) { if ((*it)->get_rc_name() == name) { @@ -201,24 +199,26 @@ class RemoteControllerTelnet : public BaseRemoteController { throw ParameterError("Module name unknown"); } - list< vector > get_parameter_descriptions_(string name) { + std::list< std::vector > + get_parameter_descriptions_(std::string name) { RemoteControllable* controllable = get_controllable_(name); return controllable->get_parameter_descriptions(); } - list get_param_list_(string name) { + std::list get_param_list_(std::string name) { RemoteControllable* controllable = get_controllable_(name); return controllable->get_supported_parameters(); } - list< vector > get_param_list_values_(string name) { + std::list< std::vector > + get_param_list_values_(std::string name) { RemoteControllable* controllable = get_controllable_(name); - list< vector > allparams; - list params = controllable->get_supported_parameters(); - for (list::iterator it = params.begin(); + std::list< std::vector > allparams; + std::list params = controllable->get_supported_parameters(); + for (std::list::iterator it = params.begin(); it != params.end(); ++it) { - vector item; + std::vector item; item.push_back(*it); item.push_back(controllable->get_parameter(*it)); @@ -227,12 +227,12 @@ class RemoteControllerTelnet : public BaseRemoteController { return allparams; } - string get_param_(string name, string param) { + std::string get_param_(std::string name, std::string param) { RemoteControllable* controllable = get_controllable_(name); return controllable->get_parameter(param); } - void set_param_(string name, string param, string value) { + void set_param_(std::string name, std::string param, std::string value) { RemoteControllable* controllable = get_controllable_(name); return controllable->set_parameter(param, value); } @@ -246,7 +246,7 @@ class RemoteControllerTelnet : public BaseRemoteController { boost::thread m_child_thread; /* This controller commands the controllables in the cohort */ - list m_cohort; + std::list m_cohort; std::string m_welcome; std::string m_prompt; -- cgit v1.2.3