--- /dev/null
+/* $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_
+
+#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 "packets.h"
+#include "protocol.h"
+
+namespace Marklin {
+
+class Server
+{
+private:
+ struct Connection: private Msp::Net::PacketReceiver<TrainSpeedPacket>,
+ private Msp::Net::PacketReceiver<TrainFunctionPacket>
+ {
+ Server &server;
+ Msp::Net::StreamSocket *socket;
+ Msp::Net::Communicator comm;
+ bool stale;
+
+ Connection(Server &, Msp::Net::StreamSocket *);
+ ~Connection();
+
+ void handshake_done();
+ void end_of_file();
+ virtual void receive(const TrainSpeedPacket &);
+ virtual void receive(const TrainFunctionPacket &);
+ };
+
+ Protocol proto;
+ TrafficManager &trfc_mgr;
+ Msp::Net::StreamListenSocket listen_sock;
+ Msp::IO::EventDispatcher *event_disp;
+ std::vector<Connection *> connections;
+
+public:
+ Server(TrafficManager &);
+ void use_event_dispatcher(Msp::IO::EventDispatcher &);
+private:
+ void incoming_connection();
+
+ void train_added(Train &);
+ void train_speed_changed(const Train &, unsigned);
+ void train_function_changed(const Train &, unsigned, bool);
+ void train_status_changed(const Train &, const std::string &);
+
+ template<typename P>
+ void send(const P &);
+};
+
+} // namespace Marklin
+
+#endif