3 This file is part of R²C²
4 Copyright © 2009-2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #ifndef R2C2_NET_SERVER_H_
9 #define R2C2_NET_SERVER_H_
11 #include <msp/io/eventdispatcher.h>
12 #include <msp/net/communicator.h>
13 #include <msp/net/streamsocket.h>
14 #include <msp/net/streamlistensocket.h>
15 #include "libr2c2/layout.h"
24 struct Connection: private Msp::Net::PacketReceiver<TrainControlPacket>,
25 private Msp::Net::PacketReceiver<TrainFunctionPacket>,
26 private Msp::Net::PacketReceiver<TrainRoutePacket>
29 Msp::Net::StreamSocket *socket;
30 Msp::Net::Communicator comm;
33 Connection(Server &, Msp::Net::StreamSocket *);
36 void handshake_done();
38 virtual void receive(const TrainControlPacket &);
39 virtual void receive(const TrainFunctionPacket &);
40 virtual void receive(const TrainRoutePacket &);
41 void error(const std::string &);
46 Msp::Net::StreamListenSocket listen_sock;
47 Msp::IO::EventDispatcher *event_disp;
48 std::vector<Connection *> connections;
52 void use_event_dispatcher(Msp::IO::EventDispatcher &);
54 void incoming_connection();
56 void train_added(Train &);
57 void train_control_changed(const Train &, const std::string &, float);
58 void train_function_changed(const Train &, unsigned, bool);
59 void train_route_changed(const Train &, const Route *);
60 void train_status_changed(const Train &, const std::string &);