/* */ #ifndef D_UNKNOWN_LENGTH_PIECE_STORAGE_H #define D_UNKNOWN_LENGTH_PIECE_STORAGE_H #include "PieceStorage.h" namespace aria2 { class Option; class DownloadContext; class DiskWriterFactory; class DirectDiskAdaptor; class UnknownLengthPieceStorage:public PieceStorage { private: SharedHandle downloadContext_; const Option* option_; SharedHandle diskAdaptor_; SharedHandle diskWriterFactory_; off_t totalLength_; bool downloadFinished_; SharedHandle piece_; public: UnknownLengthPieceStorage(const SharedHandle& downloadContext, const Option* option); virtual ~UnknownLengthPieceStorage(); #ifdef ENABLE_BITTORRENT /** * Returns true if the peer has a piece that localhost doesn't have. * Otherwise returns false. */ virtual bool hasMissingPiece(const SharedHandle& peer); virtual void getMissingPiece (std::vector >& pieces, size_t minMissingBlocks, const SharedHandle& peer, cuid_t cuid); virtual void getMissingPiece (std::vector >& pieces, size_t minMissingBlocks, const SharedHandle& peer, const std::vector& excludedIndexes, cuid_t cuid); virtual void getMissingFastPiece (std::vector >& pieces, size_t minMissingBlocks, const SharedHandle& peer, cuid_t cuid); virtual void getMissingFastPiece (std::vector >& pieces, size_t minMissingBlocks, const SharedHandle& peer, const std::vector& excludedIndexes, cuid_t cuid); virtual SharedHandle getMissingPiece (const SharedHandle& peer, cuid_t cuid); virtual SharedHandle getMissingPiece (const SharedHandle& peer, const std::vector& excludedIndexes, cuid_t cuid); #endif // ENABLE_BITTORRENT virtual bool hasMissingUnusedPiece(); /** * Returns a missing piece if available. Otherwise returns 0; */ virtual SharedHandle getMissingPiece (size_t minSplitSize, const unsigned char* ignoreBitfield, size_t length, cuid_t cuid); /** * Returns a missing piece whose index is index. * If a piece whose index is index is already acquired or currently used, * then returns 0. * Also returns 0 if any of missing piece is not available. */ virtual SharedHandle getMissingPiece(size_t index, cuid_t cuid); /** * Returns the piece denoted by index. * No status of the piece is changed in this method. */ virtual SharedHandle getPiece(size_t index); /** * Tells that the download of the specfied piece completes. */ virtual void completePiece(const SharedHandle& piece); /** * Tells that the download of the specified piece is canceled. */ virtual void cancelPiece(const SharedHandle& piece, cuid_t cuid); /** * Returns true if the specified piece is already downloaded. * Otherwise returns false. */ virtual bool hasPiece(size_t index); virtual bool isPieceUsed(size_t index); virtual off_t getTotalLength() { return totalLength_; } virtual off_t getFilteredTotalLength() { return totalLength_; } virtual off_t getCompletedLength() { // TODO we have to return actual completed length here? return totalLength_; } virtual off_t getFilteredCompletedLength() { return getCompletedLength(); } virtual void setupFileFilter() {} virtual void clearFileFilter() {} /** * Returns true if download has completed. * If file filter is enabled, then returns true if those files have * downloaded. */ virtual bool downloadFinished() { return downloadFinished_; } /** * Returns true if all files have downloaded. * The file filter is ignored. */ virtual bool allDownloadFinished() { return downloadFinished(); } /** * Initializes DiskAdaptor. * TODO add better documentation here. */ virtual void initStorage(); virtual const unsigned char* getBitfield() { return 0; } virtual void setBitfield(const unsigned char* bitfield, size_t bitfieldLength) {} virtual size_t getBitfieldLength() { return 0; } virtual bool isSelectiveDownloadingMode() { return false; } virtual bool isEndGame() { return false; } virtual void enterEndGame() {} virtual void setEndGamePieceNum(size_t num) {} virtual SharedHandle getDiskAdaptor(); virtual int32_t getPieceLength(size_t index); /** * Adds piece index to advertise to other commands. They send have message * based on this information. */ virtual void advertisePiece(cuid_t cuid, size_t index) {} /** * Returns piece index which is not advertised by the caller command and * newer than lastCheckTime. */ virtual void getAdvertisedPieceIndexes(std::vector& indexes, cuid_t myCuid, const Timer& lastCheckTime) {} /** * Removes have entry if specified seconds have elapsed since its * registration. */ virtual void removeAdvertisedPiece(time_t elapsed) {} /** * Sets all bits in bitfield to 1. */ virtual void markAllPiecesDone(); virtual void markPiecesDone(off_t length); virtual void markPieceMissing(size_t index); /** * Do nothing because loading in-flight piece is not supported for this * class. */ virtual void addInFlightPiece (const std::vector >& pieces) {} virtual size_t countInFlightPiece() { return 0; } virtual void getInFlightPieces(std::vector >& pieces); virtual void addPieceStats(size_t index) {} virtual void addPieceStats(const unsigned char* bitfield, size_t bitfieldLength) {} virtual void subtractPieceStats(const unsigned char* bitfield, size_t bitfieldLength) {} virtual void updatePieceStats(const unsigned char* newBitfield, size_t newBitfieldLength, const unsigned char* oldBitfield) {} virtual size_t getNextUsedIndex(size_t index) { return 0; } void setDiskWriterFactory(const SharedHandle& diskWriterFactory); virtual void onDownloadIncomplete() {} }; typedef SharedHandle UnknownLengthPieceStorageHandle; } // namespace aria2 #endif // D_UNKNOWN_LENGTH_PIECE_STORAGE_H