3 This file is part of R²C²
4 Copyright © 2009 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #ifndef R2C2_NET_CLIENT_H_
9 #define R2C2_NET_CLIENT_H_
11 #include <msp/io/eventdispatcher.h>
12 #include <msp/net/communicator.h>
13 #include "libr2c2/catalogue.h"
20 class Client: public Msp::Net::PacketReceiver<TrainInfoPacket>,
21 Msp::Net::PacketReceiver<TrainFunctionPacket>,
22 Msp::Net::PacketReceiver<TrainControlPacket>,
23 Msp::Net::PacketReceiver<TrainStatusPacket>,
24 Msp::Net::PacketReceiver<RouteInfoPacket>,
25 Msp::Net::PacketReceiver<TrainRoutePacket>,
26 Msp::Net::PacketReceiver<ErrorPacket>
29 sigc::signal<void, NetTrain &> signal_train_added;
30 sigc::signal<void, const std::string &> signal_error;
33 const Catalogue &catalogue;
35 Msp::Net::StreamSocket *socket;
36 Msp::Net::Communicator *comm;
37 Msp::IO::EventDispatcher *event_disp;
38 std::list<std::string> routes;
39 std::map<unsigned, NetTrain *> trains;
42 Client(const Catalogue &);
45 void use_event_dispatcher(Msp::IO::EventDispatcher &);
46 void connect(const Msp::Net::SockAddr &);
49 void send(const P &pkt)
50 { if(comm) comm->send(pkt); }
52 const Catalogue &get_catalogue() const { return catalogue; }
53 const std::list<std::string> &get_routes() const { return routes; }
54 NetTrain &get_train(unsigned) const;
55 const std::map<unsigned, NetTrain *> &get_trains() const { return trains; }
58 virtual void receive(const TrainInfoPacket &);
59 virtual void receive(const TrainControlPacket &);
60 virtual void receive(const TrainFunctionPacket &);
61 virtual void receive(const TrainStatusPacket &);
62 virtual void receive(const RouteInfoPacket &);
63 virtual void receive(const TrainRoutePacket &);
64 virtual void receive(const ErrorPacket &);