/* */ #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_