www.pudn.com > myseelite_2007_06_28.zip > SPClient.h


/* 
*  Openmysee 
* 
*  This program is free software; you can redistribute it and/or modify 
*  it under the terms of the GNU General Public License as published by 
*  the Free Software Foundation; either version 2 of the License, or 
*  (at your option) any later version. 
* 
*  This program is distributed in the hope that it will be useful, 
*  but WITHOUT ANY WARRANTY; without even the implied warranty of 
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
*  GNU General Public License for more details. 
* 
*  You should have received a copy of the GNU General Public License 
*  along with this program; if not, write to the Free Software 
*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
* 
*/ 
#ifndef __SPCLIENT_H_ 
#define __SPCLIENT_H_ 
 
#include "FreeList.h" 
#include "TransferCalculator.h" 
 
#define P2P_BUF_SIZE BLOCK_SIZE+1024 
 
#define WM_NOMORESAMPLE WM_APP+12341 
 
// TCP传输的数据包 
class TCPPacket { 
public: 
	TCPPacket() : size(0), sent(0) {}; 
	~TCPPacket() {}; 
	char GetMsgType() {return buf[4];}; 
	UINT* GetBlockID() {return reinterpret_cast(buf+5);}; 
	UINT* GetBlockSize() {return reinterpret_cast(buf+9);}; 
	void Init() {}; 
	void Uninit() {}; 
	char buf[P2P_BUF_SIZE]; 
	// 要发送的消息大小 
	int size; 
	// 已经发送的大小 
	int sent; 
}; 
 
enum MSG_STATE { 
	MSG_COMPLETE, MSG_UNCOMPLETE, MSG_ERR_SIZE, MSG_ERR_TYPE, MSG_REMOTE_ERR, 
}; 
 
enum CONNECT_RESULT {CR_ERROR, CR_CONNECTED, CR_WOULDBLOCK}; 
 
class BufferMgr; 
class LogMgr; 
class CaptureServer; 
class SPClient : public TransferCalculator { 
public: 
	SPClient(CaptureServer* cServer, NormalAddress address, BufferMgr* bufferMgr, LogMgr* log); 
	~SPClient(); 
 
private: 
	BOOL BaseRecv(); 
	MSG_STATE ParseMsg(); 
	MSG_STATE OnWelcome(); 
	MSG_STATE OnMsg(); 
	 
	BOOL SendRegister(); 
	BOOL SendBlock(); 
	BOOL SendUpdate(); 
    BOOL SendMediaType(); 
	BOOL SendPackets(); 
 
	static void __stdcall RunReceiver(SPClient* client); 
	CONNECT_RESULT Connecting(); 
	void Disconnect(); 
 
private: 
	SOCKET m_socket; 
	// 接收数据的缓冲区 
	char recvBuf[P2P_BUF_SIZE]; 
	// 缓冲区中数据的长度 
	UINT recvOff; 
	// 从接收到的数据包读取数据的移动指针 
	char* recvPointer; 
	// 向被发送的数据包写入数据的移动指针 
	char* sendPointer; 
	// 出错信息 
	char errStr[30]; 
 
	// 即将被发送的Packet列表 
	list m_sendList; 
	// TCPPacket动态分配/释放的列表 
	FreeList m_freeList;	 
 
	// 每次编制发送消息时,第一步的操作 
	BOOL SendBegin(TCPPacket*& packet, UINT8 msgType); 
	// 每次编制发送消息时,最后一步的操作 
	void SendEnd(TCPPacket*& packet); 
 
	CaptureServer *cs;    //Capture Server 
	BufferMgr* m_bufferMgr; 
	LogMgr* logFile; 
	NormalAddress addr; 
	UINT	lastSentBlockID; // store the block should send now 
	BOOL    isRunning; 
	BOOL    isLogin; 
	HANDLE  hThread; 
 
 
	// 校验块的正确与否 
	SampleHeader header; 
	int readData; 
 
	// 利用memcpy复制数据,并且把src指针加上size 
	static void CopyMoveSrc(void * des, const char *& src, size_t size); 
	// 利用memcpy复制数据,并且把des指针加上size 
	static void CopyMoveDes(char *& des, const void * src, size_t size); 
}; 
#endif