/* */ #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" #include "LpdMessageReceiver.h" #include "NullHandle.h" namespace aria2 { BtRegistry::BtRegistry() : tcpPort_(0) {} BtRegistry::~BtRegistry() {} const SharedHandle& BtRegistry::getDownloadContext(a2_gid_t gid) const { const SharedHandle& res = get(gid); if(res) { return res->downloadContext; } else { return getNull(); } } const SharedHandle& BtRegistry::getDownloadContext(const std::string& infoHash) const { for(std::map >::const_iterator i = pool_.begin(), eoi = pool_.end(); i != eoi; ++i) { if(bittorrent::getTorrentAttrs((*i).second->downloadContext)->infoHash == infoHash) { return (*i).second->downloadContext; } } return getNull(); } void BtRegistry::put(a2_gid_t gid, const SharedHandle& obj) { pool_[gid] = obj; } const SharedHandle& BtRegistry::get(a2_gid_t gid) const { std::map >::const_iterator i = pool_.find(gid); if(i == pool_.end()) { return getNull(); } else { return (*i).second; } } bool BtRegistry::remove(a2_gid_t gid) { return pool_.erase(gid); } void BtRegistry::removeAll() { pool_.clear(); } void BtRegistry::setLpdMessageReceiver (const SharedHandle& receiver) { lpdMessageReceiver_ = receiver; } 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; } } // namespace aria2