#ifndef _RSYNC_H_ #define _RSYNC_H_ #include #include namespace projection { class ProjectionModel; //! Remote sync commands. enum RSYNC_COMMAND { RSYNC_COMMAND_INIT, //!< Notify new connection. RSYNC_COMMAND_MODEL, //!< Sync model settings. RSYNC_COMMAND_VIEWPOINT, //!< Sync viewpoint. RSYNC_COMMAND_SCENE, //!< Sync scene settings. RSYNC_COMMAND_SCREEN, //!< Sync screen settings. RSYNC_COMMAND_CHANNEL, //!< Sync channel settings. RSYNC_COMMAND_GUI, //!< Sync gui settings. RSYNC_COMMAND_EXPORT, //!< Sync export settings. RSYNC_COMMAND_RELOAD, //!< Request to reload all states. RSYNC_COMMAND_EXPORTFILE, //!< Request to exort projection data. RSYNC_COMMAND_DISCONNECT, //!< Notify disconnection. RSYNC_COMMAND_END //!< Request to quit the program. }; /** * Remote state synchronize class. */ class RSync : public QObject { Q_OBJECT public: /** * Constructor. * * @param pModel Projection model. */ RSync(ProjectionModel* pModel); /** * Destructor. */ virtual ~RSync(); /** * Initialize as a server. * * @param portNo Port number. */ void initServer(int portNo); /** * Initialize as a client. * * @param address Client address. * @param portNo Port number. */ void initClient(const QString& address, int portNo); /** * Check whether this program is a server or not. * * @return True if this program is a server, false if it is a client. */ bool isServer() const { return m_bServer; } /** * Retrieve host name of the PC working on. * * @return Host name of the PC working on. */ QString getHostName() const { return m_hostName; } /** * Retrieve server address to connect. * * @param Server address to connect. */ QString getServerAddress() const { return m_serverAddress; } /** * Retrieve port number to connect. * * @param Port number to connect. */ int getPortNo() const { return m_portNo; } /** * Send a sync command to clients. * * @param command Synchronize command. * @param command Synchronize data. */ void sendChanges(RSYNC_COMMAND command, const QString& data); /** * Send a reload command to clients. */ void sendReloadSettings(); /** * Set sync message blocking. * * @param bBlock True to block sending sync data to clients. */ void setBlockSync(bool bBlock); /** * Check whether sync message is blocked or not. * * @param bBlock True to block sending sync data to clients. */ bool getBlockSync() const; protected slots: /** * Connect to a server. */ void connectToServer(); /** * Called when a new client connects to the server. Send all states to synchronize. */ void acceptNewClient(); /** * Called when a new synchronize message is received. */ void recvSettings(); /** * Called when a network error is occured. */ void displayNetworkError(QAbstractSocket::SocketError socketError); protected: bool m_bServer; //!< True if this program is a server, false if it is a client. QString m_hostName; //!< Host name of the PC working on. QString m_serverAddress; //!< Server address to connect. int m_portNo; //!< Port number to connect. QTcpServer* m_pTcpServer; //!< Server object. QTcpSocket* m_pTcpClient; //!< Client object. QList m_pClientConnections; //!< Connection objects. QString m_lastErrorString; //!< Last network error string. bool m_bBlockSync; //!< True to block sending sync data to clients. ProjectionModel* m_pModel; //!< Projection model. }; }; // projection #endif // _RSYNC_H_