]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/control.h
Forgot to add the new files
[r2c2.git] / source / libmarklin / control.h
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2009  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #ifndef LIBMARKLIN_CONTROL_H_
9 #define LIBMARKLIN_CONTROL_H_
10
11 #include <list>
12 #include <string>
13 #include <msp/time/timer.h>
14 #include <msp/time/timestamp.h>
15 #include "constants.h"
16 #include "sensor.h"
17 #include "locomotive.h"
18 #include "turnout.h"
19
20 namespace Marklin {
21
22 class Command;
23 class Reply;
24
25 class Control
26 {
27 public:
28         sigc::signal<void, bool> signal_power_event;
29         sigc::signal<void, unsigned, bool> signal_turnout_event;
30         sigc::signal<void, unsigned, bool> signal_sensor_event;
31
32 private:
33         int serial_fd;
34         bool power;
35         std::list<Command> queue;
36         std::map<unsigned, Turnout *> turnouts;
37         std::map<unsigned, Locomotive *> locomotives;
38         std::map<unsigned, Sensor *> sensors;
39         Msp::Time::TimeStamp next_event_query;
40         bool poll_sensors;
41         bool debug;
42         Msp::Time::Timer timer;
43
44 public:
45         Control();
46         ~Control();
47
48         void open(const std::string &);
49         void set_debug(bool);
50         void set_power(bool);
51         bool get_power() const { return power; }
52         Command &command(Cmd);
53         Command &command(Cmd, unsigned char);
54         Command &command(Cmd, const unsigned char *, unsigned);
55         unsigned get_queue_length() const { return queue.size(); }
56         void flush();
57
58         void add_turnout(Turnout &);
59         Turnout &get_turnout(unsigned) const;
60         const std::map<unsigned, Turnout *> &get_turnouts() const { return turnouts; }
61         void add_locomotive(Locomotive &);
62         Locomotive &get_locomotive(unsigned) const;
63         const std::map<unsigned, Locomotive *> &get_locomotives() const { return locomotives; }
64         void add_sensor(Sensor &);
65         Sensor &get_sensor(unsigned) const;
66         const std::map<unsigned, Sensor *> &get_sensors() const { return sensors; }
67
68         void tick();
69         Msp::Time::Timer::Slot &set_timer(const Msp::Time::TimeDelta &);
70 private:
71         void status_done(const Reply &);
72         void event_query_done(const Reply &);
73         void turnout_event_done(const Reply &);
74         void sensor_event_done(const Reply &);
75 };
76
77 } // namespace Marklin
78
79 #endif