3 This file is part of the MSP Märklin suite
4 Copyright © 2009 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #ifndef MARKLINNET_CLIENT_H_
9 #define MARKLINNET_CLIENT_H_
11 #include <msp/io/eventdispatcher.h>
12 #include <msp/net/communicator.h>
13 #include "libmarklin/catalogue.h"
20 class Client: public Msp::Net::PacketReceiver<TrainInfoPacket>,
21 Msp::Net::PacketReceiver<TrainSpeedPacket>,
22 Msp::Net::PacketReceiver<TrainFunctionPacket>,
23 Msp::Net::PacketReceiver<TrainStatusPacket>
26 sigc::signal<void, NetTrain &> signal_train_added;
29 const Catalogue &catalogue;
31 Msp::Net::StreamSocket *socket;
32 Msp::Net::Communicator *comm;
33 Msp::IO::EventDispatcher *event_disp;
34 std::map<unsigned, NetTrain *> trains;
37 Client(const Catalogue &);
40 void use_event_dispatcher(Msp::IO::EventDispatcher &);
41 void connect(const Msp::Net::SockAddr &);
44 void send(const P &pkt)
45 { if(comm) comm->send(pkt); }
47 const Catalogue &get_catalogue() const { return catalogue; }
48 NetTrain &get_train(unsigned);
51 virtual void receive(const TrainInfoPacket &);
52 virtual void receive(const TrainSpeedPacket &);
53 virtual void receive(const TrainFunctionPacket &);
54 virtual void receive(const TrainStatusPacket &);
57 } // namespace Marklin