source: projectionDesigner/trunk/projdesigner/include/RSync.h @ 373

Last change on this file since 373 was 4, checked in by Torben Dannhauer, 15 years ago
File size: 4.0 KB
Line 
1#ifndef _RSYNC_H_
2#define _RSYNC_H_
3
4#include <QtNetwork/QTcpSocket>
5#include <QtNetwork/QTcpServer>
6
7namespace projection
8{
9class ProjectionModel;
10
11//! Remote sync commands.
12enum RSYNC_COMMAND
13{
14    RSYNC_COMMAND_INIT,         //!< Notify new connection.
15    RSYNC_COMMAND_MODEL,        //!< Sync model settings.
16    RSYNC_COMMAND_VIEWPOINT,    //!< Sync viewpoint.
17    RSYNC_COMMAND_SCENE,        //!< Sync scene settings.
18    RSYNC_COMMAND_SCREEN,       //!< Sync screen settings.
19    RSYNC_COMMAND_CHANNEL,      //!< Sync channel settings.
20    RSYNC_COMMAND_GUI,          //!< Sync gui settings.
21    RSYNC_COMMAND_EXPORT,       //!< Sync export settings.
22    RSYNC_COMMAND_RELOAD,       //!< Request to reload all states.
23    RSYNC_COMMAND_EXPORTFILE,   //!< Request to exort projection data.
24    RSYNC_COMMAND_DISCONNECT,   //!< Notify disconnection.
25    RSYNC_COMMAND_END           //!< Request to quit the program.
26};
27
28/**
29 * Remote state synchronize class.
30 */
31class RSync : public QObject
32{
33    Q_OBJECT
34
35public:
36
37    /**
38     * Constructor.
39     *
40     * @param pModel Projection model.
41     */
42    RSync(ProjectionModel* pModel);
43
44    /**
45     * Destructor.
46     */
47    virtual ~RSync();
48
49    /**
50     * Initialize as a server.
51     *
52     * @param portNo Port number.
53     */
54    void initServer(int portNo);
55
56    /**
57     * Initialize as a client.
58     *
59     * @param address Client address.
60     * @param portNo Port number.
61     */
62    void initClient(const QString& address, int portNo);
63
64    /**
65     * Check whether this program is a server or not.
66     *
67     * @return True if this program is a server, false if it is a client.
68     */
69    bool isServer() const { return m_bServer; }
70
71    /**
72     * Retrieve host name of the PC working on.
73     *
74     * @return Host name of the PC working on.
75     */
76    QString getHostName() const { return m_hostName; }
77
78    /**
79     * Retrieve server address to connect.
80     *
81     * @param Server address to connect.
82     */
83    QString getServerAddress() const { return m_serverAddress; }
84
85    /**
86     * Retrieve port number to connect.
87     *
88     * @param Port number to connect.
89     */
90    int getPortNo() const { return m_portNo; }
91
92    /**
93     * Send a sync command to clients.
94     *
95     * @param command Synchronize command.
96     * @param command Synchronize data.
97     */
98    void sendChanges(RSYNC_COMMAND command, const QString& data);
99
100    /**
101     * Send a reload command to clients.
102     */
103    void sendReloadSettings();
104
105    /**
106     * Set sync message blocking.
107     *
108     * @param bBlock True to block sending sync data to clients.
109     */
110    void setBlockSync(bool bBlock);
111
112    /**
113     * Check whether sync message is blocked or not.
114     *
115     * @param bBlock True to block sending sync data to clients.
116     */
117    bool getBlockSync() const;
118
119protected slots:
120
121    /**
122     * Connect to a server.
123     */
124    void connectToServer();
125
126    /**
127     * Called when a new client connects to the server. Send all states to synchronize.
128     */
129    void acceptNewClient();
130
131    /**
132     * Called when a new synchronize message is received.
133     */
134    void recvSettings();
135
136    /**
137     * Called when a network error is occured.
138     */
139    void displayNetworkError(QAbstractSocket::SocketError socketError);
140
141protected:
142
143    bool m_bServer;             //!< True if this program is a server, false if it is a client.
144    QString m_hostName;         //!< Host name of the PC working on.
145    QString m_serverAddress;    //!< Server address to connect.
146    int m_portNo;               //!< Port number to connect.
147
148    QTcpServer* m_pTcpServer;                   //!< Server object.
149    QTcpSocket* m_pTcpClient;                   //!< Client object.
150    QList<QTcpSocket*> m_pClientConnections;    //!< Connection objects.
151    QString m_lastErrorString;                  //!< Last network error string.
152
153    bool m_bBlockSync;          //!< True to block sending sync data to clients.
154
155    ProjectionModel* m_pModel;  //!< Projection model.
156};
157
158}; // projection
159
160#endif // _RSYNC_H_
Note: See TracBrowser for help on using the repository browser.