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