DownloaderFeedback.h
资源名称:GGBT.rar [点击查看]
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:6k
源码类别:
P2P编程
开发平台:
Visual C++
- // DownloaderFeedback.h: interface for the CDownloaderFeedback class.
- //
- //////////////////////////////////////////////////////////////////////
- #if !defined(AFX_DOWNLOADERFEEDBACK_H__80149D16_CB00_4E69_8B28_ED7F94457FC3__INCLUDED_)
- #define AFX_DOWNLOADERFEEDBACK_H__80149D16_CB00_4E69_8B28_ED7F94457FC3__INCLUDED_
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- #include "Connection.h"
- class CConnector;
- class CDownload;
- class CConncetionData
- {
- public:
- CConncetionData()
- {
- m_lAddr = 0;
- m_sPort = 0;
- m_bLocallyInitiated = 0;
- m_lUpRate = 0;
- m_lDownRate = 0;
- m_lDownCount = 0;
- m_lUpCount = 0;
- m_bInterested = 0;
- m_bInteresting = 0;
- m_bChoked = 0;
- m_bChoking = 0;
- m_fPeerHavePercent = 0;
- m_bPaused = 0;
- m_lIndex = 0;
- memset(m_lValueUp, 0, CConnection::eCount*sizeof(long));
- memset(m_lValueDown, 0, CConnection::eCount*sizeof(long));
- }
- bool operator != (const CConncetionData& other) const
- {
- return !(*this == other);
- }
- bool operator == (const CConncetionData& other) const
- {
- if (
- m_lAddr != other.m_lAddr ||
- m_sPort != other.m_sPort ||
- m_bLocallyInitiated != other.m_bLocallyInitiated ||
- m_lUpRate != other.m_lUpRate ||
- m_lDownRate != other.m_lDownRate ||
- m_lDownCount != other.m_lDownCount ||
- m_lUpCount != other.m_lUpCount ||
- m_bInterested != other.m_bInterested ||
- m_bInteresting != other.m_bInteresting ||
- m_bChoked != other.m_bChoked ||
- m_bChoking != other.m_bChoking ||
- m_fPeerHavePercent != other.m_fPeerHavePercent ||
- m_bPaused != other.m_bPaused
- )
- {
- return false;
- }
- return true;
- }
- /*
- CConncetionData(CConncetionData* pData)
- {
- *this = pData;
- }
- CConncetionData& operator = (CConncetionData* pData)
- {
- assert(pData);
- m_lAddr = pData->m_lAddr;
- m_sPort = pData->m_sPort;
- m_bLocallyInitiated = pData->m_bLocallyInitiated;
- m_lUpRate = pData->m_lUpRate ;
- m_lDownRate = pData->m_lDownRate ;
- m_lDownCount = pData->m_lDownCount ;
- m_lUpCount = pData->m_lUpCount ;
- m_bInterested = pData->m_bInterested ;
- m_bInteresting = pData->m_bInteresting ;
- m_bChoked = pData->m_bChoked ;
- m_bChoking = pData->m_bChoking ;
- m_fPeerHavePercent = pData->m_fPeerHavePercent ;
- m_bPaused = pData->m_bPaused;
- return *this;
- }
- //*/
- long m_lAddr;
- short m_sPort;
- bool m_bLocallyInitiated;
- long m_lUpRate;
- long m_lDownRate;
- long m_lDownCount;
- long m_lUpCount;
- bool m_bInterested;
- bool m_bInteresting;
- bool m_bChoked;
- bool m_bChoking;
- float m_fPeerHavePercent;
- bool m_bPaused;
- string m_strPeerId;
- long m_lValueUp[CConnection::eCount];
- long m_lValueDown[CConnection::eCount];
- long m_lIndex;
- vector<bool> m_vHave;
- // 对方是否优先传送。
- // 该站点总下载速度。
- };
- class CStatics
- {
- public:
- CStatics()
- {
- m_fCompletedPart = 0;
- m_fCompleted = 0;
- m_lSeedsCount = 0;
- m_lDownRate = 0;
- m_lUpRate = 0;
- m_tTimeLeft= 0;
- m_lPeersCount = 0;
- m_tTimeRunned = 0;
- m_fCheckingPercent = 0;
- m_bStorageChecking = true;
- m_fAllocatingPercent = 0;
- m_bAllocating = false;
- m_bTrackerConnected = false;
- m_bFired = false;
- m_bCheckingDone = false;
- }
- float m_fCompletedPart;
- float m_fCompleted;
- long m_lPeersCount;
- long m_lSeedsCount;
- long m_lDownRate;
- long m_lUpRate;
- time_t m_tTimeLeft;
- time_t m_tTimeRunned;
- float m_fCheckingPercent;
- bool m_bStorageChecking;
- bool m_bCheckingDone;
- float m_fAllocatingPercent;
- bool m_bAllocating;
- bool m_bTrackerConnected;
- bool m_bFired;
- };
- class CSystemMsg
- {
- public:
- enum eMSG_TYPE{eMsgOut, eMsgIn, eCmd, eBad} m_eMsgType;
- CSystemMsg(time_t t, string strMsg, eMSG_TYPE eMsgType)
- {
- m_time = t;
- m_strMsg = strMsg;
- m_eMsgType = eMsgType;
- }
- time_t m_time;
- string m_strMsg;
- };
- #define DOWNLOAD_TERMINATED (WM_USER+1012)
- #define STORAGE_CHECK_COMPLETE (WM_USER+1013)
- class CDownloaderFeedback
- {
- public:
- CDownloaderFeedback();
- virtual ~CDownloaderFeedback();
- void SetCompleteKeepSeedHour(long lCompleteKeepSeedHour);
- void SetDownload(CDownload* pDownload, HTREEITEM curItem, HWND hFeedbackwnd, time_t tKeepSeedTime, long lParam);
- void Create(CConnector* pConnector, long lPutDataTimeSpan);
- void Completed();
- void data_flunked(long lAmount);
- void PartCompleted();
- void PutRunParameter(long lPort);
- void GetRunParameter(long& lPort);
- bool IsStorageChecking();
- void TrackerConnected();
- void SetStorageAllocating(bool bAllocating, float fAllocatingPercent = 0);
- void SetStorageChecking(bool bStorageChecking, float fCheckingPercent = 0);
- void SetCheckingDone(float fCompleted, float fPartCompletedPercent);
- void PutDataTime();
- vector<CConncetionData>& GetData();
- CStatics& GetStatics();
- void ClearSystemMessage();
- void ShowSystemMessage(string strMsg, CSystemMsg::eMSG_TYPE eMsgType);
- void GetSystemMessage(vector<CSystemMsg>& vMsg);
- void ShowSocketMessage(long lAddr, short sPort, string strMsg);
- string GetSocketMessage(long lAddr, short sPort);
- string GetSocketMessageAll();
- void ShowEncryptedMessage(string strMsg);
- void errorFunc(string e);
- string GetBadMsg();
- bool IsBad();
- void GetFractions(vector<long>& vFractions);
- void PutFractionsState(long lFractionInx, long lState);
- void PutFractions(const vector<bool>& vHaves);
- void QuitDownload();
- void StorageCheckComplete();
- void SetBadMsg(string strBad, bool bSendMessage = true);
- private:
- void SetCompleteMsg(string strMsg);
- void PutStatics();
- void PutData();
- CDownload* m_pDownload;
- clock_t m_lPutDataTimeSpan;
- clock_t m_lLast;
- time_t m_tStart;
- time_t m_tCompleted;
- time_t m_tKeepSeedTimeHour;
- // bool m_bCompleteKeepSeed;
- CConnector* m_pConnector;
- vector<CConncetionData> m_vConnectionDatas;
- map<CAddrPort, vector<string> > m_mapMsg;
- vector<CSystemMsg> m_vSystemMsg;
- CStatics m_statics;
- long m_lSystemMsgMaxCount;
- long m_lPort;
- bool m_bBad;
- string m_strBad;
- vector<long> m_vFractions;
- long m_lParam;
- HTREEITEM m_curItem;
- HWND m_hFeedbackwnd;
- CCriticalSection m_criticalSection;
- };
- #endif // !defined(AFX_DOWNLOADERFEEDBACK_H__80149D16_CB00_4E69_8B28_ED7F94457FC3__INCLUDED_)