/* */ #ifndef _D_BT_REGISTRY_H_ #define _D_BT_REGISTRY_H_ #include "common.h" #include #include "SharedHandle.h" #include "RequestGroup.h" namespace aria2 { class PeerStorage; class PieceStorage; class BtAnnounce; class BtRuntime; class BtProgressInfoFile; class DownloadContext; struct BtObject { SharedHandle downloadContext_; SharedHandle pieceStorage_; SharedHandle peerStorage_; SharedHandle btAnnounce_; SharedHandle btRuntime_; SharedHandle btProgressInfoFile_; BtObject(const SharedHandle& downloadContext, const SharedHandle& pieceStorage, const SharedHandle& peerStorage, const SharedHandle& btAnnounce, const SharedHandle& btRuntime, const SharedHandle& btProgressInfoFile): downloadContext_(downloadContext), pieceStorage_(pieceStorage), peerStorage_(peerStorage), btAnnounce_(btAnnounce), btRuntime_(btRuntime), btProgressInfoFile_(btProgressInfoFile) {} BtObject() {} bool isNull() const { return downloadContext_.isNull() && pieceStorage_.isNull() && peerStorage_.isNull() && btAnnounce_.isNull() && btRuntime_.isNull() && btProgressInfoFile_.isNull(); } }; class BtRegistry { private: std::map pool_; public: SharedHandle getDownloadContext(gid_t gid) const; SharedHandle getDownloadContext(const std::string& infoHash) const; void put(gid_t gid, const BtObject& obj); BtObject get(gid_t gid) const; template OutputIterator getAllDownloadContext(OutputIterator dest) { for(std::map::const_iterator i = pool_.begin(), eoi = pool_.end(); i != eoi; ++i) { *dest++ = (*i).second.downloadContext_; } return dest; } void removeAll(); bool remove(gid_t gid); }; } // namespace aria2 #endif // _D_BT_REGISTRY_H_