]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/control.h
Style fixes, including:
[r2c2.git] / source / libmarklin / control.h
1 #ifndef LIBMARKLIN_CONTROL_H_
2 #define LIBMARKLIN_CONTROL_H_
3
4 #include <list>
5 #include <string>
6 #include <msp/time/timer.h>
7 #include <msp/time/timestamp.h>
8 #include "constants.h"
9 #include "sensor.h"
10 #include "locomotive.h"
11 #include "turnout.h"
12
13 namespace Marklin {
14
15 class Command;
16
17 class Control
18 {
19 private:
20         int  serial_fd;
21         bool p50_enabled;
22         bool power;
23         std::list<Command> queue;
24         std::map<unsigned, Turnout *> turnouts;
25         std::map<unsigned, Locomotive *> locomotives;
26         std::map<unsigned, Sensor *> sensors;
27         Msp::Time::TimeStamp next_event_query;
28         bool poll_sensors;
29         bool debug;
30         Msp::Time::Timer timer;
31
32 public:
33         sigc::signal<void, unsigned, bool> signal_turnout_event;
34         sigc::signal<void, unsigned, bool> signal_sensor_event;
35
36         Control();
37         ~Control();
38
39         void       set_power(bool);
40         bool       get_power() const { return power; }
41         void       set_debug(bool);
42         const std::map<unsigned, Sensor *> &get_sensors() const { return sensors; }
43         unsigned   get_queue_length() const { return queue.size(); }
44         void       open(const std::string &);
45         Command    &command(const std::string &);
46
47         void       add_turnout(Turnout &);
48         Turnout    &get_turnout(unsigned) const;
49         void       add_locomotive(Locomotive &);
50         Locomotive &get_locomotive(unsigned) const;
51         void       add_sensor(Sensor &);
52         Sensor     &get_sensor(unsigned) const;
53
54         void       tick();
55         Msp::Time::Timer::Slot &set_timer(const Msp::Time::TimeDelta &);
56 private:
57         void read_all(int, char *, int);
58         std::string read_reply(Cmd);
59         void event_query_done(Error, const std::string &);
60         void turnout_event_done(Error, const std::string &);
61         void sensor_event_done(Error, const std::string &);
62 };
63
64 } // namespace Marklin
65
66 #endif