diff options
author | Matthias P. Braendli (think) <matthias@mpb.li> | 2012-08-16 17:45:04 +0200 |
---|---|---|
committer | Matthias P. Braendli (think) <matthias@mpb.li> | 2012-08-16 17:45:04 +0200 |
commit | 521ee81560be5d065bd090002a2c6b92a322a034 (patch) | |
tree | d4e575707616c423e602ede9118aef88a5b31f83 | |
parent | f419f8cb2e3768789cb23593cfa7c850acc0fe72 (diff) | |
download | dabmod-521ee81560be5d065bd090002a2c6b92a322a034.tar.gz dabmod-521ee81560be5d065bd090002a2c6b92a322a034.tar.bz2 dabmod-521ee81560be5d065bd090002a2c6b92a322a034.zip |
crc-dabmod: RemoteControl simplifications
-rw-r--r-- | src/OutputUHD.h | 39 | ||||
-rw-r--r-- | src/RemoteControl.h | 26 | ||||
-rw-r--r-- | src/testremotecontrol/Makefile | 3 | ||||
-rw-r--r-- | src/testremotecontrol/test.cpp | 28 |
4 files changed, 70 insertions, 26 deletions
diff --git a/src/OutputUHD.h b/src/OutputUHD.h index 23d0e4c..6d2df55 100644 --- a/src/OutputUHD.h +++ b/src/OutputUHD.h @@ -44,11 +44,14 @@ DESCRIPTION: #include <boost/thread/thread.hpp> #include <boost/thread/barrier.hpp> #include <boost/shared_ptr.hpp> +#include <list> +#include <string> #include "Log.h" #include "ModOutput.h" #include "EtiReader.h" #include "TimestampDecoder.h" +#include "RemoteControl.h" #include <stdio.h> #include <sys/types.h> @@ -136,7 +139,7 @@ class UHDWorker { }; -class OutputUHD: public ModOutput { +class OutputUHD: public ModOutput, public RemoteControl { public: OutputUHD(const char* device, unsigned sampleRate, @@ -155,6 +158,37 @@ class OutputUHD: public ModOutput { myEtiReader = etiReader; } + /*********** REMOTE CONTROL ***************/ + virtual std::string get_rc_name() { return "uhd"; } + + /* Tell the controllable to enrol at the given controller / + virtual void enrol_at(BaseRemoteController& controller) { + controller.enrol(this); + } // */ + + /* Return a list of possible parameters that can be set */ + list<string> get_supported_parameters() { + list<string> parameterlist; + for (list< vector<string> >::iterator it = parameters_.begin(); it != parameters_.end(); it++) { + parameterlist.push_back((*it)[0]); + } + return parameterlist; + } + + /* Return a mapping of the descriptions of all parameters */ + virtual std::list< std::vector<std::string> > get_parameter_descriptions() = 0; + + /* Base function to set parameters. */ + virtual void set_parameter(string parameter, string value) = 0; + + /* Convenience functions for other common types */ + virtual void set_parameter(string parameter, double value) = 0; + virtual void set_parameter(string parameter, long value) = 0; + + /* Getting a parameter always returns a string. */ + virtual string get_parameter(string parameter) = 0; + + protected: Logger& myLogger; EtiReader *myEtiReader; @@ -172,6 +206,9 @@ class OutputUHD: public ModOutput { bool enable_sync; size_t lastLen; + + + /*********** REMOTE CONTROL ***************/ }; diff --git a/src/RemoteControl.h b/src/RemoteControl.h index ab3f6fb..2830210 100644 --- a/src/RemoteControl.h +++ b/src/RemoteControl.h @@ -39,6 +39,15 @@ #include <boost/thread.hpp> #include <stdexcept> + +#define ADD_PARAMETER(p, desc) { \ + vector<string> p; \ + p.push_back(#p); \ + p.push_back(desc); \ + parameters_.push_back(p); \ +} + + using namespace std; using boost::asio::ip::tcp; @@ -65,6 +74,9 @@ class BaseRemoteController { /* Objects that support remote control must implement the following class */ class RemoteControllable { public: + + RemoteControllable(string name) : name_(name) {} + /* return a short name used to identify the controllable. * It might be used in the commands the user has to type, so keep * it short @@ -77,7 +89,14 @@ class RemoteControllable { } /* Return a list of possible parameters that can be set */ - virtual list<string> get_supported_parameters() = 0; + virtual list<string> get_supported_parameters() { + cerr << "get_sup_par" << parameters_.size() << endl; + list<string> parameterlist; + for (list< vector<string> >::iterator it = parameters_.begin(); it != parameters_.end(); it++) { + parameterlist.push_back((*it)[0]); + } + return parameterlist; + } /* Return a mapping of the descriptions of all parameters */ virtual std::list< std::vector<std::string> > get_parameter_descriptions() = 0; @@ -91,6 +110,10 @@ class RemoteControllable { /* Getting a parameter always returns a string. */ virtual string get_parameter(string parameter) = 0; + + protected: + std::string name_; + std::list< std::vector<std::string> > parameters_; }; /* Implements a Remote controller based on a simple telnet CLI @@ -162,6 +185,7 @@ class RemoteControllerTelnet : public BaseRemoteController { list< vector<string> > allparams; list<string> params = controllable->get_supported_parameters(); + cerr << "# of supported parameters " << params.size() << endl; for (list<string>::iterator it = params.begin(); it != params.end(); it++) { vector<string> item; item.push_back(*it); diff --git a/src/testremotecontrol/Makefile b/src/testremotecontrol/Makefile index d5b5d7d..94565c5 100644 --- a/src/testremotecontrol/Makefile +++ b/src/testremotecontrol/Makefile @@ -3,3 +3,6 @@ CXXFLAGS=-Wall -g -lboost_system -lboost_thread -I.. all: test test: test.cpp ../RemoteControl.cpp + +clean: + rm test diff --git a/src/testremotecontrol/test.cpp b/src/testremotecontrol/test.cpp index 84032fc..07b761f 100644 --- a/src/testremotecontrol/test.cpp +++ b/src/testremotecontrol/test.cpp @@ -5,36 +5,18 @@ using namespace std; -#define BUILD_FOO(p) { \ - vector<string> p; \ - p.push_back(#p); \ - p.push_back("That's the" #p); \ - parameters_.push_back(p); \ -} - class TestControllable : public RemoteControllable { public: - TestControllable(string name) + TestControllable(string name) : RemoteControllable(name) { - name_ = name; - - BUILD_FOO(foo); - BUILD_FOO(bar); - BUILD_FOO(baz); - + ADD_PARAMETER(foo, "That's the foo"); + ADD_PARAMETER(bar, "That's the bar"); + ADD_PARAMETER(baz, "That's the baz"); } string get_rc_name() { return name_; }; - list<string> get_supported_parameters() { - list<string> parameterlist; - for (list< vector<string> >::iterator it = parameters_.begin(); it != parameters_.end(); it++) { - parameterlist.push_back((*it)[0]); - } - return parameterlist; - } - void set_parameter(string parameter, string value) { if (parameter == "foo") { stringstream ss(value); @@ -102,9 +84,7 @@ class TestControllable : public RemoteControllable private: long foo_; std::string bar_; - std::string name_; double baz_; - std::list< std::vector<std::string> > parameters_; }; |