]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/control.h
Code reformatting:
[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
57         void add_turnout(Turnout &);
58         Turnout &get_turnout(unsigned) const;
59         const std::map<unsigned, Turnout *> &get_turnouts() const { return turnouts; }
60         void add_locomotive(Locomotive &);
61         Locomotive &get_locomotive(unsigned) const;
62         void add_sensor(Sensor &);
63         Sensor &get_sensor(unsigned) const;
64         const std::map<unsigned, Sensor *> &get_sensors() const { return sensors; }
65
66         void tick();
67         Msp::Time::Timer::Slot &set_timer(const Msp::Time::TimeDelta &);
68 private:
69         void status_done(const Reply &);
70         void event_query_done(const Reply &);
71         void turnout_event_done(const Reply &);
72         void sensor_event_done(const Reply &);
73 };
74
75 } // namespace Marklin
76
77 #endif