/* */ #ifndef _D_PIECE_H_ #define _D_PIECE_H_ #include "common.h" #include "SharedHandle.h" #include #include #include namespace aria2 { class BitfieldMan; class Piece { private: int32_t index; int32_t length; int32_t _blockLength; BitfieldMan* bitfield; public: static const int32_t BLOCK_LENGTH = 16*1024; Piece(); Piece(int32_t index, int32_t length, int32_t blockLength = BLOCK_LENGTH); Piece(const Piece& piece); ~Piece(); Piece& operator=(const Piece& piece); bool operator==(const Piece& piece) const; int32_t getMissingUnusedBlockIndex() const; int32_t getMissingBlockIndex() const; int32_t getFirstMissingBlockIndexWithoutLock() const; std::deque getAllMissingBlockIndexes() const; void completeBlock(int32_t blockIndex); void cancelBlock(int32_t blockIndex); int32_t countCompleteBlock() const; bool hasBlock(int32_t blockIndex) const; /** * Returns true if all blocks of this piece have been downloaded, otherwise * returns false. */ bool pieceComplete() const; int32_t countBlock() const; int32_t getBlockLength(int32_t index) const; int32_t getBlockLength() const; int32_t getIndex() const { return index; } void setIndex(int32_t index) { this->index = index; } int32_t getLength() const { return length; } void setLength(int32_t index) { this->length = length; } const unsigned char* getBitfield() const; void setBitfield(const unsigned char* bitfield, int32_t len); int32_t getBitfieldLength() const; void clearAllBlock(); void setAllBlock(); std::string toString() const; bool isBlockUsed(int32_t index) const; // Calculates completed length int32_t getCompletedLength(); /** * Loses current bitfield state. */ void reconfigure(int32_t length); }; typedef SharedHandle PieceHandle; typedef std::deque Pieces; } // namespace aria2 #endif // _D_PIECE_H_