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: Msp::Net::PacketReceiver<DriverStatePacket>,
25 Msp::Net::PacketReceiver<TrainControlPacket>,
26 Msp::Net::PacketReceiver<TrainFunctionPacket>,
27 Msp::Net::PacketReceiver<TrainRoutePacket>
30 Msp::Net::StreamSocket *socket;
31 Msp::Net::Communicator comm;
34 Connection(Server &, Msp::Net::StreamSocket *);
37 void handshake_done();
39 virtual void receive(const DriverStatePacket &);
40 virtual void receive(const TrainControlPacket &);
41 virtual void receive(const TrainFunctionPacket &);
42 virtual void receive(const TrainRoutePacket &);
43 void error(const std::string &);
48 Msp::Net::StreamListenSocket listen_sock;
49 Msp::IO::EventDispatcher *event_disp;
50 std::vector<Connection *> connections;
54 void use_event_dispatcher(Msp::IO::EventDispatcher &);
56 void incoming_connection();
58 void driver_state_changed();
59 void emergency(const std::string &);
60 void train_added(Train &);
61 void train_control_changed(const Train &, const std::string &, float);
62 void train_function_changed(const Train &, unsigned, bool);
63 void train_route_changed(const Train &, const Route *);
64 void train_status_changed(const Train &, const std::string &);