]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/dummy.h
Implement halt in the dummy driver
[r2c2.git] / source / libr2c2 / dummy.h
1 #ifndef LIBR2C2_DUMMY_H_
2 #define LIBR2C2_DUMMY_H_
3
4 #include <map>
5 #include <msp/time/timedelta.h>
6 #include <msp/time/timestamp.h>
7 #include "driver.h"
8
9 namespace R2C2 {
10
11 class Dummy: public Driver
12 {
13 private:
14         struct TurnoutState
15         {
16                 unsigned state;
17                 unsigned pending;
18                 Msp::Time::TimeStamp timeout;
19         };
20
21         struct LocoState
22         {
23                 unsigned speed;
24                 bool reverse;
25         };
26
27         bool power;
28         bool halted;
29         std::map<unsigned, TurnoutState> turnouts;
30         std::map<unsigned, LocoState> locos;
31         std::map<unsigned, bool> sensors;
32         Msp::Time::TimeDelta turnout_delay;
33
34 public:
35         Dummy(const Options &);
36
37         virtual void set_power(bool);
38         virtual bool get_power() const { return power; }
39         virtual void halt(bool);
40         virtual bool is_halted() const { return halted; }
41
42         virtual const char *enumerate_protocols(unsigned) const;
43         virtual unsigned get_protocol_speed_steps(const std::string &) const;
44         virtual DetectedLocomotive *enumerate_detected_locos(unsigned) const { return 0; }
45         virtual unsigned add_loco(unsigned a, const std::string &, const VehicleType &) { return a; }
46         virtual void remove_loco(unsigned) { }
47         virtual void set_loco_speed(unsigned, unsigned);
48         virtual void set_loco_reverse(unsigned, bool);
49         virtual void set_loco_function(unsigned, unsigned, bool);
50
51         virtual unsigned add_turnout(unsigned, const TrackType &);
52         virtual void remove_turnout(unsigned) { }
53         virtual void set_turnout(unsigned, unsigned);
54         virtual unsigned get_turnout(unsigned) const;
55
56         virtual unsigned add_signal(unsigned a, const SignalType &) { return a; }
57         virtual void remove_signal(unsigned) { }
58         virtual void set_signal(unsigned, unsigned) { }
59         virtual unsigned get_signal(unsigned) const { return 0; }
60
61         virtual unsigned add_sensor(unsigned a) { return a; }
62         virtual void remove_sensor(unsigned) { }
63         virtual void set_sensor(unsigned, bool);
64         virtual bool get_sensor(unsigned) const;
65
66         virtual void tick();
67         virtual void flush() { }
68 };
69
70 } // namespace R2C2
71
72 #endif