]> git.tdb.fi Git - r2c2.git/blobdiff - source/network/client.h
Add networking library and a remote control program
[r2c2.git] / source / network / client.h
diff --git a/source/network/client.h b/source/network/client.h
new file mode 100644 (file)
index 0000000..ce8dcb6
--- /dev/null
@@ -0,0 +1,59 @@
+/* $Id$
+
+This file is part of the MSP Märklin suite
+Copyright © 2009  Mikkosoft Productions, Mikko Rasa
+Distributed under the GPL
+*/
+
+#ifndef MARKLINNET_CLIENT_H_
+#define MARKLINNET_CLIENT_H_
+
+#include <msp/io/eventdispatcher.h>
+#include <msp/net/communicator.h>
+#include "libmarklin/catalogue.h"
+#include "packets.h"
+#include "protocol.h"
+#include "train.h"
+
+namespace Marklin {
+
+class Client: public Msp::Net::PacketReceiver<TrainInfoPacket>,
+       Msp::Net::PacketReceiver<TrainSpeedPacket>,
+       Msp::Net::PacketReceiver<TrainFunctionPacket>,
+       Msp::Net::PacketReceiver<TrainStatusPacket>
+{
+public:
+       sigc::signal<void, NetTrain &> signal_train_added;
+
+private:
+       const Catalogue &catalogue;
+       Protocol proto;
+       Msp::Net::StreamSocket *socket;
+       Msp::Net::Communicator *comm;
+       Msp::IO::EventDispatcher *event_disp;
+       std::map<unsigned, NetTrain *> trains;
+
+public:
+       Client(const Catalogue &);
+       ~Client();
+
+       void use_event_dispatcher(Msp::IO::EventDispatcher &);
+       void connect(const Msp::Net::SockAddr &);
+
+       template<typename P>
+       void send(const P &pkt)
+       { if(comm) comm->send(pkt); }
+
+       const Catalogue &get_catalogue() const { return catalogue; }
+       NetTrain &get_train(unsigned);
+
+private:
+       virtual void receive(const TrainInfoPacket &);
+       virtual void receive(const TrainSpeedPacket &);
+       virtual void receive(const TrainFunctionPacket &);
+       virtual void receive(const TrainStatusPacket &);
+};
+
+} // namespace Marklin
+
+#endif