]> git.tdb.fi Git - r2c2.git/blob - source/network/train.h
Emit signals from loco status command only when all data has been gathered
[r2c2.git] / source / network / train.h
1 /* $Id$
2
3 This file is part of R²C²
4 Copyright © 2009  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #ifndef R2C2_NET_TRAIN_H_
9 #define R2C2_NET_TRAIN_H_
10
11 #include <sigc++/signal.h>
12 #include "libr2c2/vehicletype.h"
13 #include "packets.h"
14
15 namespace R2C2 {
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, const std::string &, float> signal_control_changed;
24         sigc::signal<void, unsigned, bool> signal_function_changed;
25         sigc::signal<void, const std::string &> signal_route_changed;
26         sigc::signal<void, const std::string &> signal_status_changed;
27
28 private:
29         Client &client;
30         const VehicleType &loco_type;
31         unsigned address;
32         std::string name;
33         std::map<std::string, float> controls;
34         unsigned functions;
35         std::string route;
36         std::string status;
37
38 public:
39         NetTrain(Client &, const TrainInfoPacket &);
40
41         const VehicleType &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_control(const std::string &, float);
45         float get_control(const std::string &) const;
46         void set_function(unsigned, bool);
47         bool get_function(unsigned i) const { return (functions>>i)&1; }
48         void set_route(const std::string &);
49         const std::string &get_route() const { return route; }
50
51         void process_packet(const TrainControlPacket &);
52         void process_packet(const TrainFunctionPacket &);
53         void process_packet(const TrainRoutePacket &);
54         void process_packet(const TrainStatusPacket &);
55 };
56
57 } // namespace R2C2
58
59 #endif