summaryrefslogtreecommitdiffstats
path: root/src/testremotecontrol/test.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli (think) <matthias@mpb.li>2012-08-16 16:29:59 +0200
committerMatthias P. Braendli (think) <matthias@mpb.li>2012-08-16 16:29:59 +0200
commit2a4ec6dd6a48668589c7db2206c97e8781b644b3 (patch)
tree3cbde215632cd43b0e092ced0f58c6e32c54b622 /src/testremotecontrol/test.cpp
parent52e36228e7b89de07af15a5029ac2655d5d55dfa (diff)
downloaddabmod-2a4ec6dd6a48668589c7db2206c97e8781b644b3.tar.gz
dabmod-2a4ec6dd6a48668589c7db2206c97e8781b644b3.tar.bz2
dabmod-2a4ec6dd6a48668589c7db2206c97e8781b644b3.zip
crc-dabmod: added RemoteControl code and test program
Diffstat (limited to 'src/testremotecontrol/test.cpp')
-rw-r--r--src/testremotecontrol/test.cpp114
1 files changed, 114 insertions, 0 deletions
diff --git a/src/testremotecontrol/test.cpp b/src/testremotecontrol/test.cpp
new file mode 100644
index 0000000..7733a96
--- /dev/null
+++ b/src/testremotecontrol/test.cpp
@@ -0,0 +1,114 @@
+#include <string>
+#include <unistd.h>
+#include "RemoteControl.h"
+
+using namespace std;
+
+class TestControllable : public RemoteControllable
+{
+ public:
+ TestControllable(string name)
+ {
+ name_ = name;
+ parameterlist_.push_back("foo");
+ parameterlist_.push_back("bar");
+ parameterlist_.push_back("baz");
+ }
+
+ std::string get_rc_name() { return name_; };
+
+ list<string> get_supported_parameters() {
+ return parameterlist_;
+ }
+
+ void set_parameter(string parameter, string value) {
+ if (parameter == "foo") {
+ stringstream ss(value);
+ ss >> foo_;
+ }
+ else if (parameter == "bar") {
+ bar_ = value;
+ }
+ else if (parameter == "baz") {
+ stringstream ss(value);
+ ss >> baz_;
+ }
+ else {
+ stringstream ss;
+ ss << "Parameter '" << parameter << "' is not exported by controllable " << get_rc_name();
+ throw ParameterError(ss.str());
+ }
+ }
+
+ void set_parameter(string parameter, double value) {
+ if (parameter == "baz") {
+ baz_ = value;
+ }
+ else {
+ stringstream ss;
+ ss << "Parameter '" << parameter << "' is not a double in controllable " << get_rc_name();
+ throw ParameterError(ss.str());
+ }
+ }
+
+ void set_parameter(string parameter, long value) {
+ if (parameter == "foo") {
+ foo_ = value;
+ }
+ else {
+ stringstream ss;
+ ss << "Parameter '" << parameter << "' is not a long in controllable " << get_rc_name();
+ throw ParameterError(ss.str());
+ }
+ }
+
+ string get_parameter(string parameter) {
+ stringstream ss;
+ if (parameter == "foo") {
+ ss << foo_;
+ }
+ else if (parameter == "bar") {
+ ss << bar_;
+ }
+ else if (parameter == "baz") {
+ ss << baz_;
+ }
+ else {
+ stringstream ss;
+ ss << "Parameter '" << parameter << "' is not exported by controllable " << get_rc_name();
+ throw ParameterError(ss.str());
+ }
+ return ss.str();
+ }
+
+ private:
+ long foo_;
+ std::string bar_;
+ std::string name_;
+ double baz_;
+ std::list<std::string> parameterlist_;
+
+};
+
+int main()
+{
+ RemoteControllerTelnet rc (2121);
+ TestControllable t("test1");
+ TestControllable t2("test2");
+
+ t.enrol_at(rc);
+ t2.enrol_at(rc);
+
+ rc.start();
+
+ std::cerr << "Thread has been launched" << std::endl;
+
+ sleep(100);
+
+ std::cerr << "Stop" << std::endl;
+
+ rc.stop();
+
+ return 0;
+}
+