3 This file is part of R²C²
4 Copyright © 2009-2011 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: Msp::Net::PacketReceiver<DriverStatePacket>,
21 Msp::Net::PacketReceiver<EmergencyPacket>,
22 Msp::Net::PacketReceiver<TrainInfoPacket>,
23 Msp::Net::PacketReceiver<TrainFunctionPacket>,
24 Msp::Net::PacketReceiver<TrainControlPacket>,
25 Msp::Net::PacketReceiver<TrainStatusPacket>,
26 Msp::Net::PacketReceiver<RouteInfoPacket>,
27 Msp::Net::PacketReceiver<TrainRoutePacket>,
28 Msp::Net::PacketReceiver<ErrorPacket>
31 sigc::signal<void, bool> signal_power_changed;
32 sigc::signal<void, bool> signal_halt_changed;
33 sigc::signal<void, const std::string &> signal_emergency;
34 sigc::signal<void, NetTrain &> signal_train_added;
35 sigc::signal<void, const std::string &> signal_error;
38 const Catalogue &catalogue;
40 Msp::Net::StreamSocket *socket;
41 Msp::Net::Communicator *comm;
42 Msp::IO::EventDispatcher *event_disp;
45 std::list<std::string> routes;
46 std::map<unsigned, NetTrain *> trains;
49 Client(const Catalogue &);
52 void use_event_dispatcher(Msp::IO::EventDispatcher &);
53 void connect(const Msp::Net::SockAddr &);
56 void send(const P &pkt)
57 { if(comm) comm->send(pkt); }
59 const Catalogue &get_catalogue() const { return catalogue; }
60 const std::list<std::string> &get_routes() const { return routes; }
63 NetTrain &get_train(unsigned) const;
64 const std::map<unsigned, NetTrain *> &get_trains() const { return trains; }
67 virtual void receive(const DriverStatePacket &);
68 virtual void receive(const EmergencyPacket &);
69 virtual void receive(const TrainInfoPacket &);
70 virtual void receive(const TrainControlPacket &);
71 virtual void receive(const TrainFunctionPacket &);
72 virtual void receive(const TrainStatusPacket &);
73 virtual void receive(const RouteInfoPacket &);
74 virtual void receive(const TrainRoutePacket &);
75 virtual void receive(const ErrorPacket &);