]> git.tdb.fi Git - r2c2.git/blobdiff - source/network/train.h
Add networking library and a remote control program
[r2c2.git] / source / network / train.h
diff --git a/source/network/train.h b/source/network/train.h
new file mode 100644 (file)
index 0000000..57154a0
--- /dev/null
@@ -0,0 +1,58 @@
+/* $Id$
+
+This file is part of the MSP Märklin suite
+Copyright © 2009  Mikkosoft Productions, Mikko Rasa
+Distributed under the GPL
+*/
+
+#ifndef MARKLINNET_TRAIN_H_
+#define MARKLINNET_TRAIN_H_
+
+#include <sigc++/signal.h>
+#include "libmarklin/locotype.h"
+#include "packets.h"
+
+namespace Marklin {
+
+class Client;
+
+class NetTrain
+{
+public:
+       sigc::signal<void, const std::string &> signal_name_changed;
+       sigc::signal<void, unsigned> signal_speed_changed;
+       sigc::signal<void, bool> signal_reverse_changed;
+       sigc::signal<void, unsigned, bool> signal_function_changed;
+       sigc::signal<void, const std::string &> signal_status_changed;
+
+private:
+       Client &client;
+       const LocoType &loco_type;
+       unsigned address;
+       std::string name;
+       unsigned speed;
+       bool reverse;
+       unsigned functions;
+       std::string status;
+
+public:
+       NetTrain(Client &, const TrainInfoPacket &);
+
+       const LocoType &get_loco_type() const { return loco_type; }
+       unsigned get_address() const { return address; }
+       const std::string &get_name() const { return name; }
+       void set_speed(unsigned);
+       unsigned get_speed() const { return speed; }
+       void set_reverse(bool);
+       bool get_reverse() const { return reverse; }
+       void set_function(unsigned, bool);
+       bool get_function(unsigned i) const { return (functions>>i)&1; }
+
+       void process_packet(const TrainSpeedPacket &);
+       void process_packet(const TrainFunctionPacket &);
+       void process_packet(const TrainStatusPacket &);
+};
+
+} // namespace Marklin
+
+#endif