/* */ #ifndef _D_MULTI_DISK_ADAPTOR_H_ #define _D_MULTI_DISK_ADAPTOR_H_ #include "DiskAdaptor.h" namespace aria2 { class MultiFileAllocationIterator; class FileEntry; class DiskWriter; class DiskWriterEntry { private: SharedHandle fileEntry; SharedHandle diskWriter; public: DiskWriterEntry(const SharedHandle& fileEntry); ~DiskWriterEntry(); std::string getFilePath(const std::string& topDir) const; void initAndOpenFile(const std::string& topDir); void openFile(const std::string& topDir); void openExistingFile(const std::string& topDir); void closeFile(); bool fileExists(const std::string& topDir); int64_t size() const; SharedHandle getFileEntry() const; void setDiskWriter(const SharedHandle& diskWriter); SharedHandle getDiskWriter() const; bool operator<(const DiskWriterEntry& entry) const; }; typedef SharedHandle DiskWriterEntryHandle; typedef std::deque DiskWriterEntries; class MultiDiskAdaptor : public DiskAdaptor { friend class MultiFileAllocationIterator; private: std::string topDir; int32_t pieceLength; DiskWriterEntries diskWriterEntries; bool _directIOAllowed; void resetDiskWriterEntries(); void mkdir() const; bool isInRange(const DiskWriterEntryHandle entry, int64_t offset) const; int32_t calculateLength(const DiskWriterEntryHandle entry, int64_t fileOffset, int32_t rem) const; std::string getTopDirPath() const; public: MultiDiskAdaptor(); virtual ~MultiDiskAdaptor(); virtual void initAndOpenFile(); virtual void openFile(); virtual void openExistingFile(); virtual void closeFile(); virtual void onDownloadComplete(); virtual void writeData(const unsigned char* data, int32_t len, int64_t offset); virtual int32_t readData(unsigned char* data, int32_t len, int64_t offset); virtual bool fileExists(); virtual std::string getFilePath() { return getTopDirPath(); } virtual int64_t size() const; virtual SharedHandle fileAllocationIterator(); virtual void enableDirectIO(); virtual void disableDirectIO(); void setTopDir(const std::string& topDir) { this->topDir = topDir; } const std::string& getTopDir() const { return topDir; } void setPieceLength(int32_t pieceLength) { this->pieceLength = pieceLength; } int32_t getPieceLength() const { return pieceLength; } virtual bool directIOAllowed() const { return _directIOAllowed; } void setDirectIOAllowed(bool b) { _directIOAllowed = b; } }; typedef SharedHandle MultiDiskAdaptorHandle; } // namespace aria2 #endif // _D_MULTI_DISK_ADAPTOR_H_