]> git.tdb.fi Git - r2c2.git/blobdiff - source/network/server.h
Better handling of network communication errors
[r2c2.git] / source / network / server.h
index 6ce965e555d05009c66fbd35c9b89e886c859d67..50c0f72fae98d6ac2a0f0ce00e7d49a9b194ad02 100644 (file)
@@ -1,28 +1,24 @@
-/* $Id$
-
-This file is part of the MSP Märklin suite
-Copyright © 2009  Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
-#ifndef MARKLINNET_SERVER_H_
-#define MARKLINNET_SERVER_H_
+#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 "libmarklin/trafficmanager.h"
+#include <msp/net/streamserversocket.h>
+#include "libr2c2/layout.h"
+#include "libr2c2/trainai.h"
 #include "packets.h"
 #include "protocol.h"
 
-namespace Marklin {
+namespace R2C2 {
 
 class Server
 {
 private:
-       struct Connection: private Msp::Net::PacketReceiver<TrainSpeedPacket>,
-               private Msp::Net::PacketReceiver<TrainFunctionPacket>
+       struct Connection: Msp::Net::PacketReceiver<DriverStatePacket>,
+               Msp::Net::PacketReceiver<TrainControlPacket>,
+               Msp::Net::PacketReceiver<TrainFunctionPacket>,
+               Msp::Net::PacketReceiver<TrainRoutePacket>
        {
                Server &server;
                Msp::Net::StreamSocket *socket;
@@ -34,31 +30,39 @@ private:
 
                void handshake_done();
                void end_of_file();
-               virtual void receive(const TrainSpeedPacket &);
+               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;
-       TrafficManager &trfc_mgr;
-       Msp::Net::StreamListenSocket listen_sock;
+       Layout &layout;
+       Msp::Net::StreamServerSocket listen_sock;
        Msp::IO::EventDispatcher *event_disp;
        std::vector<Connection *> connections;
 
 public:
-       Server(TrafficManager &);
+       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_speed_changed(const Train &, unsigned);
+       void train_control_changed(const Train &, const std::string &, float);
        void train_function_changed(const Train &, unsigned, bool);
-       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 &);
 };
 
-} // namespace Marklin
+} // namespace R2C2
 
 #endif