/* */ #ifndef _D_SHARE_RATIO_SEED_CRITERIA_H_ #define _D_SHARE_RATIO_SEED_CRITERIA_H_ #include "SeedCriteria.h" #include "DownloadContext.h" #include "PeerStorage.h" #include "PieceStorage.h" namespace aria2 { class ShareRatioSeedCriteria : public SeedCriteria { private: double ratio; SharedHandle _downloadContext; SharedHandle _peerStorage; SharedHandle _pieceStorage; public: ShareRatioSeedCriteria (double ratio, const SharedHandle& downloadContext) :ratio(ratio), _downloadContext(downloadContext) {} virtual ~ShareRatioSeedCriteria() {} virtual void reset() {} virtual bool evaluate() { if(_downloadContext->getTotalLength() == 0) { return false; } TransferStat stat = _peerStorage->calculateStat(); return ratio <= (double)stat.getAllTimeUploadLength()/ _pieceStorage->getCompletedLength(); } void setRatio(double ratio) { this->ratio = ratio; } double getRatio() const { return ratio; } void setPeerStorage(const SharedHandle& peerStorage) { _peerStorage = peerStorage; } void setPieceStorage(const SharedHandle& pieceStorage) { _pieceStorage = pieceStorage; } }; } // namespace aria2 #endif // _D_SHARE_RATIO_SEED_CRITERIA_H_