]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/locomotive.h
Allow intercepting and denying turnout route and locomotive speed changes
[r2c2.git] / source / libmarklin / locomotive.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_LOCOMOTIVE_H_
9 #define LIBMARKLIN_LOCOMOTIVE_H_
10
11 #include <list>
12 #include <string>
13 #include <sigc++/signal.h>
14 #include "constants.h"
15
16 namespace Marklin {
17
18 class Control;
19 class LocoType;
20 class Reply;
21
22 class Locomotive
23 {
24 private:
25         const LocoType &type;
26         Control  &control;
27         unsigned addr;
28         unsigned speed;
29         bool     reverse;
30         unsigned funcs;
31
32 public:
33         sigc::signal<void, unsigned> signal_speed_changing;
34         sigc::signal<void, unsigned> signal_speed_changed;
35         sigc::signal<void, unsigned, bool> signal_function_changed;
36
37         Locomotive(const LocoType &, Control &, unsigned);
38
39         const LocoType &get_type() const { return type; }
40         void     set_speed(unsigned);
41         void     set_reverse(bool);
42         void     set_function(unsigned, bool);
43         unsigned get_address() const   { return addr; }
44         unsigned get_speed() const     { return speed; }
45         bool     get_reverse() const   { return reverse; }
46         bool     get_function(unsigned f) const { return (funcs>>f)&1; }
47         void     refresh_status();
48 private:
49         void     send_command(bool);
50         void     status_reply(const Reply &);
51         bool     reverse_timeout();
52 };
53
54 } // namespace Marklin
55
56 #endif