]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/sensor.h
Don't crash if a train has no router
[r2c2.git] / source / libr2c2 / sensor.h
1 #ifndef LIBR2C2_SENSOR_H_
2 #define LIBR2C2_SENSOR_H_
3
4 #include <sigc++/signal.h>
5 #include <msp/time/timedelta.h>
6
7 namespace R2C2 {
8
9 class Block;
10 class Layout;
11
12 class Sensor: public sigc::trackable
13 {
14 public:
15         enum State
16         {
17                 INACTIVE,
18                 MAYBE_INACTIVE,
19                 MAYBE_ACTIVE,
20                 ACTIVE
21         };
22
23         sigc::signal<void, State> signal_state_changed;
24
25 protected:
26         Layout &layout;
27         unsigned address;
28         unsigned id;
29         bool invert;
30         State state;
31         Msp::Time::TimeDelta state_confirm_timeout;
32
33         Sensor(Layout &);
34 public:
35         virtual ~Sensor();
36
37         virtual void set_address(unsigned);
38         unsigned get_address() const { return address; }
39         State get_state() const { return state; }
40         virtual Block *get_block() const { return 0; }
41
42         void tick(const Msp::Time::TimeDelta &);
43
44 private:
45         void event(unsigned, bool);
46 };
47
48 } // namespace R2C2
49
50 #endif