/* */ #ifndef _D_PIECE_STORAGE_H_ #define _D_PIECE_STORAGE_H_ #include "common.h" #include "SharedHandle.h" #include "TimeA2.h" #include "IntSequence.h" #include #include namespace aria2 { class Piece; class Peer; class DiskAdaptor; class PieceStorage { public: virtual ~PieceStorage() {} /** * Returns true if the peer has a piece that localhost doesn't have. * Otherwise returns false. */ virtual bool hasMissingPiece(const SharedHandle& peer) = 0; /** * Returns a piece that the peer has but localhost doesn't. * The piece will be marked "used" status in order to prevent other command * from get the same piece. But in end game mode, same piece may be returned * to several commands. */ virtual SharedHandle getMissingPiece(const SharedHandle& peer) = 0; /** * Same as getMissingPiece(const SharedHandle& peer), but the indexes in * excludedIndexes are excluded. */ virtual SharedHandle getMissingPiece (const SharedHandle& peer, const std::deque& excludedIndexes) = 0; /** * Returns a piece that the peer has but localhost doesn't. * Only pieces that declared as "fast" are returned. * The piece will be marked "used" status in order to prevent other command * from get the same piece. But in end game mode, same piece may be returned * to several commands. */ virtual SharedHandle getMissingFastPiece(const SharedHandle& peer) = 0; /** * Same as getMissingFastPiece(const SharedHandle& peer), but the * indexes in excludedIndexes are excluded. */ virtual SharedHandle getMissingFastPiece (const SharedHandle& peer, const std::deque& excludedIndexes) = 0; /** * Returns a missing piece if available. Otherwise returns 0; */ virtual SharedHandle getMissingPiece() = 0; /** * 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) = 0; /** * Returns the piece denoted by index. * No status of the piece is changed in this method. */ virtual SharedHandle getPiece(size_t index) = 0; /** * Marks the piece whose index is index as missing. */ virtual void markPieceMissing(size_t index) = 0; /** * Tells that the download of the specfied piece completes. */ virtual void completePiece(const SharedHandle& piece) = 0; /** * Tells that the download of the specified piece is canceled. */ virtual void cancelPiece(const SharedHandle& piece) = 0; /** * Returns true if the specified piece is already downloaded. * Otherwise returns false. */ virtual bool hasPiece(size_t index) = 0; virtual bool isPieceUsed(size_t index) = 0; virtual uint64_t getTotalLength() = 0; virtual uint64_t getFilteredTotalLength() = 0; virtual uint64_t getCompletedLength() = 0; virtual uint64_t getFilteredCompletedLength() = 0; virtual void setFileFilter(const std::deque& filePaths) = 0; virtual void setFileFilter(IntSequence seq) = 0; virtual void clearFileFilter() = 0; /** * Returns true if download has completed. * If file filter is enabled, then returns true if those files have * downloaded. */ virtual bool downloadFinished() = 0; /** * Returns true if all files have downloaded. * The file filter is ignored. */ virtual bool allDownloadFinished() = 0; /** * Initializes DiskAdaptor. * TODO add better documentation here. */ virtual void initStorage() = 0; virtual const unsigned char* getBitfield() = 0; virtual void setBitfield(const unsigned char* bitfield, size_t bitfieldLength) = 0; virtual size_t getBitfieldLength() = 0; virtual bool isSelectiveDownloadingMode() = 0; virtual void finishSelectiveDownloadingMode() = 0; virtual bool isEndGame() = 0; virtual SharedHandle getDiskAdaptor() = 0; virtual size_t getPieceLength(size_t index) = 0; /** * Adds piece index to advertise to other commands. They send have message * based on this information. */ virtual void advertisePiece(int32_t cuid, size_t index) = 0; /** * indexes is filled with piece index which is not advertised by the caller * command and newer than lastCheckTime. */ virtual void getAdvertisedPieceIndexes(std::deque& indexes, int32_t myCuid, const Time& lastCheckTime) = 0; /** * Removes have entry if specified seconds have elapsed since its * registration. */ virtual void removeAdvertisedPiece(time_t elapsed) = 0; /** * Sets all bits in bitfield to 1. */ virtual void markAllPiecesDone() = 0; /** * Sets all bits in bitfield(0 to length) to 1. */ virtual void markPiecesDone(uint64_t length) = 0; virtual void addInFlightPiece(const std::deque >& pieces) = 0; virtual size_t countInFlightPiece() = 0; virtual void getInFlightPieces(std::deque >& pieces) = 0; virtual void addPieceStats(size_t index) = 0; virtual void addPieceStats(const unsigned char* bitfield, size_t bitfieldLength) = 0; virtual void subtractPieceStats(const unsigned char* bitfield, size_t bitfieldLength) = 0; virtual void updatePieceStats(const unsigned char* newBitfield, size_t newBitfieldLength, const unsigned char* oldBitfield) = 0; }; typedef SharedHandle PieceStorageHandle; } // namespace aria2 #endif // _D_PIECE_STORAGE_H_