/* */ #include "BtRegistry.h" #include "DlAbortEx.h" #include "DownloadContext.h" #include "PeerStorage.h" #include "PieceStorage.h" #include "BtAnnounce.h" #include "BtRuntime.h" #include "BtProgressInfoFile.h" #include "bittorrent_helper.h" namespace aria2 { SharedHandle BtRegistry::getDownloadContext(gid_t gid) const { return get(gid).downloadContext_; } SharedHandle BtRegistry::getDownloadContext(const std::string& infoHash) const { SharedHandle dctx; for(std::map::const_iterator i = pool_.begin(), eoi = pool_.end(); i != eoi; ++i) { if(bittorrent::getTorrentAttrs((*i).second.downloadContext_)->infoHash == infoHash) { dctx = (*i).second.downloadContext_; break; } } return dctx; } void BtRegistry::put(gid_t gid, const BtObject& obj) { pool_[gid] = obj; } BtObject BtRegistry::get(gid_t gid) const { std::map::const_iterator i = pool_.find(gid); if(i == pool_.end()) { return BtObject(); } else { return (*i).second; } } bool BtRegistry::remove(gid_t gid) { return pool_.erase(gid); } void BtRegistry::removeAll() { pool_.clear(); } BtObject::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::BtObject() {} BtObject::BtObject(const BtObject& c) : downloadContext_(c.downloadContext_), pieceStorage_(c.pieceStorage_), peerStorage_(c.peerStorage_), btAnnounce_(c.btAnnounce_), btRuntime_(c.btRuntime_), btProgressInfoFile_(c.btProgressInfoFile_) {} BtObject::~BtObject() {} BtObject& BtObject::operator=(const BtObject& c) { if(this != &c) { downloadContext_ = c.downloadContext_; pieceStorage_ = c.pieceStorage_; peerStorage_ = c.peerStorage_; btAnnounce_ = c.btAnnounce_; btRuntime_ = c.btRuntime_; btProgressInfoFile_ = c.btProgressInfoFile_; } return *this; } bool BtObject::isNull() const { return !downloadContext_ && !pieceStorage_ && !peerStorage_ && !btAnnounce_ && !btRuntime_ && !btProgressInfoFile_; } } // namespace aria2