SyncServer.hpp   SyncServer.hpp 
skipping to change at line 27 skipping to change at line 27
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#ifndef SYNCSERVER_HPP_ #ifndef SYNCSERVER_HPP_
#define SYNCSERVER_HPP_ #define SYNCSERVER_HPP_
#include "SyncProtocol.hpp" #include "SyncProtocol.hpp"
#include <QObject> #include <QObject>
#include <QAbstractSocket> #include <QAbstractSocket>
#include <QDateTime> #include <QDateTime>
#include <QLoggingCategory>
#include <QUuid> #include <QUuid>
class QTcpServer; class QTcpServer;
class SyncServerEventSender; class SyncServerEventSender;
Q_DECLARE_LOGGING_CATEGORY(syncServer)
//! Implements a server to which SyncClients can connect and receive state changes //! Implements a server to which SyncClients can connect and receive state changes
class SyncServer : public QObject class SyncServer : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
SyncServer(QObject* parent = 0); SyncServer(QObject* parent = Q_NULLPTR);
virtual ~SyncServer(); virtual ~SyncServer();
//! This should be called in the StelModule::update function //! This should be called in the StelModule::update function
void update(); void update();
//! Broadcasts this message to all connected and authenticated clien ts //! Broadcasts this message to all connected and authenticated clien ts
void broadcastMessage(const SyncMessage& msg); void broadcastMessage(const SyncProtocol::SyncMessage& msg);
public slots: public slots:
//! Starts the SyncServer on the specified port. If the server is al ready running, stops it first. //! Starts the SyncServer on the specified port. If the server is al ready running, stops it first.
//! Returns true if successful (false usually means port was in use, use getErrorString) //! Returns true if successful (false usually means port was in use, use getErrorString)
bool start(int port); bool start(int port);
//! Disconnects all clients, and stops listening //! Disconnects all clients, and stops listening
void stop(); void stop();
//! Returns a string of the last server error. //! Returns a string of the last server error.
QString errorString() const; QString errorString() const;
signals:
//! Emitted when the server is completely stopped, and all clients h
ave disconnected
void serverStopped();
protected: protected:
void timerEvent(QTimerEvent* evt) Q_DECL_OVERRIDE; void timerEvent(QTimerEvent* evt) Q_DECL_OVERRIDE;
private slots: private slots:
void handleNewConnection(); void handleNewConnection();
void connectionError(QAbstractSocket::SocketError err); void connectionError(QAbstractSocket::SocketError err);
//! On receipt of new client data
void clientDataReceived();
void clientError(QAbstractSocket::SocketError);
void clientAuthenticated(SyncRemotePeer& peer); void clientAuthenticated(SyncRemotePeer& peer);
void clientDisconnected(); void clientDisconnected(bool clean);
private: private:
void addSender(SyncServerEventSender* snd); void addSender(SyncServerEventSender* snd);
void checkTimeouts(); void checkTimeouts();
void clientLog(QAbstractSocket* cl, const QString& msg); void checkStopState();
//use composition instead of inheritance, cleaner interfaace this wa y //use composition instead of inheritance, cleaner interfaace this wa y
//for now, we use TCP, but will test multicast UDP later if the basi c setup is working //for now, we use TCP, but will test multicast UDP later if the basi c setup is working
QTcpServer* qserver; QTcpServer* qserver;
QVector<SyncMessageHandler*> handlerList; QVector<SyncMessageHandler*> handlerList;
QVector<SyncServerEventSender*> senderList; QVector<SyncServerEventSender*> senderList;
// a map to associate sockets with the client data bool stopping;
typedef QMap<QAbstractSocket*,SyncRemotePeer> tClientMap;
tClientMap clients; // client list
typedef QVector<SyncRemotePeer*> tClientList;
tClientList clients;
QByteArray broadcastBuffer; QByteArray broadcastBuffer;
int timeoutTimerId; int timeoutTimerId;
friend class ServerAuthHandler; friend class ServerAuthHandler;
}; };
#endif #endif
 End of changes. 9 change blocks. 
10 lines changed or deleted 16 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/