diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc index 347bce6a..23112f59 100644 --- a/src/DownloadEngine.cc +++ b/src/DownloadEngine.cc @@ -578,10 +578,9 @@ void DownloadEngine::addCommand(std::unique_ptr command) commands_.push_back(std::move(command)); } -void DownloadEngine::setRequestGroupMan -(const std::shared_ptr& rgman) +void DownloadEngine::setRequestGroupMan(std::unique_ptr rgman) { - requestGroupMan_ = rgman; + requestGroupMan_ = std::move(rgman); } void DownloadEngine::setFileAllocationMan diff --git a/src/DownloadEngine.h b/src/DownloadEngine.h index 29503fd7..6dbd341c 100644 --- a/src/DownloadEngine.h +++ b/src/DownloadEngine.h @@ -168,7 +168,7 @@ private: findSocketPoolEntry(const std::string& key); std::deque> commands_; - std::shared_ptr requestGroupMan_; + std::unique_ptr requestGroupMan_; std::unique_ptr fileAllocationMan_; std::unique_ptr checkIntegrityMan_; Option* option_; @@ -204,12 +204,12 @@ public: void addCommand(std::unique_ptr command); - const std::shared_ptr& getRequestGroupMan() const + const std::unique_ptr& getRequestGroupMan() const { return requestGroupMan_; } - void setRequestGroupMan(const std::shared_ptr& rgman); + void setRequestGroupMan(std::unique_ptr rgman); const std::unique_ptr& getFileAllocationMan() const { diff --git a/src/DownloadEngineFactory.cc b/src/DownloadEngineFactory.cc index 0227e061..49e9a4bf 100644 --- a/src/DownloadEngineFactory.cc +++ b/src/DownloadEngineFactory.cc @@ -148,11 +148,12 @@ DownloadEngineFactory::newDownloadEngine } std::shared_ptr e(new DownloadEngine(eventPoll)); e->setOption(op); - - auto requestGroupMan = std::make_shared - (std::move(requestGroups), MAX_CONCURRENT_DOWNLOADS, op); - requestGroupMan->initWrDiskCache(); - e->setRequestGroupMan(requestGroupMan); + { + auto requestGroupMan = make_unique + (std::move(requestGroups), MAX_CONCURRENT_DOWNLOADS, op); + requestGroupMan->initWrDiskCache(); + e->setRequestGroupMan(std::move(requestGroupMan)); + } e->setFileAllocationMan(make_unique()); #ifdef ENABLE_MESSAGE_DIGEST e->setCheckIntegrityMan(make_unique()); diff --git a/src/FillRequestGroupCommand.cc b/src/FillRequestGroupCommand.cc index 3aa12d0d..f40c8fe6 100644 --- a/src/FillRequestGroupCommand.cc +++ b/src/FillRequestGroupCommand.cc @@ -60,7 +60,7 @@ bool FillRequestGroupCommand::execute() if(e_->isHaltRequested()) { return true; } - const std::shared_ptr& rgman = e_->getRequestGroupMan(); + auto& rgman = e_->getRequestGroupMan(); if(rgman->queueCheckRequested()) { while(rgman->queueCheckRequested()) { try { diff --git a/src/MultiUrlRequestInfo.cc b/src/MultiUrlRequestInfo.cc index 8517b045..74ab10d5 100644 --- a/src/MultiUrlRequestInfo.cc +++ b/src/MultiUrlRequestInfo.cc @@ -288,7 +288,7 @@ error_code::Value MultiUrlRequestInfo::getResult() returnValue = s.getLastErrorResult(); } } - SessionSerializer sessionSerializer(e_->getRequestGroupMan()); + SessionSerializer sessionSerializer{e_->getRequestGroupMan().get()}; // TODO Add option: --save-session-status=error,inprogress,waiting if(!option_->blank(PREF_SAVE_SESSION)) { const std::string& filename = option_->get(PREF_SAVE_SESSION); diff --git a/src/RpcMethodImpl.cc b/src/RpcMethodImpl.cc index 43d8748d..dd189563 100644 --- a/src/RpcMethodImpl.cc +++ b/src/RpcMethodImpl.cc @@ -1351,7 +1351,7 @@ std::shared_ptr ForceShutdownRpcMethod::process std::shared_ptr GetGlobalStatRpcMethod::process (const RpcRequest& req, DownloadEngine* e) { - const std::shared_ptr& rgman = e->getRequestGroupMan(); + auto& rgman = e->getRequestGroupMan(); TransferStat ts = rgman->calculateStat(); std::shared_ptr res = Dict::g(); res->put(KEY_DOWNLOAD_SPEED, util::itos(ts.downloadSpeed)); diff --git a/src/SaveSessionCommand.cc b/src/SaveSessionCommand.cc index 2d990532..a09811e5 100644 --- a/src/SaveSessionCommand.cc +++ b/src/SaveSessionCommand.cc @@ -64,7 +64,7 @@ void SaveSessionCommand::process() ->get(PREF_SAVE_SESSION); if(!filename.empty()) { SessionSerializer sessionSerializer(getDownloadEngine()-> - getRequestGroupMan()); + getRequestGroupMan().get()); if(sessionSerializer.save(filename)) { A2_LOG_NOTICE(fmt(_("Serialized session to '%s' successfully."), filename.c_str())); diff --git a/src/SessionSerializer.cc b/src/SessionSerializer.cc index 17bdef65..0d78b945 100644 --- a/src/SessionSerializer.cc +++ b/src/SessionSerializer.cc @@ -60,11 +60,12 @@ namespace aria2 { SessionSerializer::SessionSerializer -(const std::shared_ptr& requestGroupMan): - rgman_(requestGroupMan), - saveError_(true), - saveInProgress_(true), - saveWaiting_(true) {} +(RequestGroupMan* requestGroupMan) + : rgman_{requestGroupMan}, + saveError_{true}, + saveInProgress_{true}, + saveWaiting_{true} +{} bool SessionSerializer::save(const std::string& filename) const { diff --git a/src/SessionSerializer.h b/src/SessionSerializer.h index a72aafdf..c3493edc 100644 --- a/src/SessionSerializer.h +++ b/src/SessionSerializer.h @@ -48,13 +48,13 @@ class IOFile; class SessionSerializer { private: - std::shared_ptr rgman_; + RequestGroupMan* rgman_; bool saveError_; bool saveInProgress_; bool saveWaiting_; bool save(IOFile& fp) const; public: - SessionSerializer(const std::shared_ptr& requestGroupMan); + SessionSerializer(RequestGroupMan* requestGroupMan); bool save(const std::string& filename) const; }; diff --git a/src/aria2api.cc b/src/aria2api.cc index 980e3c45..0443ebfb 100644 --- a/src/aria2api.cc +++ b/src/aria2api.cc @@ -525,7 +525,7 @@ GlobalStat getGlobalStat(Session* session) { const std::shared_ptr& e = session->context->reqinfo->getDownloadEngine(); - const std::shared_ptr& rgman = e->getRequestGroupMan(); + auto& rgman = e->getRequestGroupMan(); TransferStat ts = rgman->calculateStat(); GlobalStat res; res.downloadSpeed = ts.downloadSpeed; @@ -945,7 +945,7 @@ DownloadHandle* getDownloadHandle(Session* session, A2Gid gid) { const std::shared_ptr& e = session->context->reqinfo->getDownloadEngine(); - const std::shared_ptr& rgman = e->getRequestGroupMan(); + auto& rgman = e->getRequestGroupMan(); std::shared_ptr group = rgman->findGroup(gid); if(group) { return new RequestGroupDH(group); diff --git a/test/Aria2ApiTest.cc b/test/Aria2ApiTest.cc index e84482d5..fecf0f52 100644 --- a/test/Aria2ApiTest.cc +++ b/test/Aria2ApiTest.cc @@ -235,7 +235,7 @@ void Aria2ApiTest::testDownloadResultDH() std::shared_ptr dr2 = createDownloadResult(error_code::NETWORK_PROBLEM, "http://example.org/network"); - std::shared_ptr gman = + auto& gman = session_->context->reqinfo->getDownloadEngine()->getRequestGroupMan(); gman->addDownloadResult(dr1); gman->addDownloadResult(dr2); diff --git a/test/RequestGroupManTest.cc b/test/RequestGroupManTest.cc index b64c0390..47f22959 100644 --- a/test/RequestGroupManTest.cc +++ b/test/RequestGroupManTest.cc @@ -37,24 +37,23 @@ class RequestGroupManTest : public CppUnit::TestFixture { CPPUNIT_TEST(testAddDownloadResult); CPPUNIT_TEST_SUITE_END(); private: - std::shared_ptr e_; + std::unique_ptr e_; std::shared_ptr