]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/control.h
Major code refactoring:
[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         void       set_power(bool);
38         bool       get_power() const { return power; }
39         void       set_debug(bool d) { debug=d; }
40         //const TurnoutMap &get_turnouts() const { return turnouts; }
41         const std::map<unsigned, Sensor *> &get_sensors() const { return sensors; }
42         unsigned   get_queue_length() const { return queue.size(); }
43         void       open(const std::string &);
44         Command    &command(const std::string &);
45         void       add_turnout(Turnout &);
46         Turnout    &get_turnout(unsigned) const;
47         void       add_locomotive(Locomotive &);
48         Locomotive &get_locomotive(unsigned) const;
49         void       add_sensor(Sensor &);
50         Sensor     &get_sensor(unsigned) const;
51         void       tick();
52         Msp::Time::Timer::Slot &set_timer(const Msp::Time::TimeDelta &);
53         ~Control();
54 private:
55         void read_all(int, char *, int);
56         std::string read_reply(Cmd);
57         void event_query_done(Error, const std::string &);
58         void turnout_event_done(Error, const std::string &);
59         void sensor_event_done(Error, const std::string &);
60 };
61
62 } // namespace Marklin
63
64 #endif