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_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"
16 #include "libr2c2/trainstatus.h"
25 struct Connection: Msp::Net::PacketReceiver<DriverStatePacket>,
26 Msp::Net::PacketReceiver<TrainControlPacket>,
27 Msp::Net::PacketReceiver<TrainFunctionPacket>,
28 Msp::Net::PacketReceiver<TrainRoutePacket>
31 Msp::Net::StreamSocket *socket;
32 Msp::Net::Communicator comm;
35 Connection(Server &, Msp::Net::StreamSocket *);
38 void handshake_done();
40 virtual void receive(const DriverStatePacket &);
41 virtual void receive(const TrainControlPacket &);
42 virtual void receive(const TrainFunctionPacket &);
43 virtual void receive(const TrainRoutePacket &);
44 void error(const std::string &);
49 Msp::Net::StreamListenSocket listen_sock;
50 Msp::IO::EventDispatcher *event_disp;
51 std::vector<Connection *> connections;
55 void use_event_dispatcher(Msp::IO::EventDispatcher &);
57 void incoming_connection();
59 void driver_state_changed();
60 void emergency(const std::string &);
61 void train_added(Train &);
62 void train_control_changed(const Train &, const std::string &, float);
63 void train_function_changed(const Train &, unsigned, bool);
64 void train_route_changed(const Train &, const Route *);
65 void train_status_changed(const Train &, const std::string &);