]> git.tdb.fi Git - r2c2.git/blob - source/network/train.h
57154a04e7245dd997990ee1fa79c9da520c037b
[r2c2.git] / source / network / train.h
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2009  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #ifndef MARKLINNET_TRAIN_H_
9 #define MARKLINNET_TRAIN_H_
10
11 #include <sigc++/signal.h>
12 #include "libmarklin/locotype.h"
13 #include "packets.h"
14
15 namespace Marklin {
16
17 class Client;
18
19 class NetTrain
20 {
21 public:
22         sigc::signal<void, const std::string &> signal_name_changed;
23         sigc::signal<void, unsigned> signal_speed_changed;
24         sigc::signal<void, bool> signal_reverse_changed;
25         sigc::signal<void, unsigned, bool> signal_function_changed;
26         sigc::signal<void, const std::string &> signal_status_changed;
27
28 private:
29         Client &client;
30         const LocoType &loco_type;
31         unsigned address;
32         std::string name;
33         unsigned speed;
34         bool reverse;
35         unsigned functions;
36         std::string status;
37
38 public:
39         NetTrain(Client &, const TrainInfoPacket &);
40
41         const LocoType &get_loco_type() const { return loco_type; }
42         unsigned get_address() const { return address; }
43         const std::string &get_name() const { return name; }
44         void set_speed(unsigned);
45         unsigned get_speed() const { return speed; }
46         void set_reverse(bool);
47         bool get_reverse() const { return reverse; }
48         void set_function(unsigned, bool);
49         bool get_function(unsigned i) const { return (functions>>i)&1; }
50
51         void process_packet(const TrainSpeedPacket &);
52         void process_packet(const TrainFunctionPacket &);
53         void process_packet(const TrainStatusPacket &);
54 };
55
56 } // namespace Marklin
57
58 #endif