-/* $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"
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;
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 &);
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 &);