00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef GXMLDIRECTNETWORKH
00026 #define GXMLDIRECTNETWORKH
00027
00028 #include "GXmlNetwork.h"
00029 #include "GNetworkMessageQueue.h"
00030
00031 #include <QTcpServer>
00032 #include <QTcpSocket>
00033
00034 #include <QMap>
00035 #include <QMutex>
00036
00037 namespace GWE
00038 {
00039
00040
00047 class GXmlDirectNetworkConnection
00048 {
00049 protected:
00053 QTcpSocket* Socket;
00054
00064 QString ConnectionName;
00065
00066 public:
00067
00072 GXmlDirectNetworkConnection(QTcpSocket* socket, const QString& id = QString());
00073
00077 virtual ~GXmlDirectNetworkConnection();
00078
00082 void setConnectionName(const QString& id);
00083
00087 QString getConnectionName() const;
00088
00092 QTcpSocket* getSocket();
00093 };
00094
00095
00135 class GXmlDirectNetwork : public GXmlNetwork
00136 {
00137 Q_OBJECT
00138
00139 protected:
00140
00144 QString NetworkID;
00145
00162 QString MasterServer;
00163
00168 QTcpServer Server;
00169
00173 QMap<QString,GXmlDirectNetworkConnection*> Connections;
00174
00180 QMap<const QTcpSocket*,GXmlDirectNetworkConnection*> IncomingConnections;
00181
00187 QMap<const QTcpSocket*,QString> SocketNameMapping;
00188
00193 GNetworkMessageQueue MessageQueue;
00194
00199 int Port;
00200
00205 QMutex ReceiveMutex;
00206
00207 public:
00215 GXmlDirectNetwork(QString networkid, QString master, int port = 7471, QObject* parent = NULL);
00216
00220 virtual ~GXmlDirectNetwork();
00221
00222 protected:
00223
00228 void removeConnection(const QString& destination);
00229
00234 void connectSocketSignals(QTcpSocket* socket);
00235
00245 QByteArray readSection(QIODevice* datasource, const QByteArray& begin, const QByteArray& ending);
00246
00247 protected slots:
00248
00252 void socketError(QAbstractSocket::SocketError socketError);
00253
00258 void socketDisconnected();
00259
00266 void processPendingClientConnection();
00267
00273 void receiveData();
00274
00279 void sendQueuedMessages(QString destination);
00280
00286 void socketConnected();
00287
00288 public:
00289
00290
00291
00295 bool isConnected();
00296
00300 QString getNetworkId() const;
00301
00305 QString getMasterServer() const;
00306
00307 public slots:
00308
00312 void setNetworkId(const QString& id);
00313
00317 void setMasterServer(const QString& master);
00318
00322 bool initNetwork();
00323
00330 bool closeNetwork();
00331
00335 void setPassword(const QString& password);
00336
00337
00338
00353 bool send(QDomElement data, const QString& destination);
00354
00359 bool send(const QString& data);
00360
00364 bool flushOutput();
00365
00369 void makeDestinationAvailable(const QString& destination);
00370
00374 bool isDestinationAvailable(const QString& destination);
00375
00376
00377 };
00378
00379 }
00380
00381 #endif