]> git.tdb.fi Git - r2c2.git/blobdiff - source/network/server.h
Better handling of network communication errors
[r2c2.git] / source / network / server.h
index ced08aac06eb2df544a9dd8e741cf6cdcfc75e2f..50c0f72fae98d6ac2a0f0ce00e7d49a9b194ad02 100644 (file)
@@ -1,18 +1,12 @@
-/* $Id$
-
-This file is part of R²C²
-Copyright © 2009-2010  Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
 #ifndef R2C2_NET_SERVER_H_
 #define R2C2_NET_SERVER_H_
 
 #include <msp/io/eventdispatcher.h>
 #include <msp/net/communicator.h>
 #include <msp/net/streamsocket.h>
-#include <msp/net/streamlistensocket.h>
+#include <msp/net/streamserversocket.h>
 #include "libr2c2/layout.h"
+#include "libr2c2/trainai.h"
 #include "packets.h"
 #include "protocol.h"
 
@@ -21,9 +15,10 @@ namespace R2C2 {
 class Server
 {
 private:
-       struct Connection: private Msp::Net::PacketReceiver<TrainControlPacket>,
-               private Msp::Net::PacketReceiver<TrainFunctionPacket>,
-               private Msp::Net::PacketReceiver<TrainRoutePacket>
+       struct Connection: Msp::Net::PacketReceiver<DriverStatePacket>,
+               Msp::Net::PacketReceiver<TrainControlPacket>,
+               Msp::Net::PacketReceiver<TrainFunctionPacket>,
+               Msp::Net::PacketReceiver<TrainRoutePacket>
        {
                Server &server;
                Msp::Net::StreamSocket *socket;
@@ -35,29 +30,34 @@ private:
 
                void handshake_done();
                void end_of_file();
+               virtual void receive(const DriverStatePacket &);
                virtual void receive(const TrainControlPacket &);
                virtual void receive(const TrainFunctionPacket &);
                virtual void receive(const TrainRoutePacket &);
+               void comm_error(const std::exception &);
                void error(const std::string &);
        };
 
        Protocol proto;
        Layout &layout;
-       Msp::Net::StreamListenSocket listen_sock;
+       Msp::Net::StreamServerSocket listen_sock;
        Msp::IO::EventDispatcher *event_disp;
        std::vector<Connection *> connections;
 
 public:
        Server(Layout &);
+       ~Server();
+
        void use_event_dispatcher(Msp::IO::EventDispatcher &);
 private:
        void incoming_connection();
 
+       void driver_state_changed();
+       void emergency(Block *, const std::string &);
        void train_added(Train &);
        void train_control_changed(const Train &, const std::string &, float);
        void train_function_changed(const Train &, unsigned, bool);
-       void train_route_changed(const Train &, const Route *);
-       void train_status_changed(const Train &, const std::string &);
+       void train_ai_event(const Train &, TrainAI &, const TrainAI::Message &);
 
        template<typename P>
        void send(const P &);