X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fnetwork%2Fclient.h;fp=source%2Fnetwork%2Fclient.h;h=ce8dcb66fc15cdb681157b57d3b5e50b968741fc;hb=010d8321e982d1684fcbff5bf6fc2bdec7cb7bae;hp=0000000000000000000000000000000000000000;hpb=6109a2122226e1c71e9cc71e4c21036e99e43601;p=r2c2.git diff --git a/source/network/client.h b/source/network/client.h new file mode 100644 index 0000000..ce8dcb6 --- /dev/null +++ b/source/network/client.h @@ -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 +#include +#include "libmarklin/catalogue.h" +#include "packets.h" +#include "protocol.h" +#include "train.h" + +namespace Marklin { + +class Client: public Msp::Net::PacketReceiver, + Msp::Net::PacketReceiver, + Msp::Net::PacketReceiver, + Msp::Net::PacketReceiver +{ +public: + sigc::signal signal_train_added; + +private: + const Catalogue &catalogue; + Protocol proto; + Msp::Net::StreamSocket *socket; + Msp::Net::Communicator *comm; + Msp::IO::EventDispatcher *event_disp; + std::map trains; + +public: + Client(const Catalogue &); + ~Client(); + + void use_event_dispatcher(Msp::IO::EventDispatcher &); + void connect(const Msp::Net::SockAddr &); + + template + 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