zp_clusternode.h 2.8 KB
Newer Older
丁劲犇's avatar
丁劲犇 已提交
1 2 3 4
#ifndef ZP_CLUSTERNODE_H
#define ZP_CLUSTERNODE_H

#include <QObject>
5 6
#include <QHostAddress>
#include <QDateTime>
丁劲犇's avatar
丁劲犇 已提交
7
#include "../pipeline/zp_pltaskbase.h"
8
#include "cross_svr_messages.h"
丁劲犇's avatar
丁劲犇 已提交
9
namespace ZP_Cluster{
10
	class zp_ClusterTerm;
丁劲犇's avatar
丁劲犇 已提交
11 12 13 14 15 16 17 18 19
	/**
	 * @brief This class stand for a remote server.
	 * when local server establish a connection between itself and remote svr,
	 * a zp_ClusterNode object will be created.
	 */
	class zp_ClusterNode : public ZPTaskEngine::zp_plTaskBase
	{
		Q_OBJECT
	public:
20
		explicit zp_ClusterNode(zp_ClusterTerm * pTerm, QObject * psock,QObject *parent = 0);
丁劲犇's avatar
丁劲犇 已提交
21
		int run();
22 23 24
		bool bTermSet;
		//push new binary data into queue
		int push_new_data(const  QByteArray &  dtarray);
25 26 27 28 29
		void CheckHeartBeating();

	protected:
		//!deal at most m_nMessageBlockSize messages per deal_message();
		static const int m_nMessageBlockSize = 8;
30 31 32 33 34
		//!deal one message, affect m_currentRedOffset,m_currentMessageSize,m_currentHeader
		//!return bytes Used.
		int filter_message(const QByteArray &, int offset);
		//!in Trans-Layer, it does nothing.
		int deal_current_message_block();
35 36
		//!virtual functions, dealing with the user-defined operations.
		virtual bool deal_user_data(const QByteArray &);
37

38
		QDateTime lastActiveTime();
39 40

	public:
41 42 43 44
		QString termName();
		QHostAddress addrPublish();
		int portPublish() ;
		QObject * sock() ;
45 46 47
		//!Messages
	public:
		void SendHelloPackage();
48 49 50 51 52 53 54 55
	protected:
		zp_ClusterTerm * m_pTerm;
		//Client socket handle of this connection
		QObject * m_pSock;
		//the data members.
		QString m_strTermName;		//the Terminal's name
		QHostAddress m_addrPublish;	//The publish address for other terms to connect to
		int m_nPortPublish;			//The publish port for other terms to connect to
丁劲犇's avatar
丁劲犇 已提交
56

57 58 59 60 61 62 63 64 65 66 67 68
		//Data Process
		//The raw data queue and its mutex
		QList<QByteArray> m_list_RawData;
		QMutex m_mutex_rawData;
		//The current Read Offset, from m_list_RawData's beginning
		int m_currentReadOffset;
		//Current Message Offset, according to m_currentHeader
		int m_currentMessageSize;
		//Current un-procssed message block.for large blocks,
		//this array will be re-setted as soon as some part of data has been
		//dealed, eg, send a 200MB block, the 200MB data will be splitted into pieces
		QByteArray m_currentBlock;
丁劲犇's avatar
丁劲犇 已提交
69

70 71 72 73 74 75 76
		CROSS_SVR_MSG::tag_header m_currentHeader;

		QDateTime m_last_Report;
	signals:
		void evt_SendDataToClient(QObject * objClient,const QByteArray &  dtarray);
		void evt_BroadcastData(QObject * objFromClient,const QByteArray &  dtarray);
		void evt_close_client(QObject * objClient);
77
		void evt_connect_to(const QHostAddress & address , quint16 nPort,bool bSSLConn);
78
		void evt_Message (QObject * psource,const QString &);
79 80 81 82 83

		//Notify Messages
		void evt_NewSvrConnected(const QString & /*svrHandle*/);
		//some data arrival
		void evt_RemoteData_recieved(const QString &  /*svrHandle*/,const QByteArray & /*svrHandle*/ );
丁劲犇's avatar
丁劲犇 已提交
84 85 86
	};
}
#endif // ZP_CLUSTERNODE_H