]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/control.h
Initial revision
[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/timestamp.h>
7 #include "constants.h"
8 #include "sensor.h"
9 #include "locomotive.h"
10 #include "turnout.h"
11
12 namespace Marklin {
13
14 class Command;
15
16 class Control
17 {
18 public:
19         sigc::signal<void, unsigned, bool> signal_turnout_event;
20         sigc::signal<void, unsigned, bool> signal_sensor_event;
21
22         Control();
23         void       set_power(bool);
24         void       set_debug(bool d) { debug=d; }
25         bool       get_power() const { return power; }
26         const TurnoutMap &get_turnouts() const { return turnouts; }
27         Turnout    *get_turnout(unsigned) const;
28         Locomotive *get_locomotive(unsigned) const;
29         Sensor     *get_sensor(unsigned) const;
30         unsigned   get_queue_length() const { return queue.size(); }
31         void       open(const std::string &);
32         Command    &command(const std::string &);
33         void       add_turnout(Turnout *);
34         void       add_locomotive(Locomotive *);
35         void       add_sensor(Sensor *);
36         void       tick();
37         ~Control();
38 private:
39         int  serial_fd;
40         bool p50_enabled;
41         bool power;
42         std::list<Command> queue;
43         TurnoutMap turnouts;
44         LocomotiveSeq locomotives;
45         SensorMap sensors;
46         Msp::Time::TimeStamp next_event_query;
47         bool poll_sensors;
48         bool debug;
49
50         void read_all(int, char *, int);
51         std::string read_reply(Cmd);
52         void event_query_done(Error, const std::string &);
53         void turnout_event_done(Error, const std::string &);
54         void sensor_event_done(Error, const std::string &);
55 };
56
57 } // namespace Marklin
58
59 #endif