summaryrefslogtreecommitdiffstats
path: root/src/testremotecontrol/test.cpp
blob: 40f0e25ea8618b4af55026d89d3b67167fc9d730 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <string>
#include <map>
#include <unistd.h>

#include "RemoteControl.h"

using namespace std;

class TestControllable : public RemoteControllable
{
    public:
        TestControllable(string name) : RemoteControllable(name)
        {
            RC_ADD_PARAMETER(foo, "That's the foo");
            RC_ADD_PARAMETER(bar, "That's the bar");
            RC_ADD_PARAMETER(baz, "That's the baz");
        }

        void set_parameter(string parameter, string value) {
            stringstream ss(value);
            ss.exceptions ( stringstream::failbit | stringstream::badbit );

            if (parameter == "foo") {
                ss >> foo_;
            }
            else if (parameter == "bar") {
                bar_ = value;
            }
            else if (parameter == "baz") {
                ss >> baz_;
            }
            else {
                stringstream ss;
                ss << "Parameter '" << parameter << "' is not exported by 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_;
        double baz_;

};

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;
}