DownloadEngine: Use std::unique_ptr for RequestGroupMan

pull/106/head
Tatsuhiro Tsujikawa 2013-07-06 00:59:43 +09:00
parent 697c1008f7
commit 68f2a33355
16 changed files with 81 additions and 79 deletions

View File

@ -578,10 +578,9 @@ void DownloadEngine::addCommand(std::unique_ptr<Command> command)
commands_.push_back(std::move(command)); commands_.push_back(std::move(command));
} }
void DownloadEngine::setRequestGroupMan void DownloadEngine::setRequestGroupMan(std::unique_ptr<RequestGroupMan> rgman)
(const std::shared_ptr<RequestGroupMan>& rgman)
{ {
requestGroupMan_ = rgman; requestGroupMan_ = std::move(rgman);
} }
void DownloadEngine::setFileAllocationMan void DownloadEngine::setFileAllocationMan

View File

@ -168,7 +168,7 @@ private:
findSocketPoolEntry(const std::string& key); findSocketPoolEntry(const std::string& key);
std::deque<std::unique_ptr<Command>> commands_; std::deque<std::unique_ptr<Command>> commands_;
std::shared_ptr<RequestGroupMan> requestGroupMan_; std::unique_ptr<RequestGroupMan> requestGroupMan_;
std::unique_ptr<FileAllocationMan> fileAllocationMan_; std::unique_ptr<FileAllocationMan> fileAllocationMan_;
std::unique_ptr<CheckIntegrityMan> checkIntegrityMan_; std::unique_ptr<CheckIntegrityMan> checkIntegrityMan_;
Option* option_; Option* option_;
@ -204,12 +204,12 @@ public:
void addCommand(std::unique_ptr<Command> command); void addCommand(std::unique_ptr<Command> command);
const std::shared_ptr<RequestGroupMan>& getRequestGroupMan() const const std::unique_ptr<RequestGroupMan>& getRequestGroupMan() const
{ {
return requestGroupMan_; return requestGroupMan_;
} }
void setRequestGroupMan(const std::shared_ptr<RequestGroupMan>& rgman); void setRequestGroupMan(std::unique_ptr<RequestGroupMan> rgman);
const std::unique_ptr<FileAllocationMan>& getFileAllocationMan() const const std::unique_ptr<FileAllocationMan>& getFileAllocationMan() const
{ {

View File

@ -148,11 +148,12 @@ DownloadEngineFactory::newDownloadEngine
} }
std::shared_ptr<DownloadEngine> e(new DownloadEngine(eventPoll)); std::shared_ptr<DownloadEngine> e(new DownloadEngine(eventPoll));
e->setOption(op); e->setOption(op);
{
auto requestGroupMan = std::make_shared<RequestGroupMan> auto requestGroupMan = make_unique<RequestGroupMan>
(std::move(requestGroups), MAX_CONCURRENT_DOWNLOADS, op); (std::move(requestGroups), MAX_CONCURRENT_DOWNLOADS, op);
requestGroupMan->initWrDiskCache(); requestGroupMan->initWrDiskCache();
e->setRequestGroupMan(requestGroupMan); e->setRequestGroupMan(std::move(requestGroupMan));
}
e->setFileAllocationMan(make_unique<FileAllocationMan>()); e->setFileAllocationMan(make_unique<FileAllocationMan>());
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
e->setCheckIntegrityMan(make_unique<CheckIntegrityMan>()); e->setCheckIntegrityMan(make_unique<CheckIntegrityMan>());

View File

@ -60,7 +60,7 @@ bool FillRequestGroupCommand::execute()
if(e_->isHaltRequested()) { if(e_->isHaltRequested()) {
return true; return true;
} }
const std::shared_ptr<RequestGroupMan>& rgman = e_->getRequestGroupMan(); auto& rgman = e_->getRequestGroupMan();
if(rgman->queueCheckRequested()) { if(rgman->queueCheckRequested()) {
while(rgman->queueCheckRequested()) { while(rgman->queueCheckRequested()) {
try { try {

View File

@ -288,7 +288,7 @@ error_code::Value MultiUrlRequestInfo::getResult()
returnValue = s.getLastErrorResult(); returnValue = s.getLastErrorResult();
} }
} }
SessionSerializer sessionSerializer(e_->getRequestGroupMan()); SessionSerializer sessionSerializer{e_->getRequestGroupMan().get()};
// TODO Add option: --save-session-status=error,inprogress,waiting // TODO Add option: --save-session-status=error,inprogress,waiting
if(!option_->blank(PREF_SAVE_SESSION)) { if(!option_->blank(PREF_SAVE_SESSION)) {
const std::string& filename = option_->get(PREF_SAVE_SESSION); const std::string& filename = option_->get(PREF_SAVE_SESSION);

View File

@ -1351,7 +1351,7 @@ std::shared_ptr<ValueBase> ForceShutdownRpcMethod::process
std::shared_ptr<ValueBase> GetGlobalStatRpcMethod::process std::shared_ptr<ValueBase> GetGlobalStatRpcMethod::process
(const RpcRequest& req, DownloadEngine* e) (const RpcRequest& req, DownloadEngine* e)
{ {
const std::shared_ptr<RequestGroupMan>& rgman = e->getRequestGroupMan(); auto& rgman = e->getRequestGroupMan();
TransferStat ts = rgman->calculateStat(); TransferStat ts = rgman->calculateStat();
std::shared_ptr<Dict> res = Dict::g(); std::shared_ptr<Dict> res = Dict::g();
res->put(KEY_DOWNLOAD_SPEED, util::itos(ts.downloadSpeed)); res->put(KEY_DOWNLOAD_SPEED, util::itos(ts.downloadSpeed));

View File

@ -64,7 +64,7 @@ void SaveSessionCommand::process()
->get(PREF_SAVE_SESSION); ->get(PREF_SAVE_SESSION);
if(!filename.empty()) { if(!filename.empty()) {
SessionSerializer sessionSerializer(getDownloadEngine()-> SessionSerializer sessionSerializer(getDownloadEngine()->
getRequestGroupMan()); getRequestGroupMan().get());
if(sessionSerializer.save(filename)) { if(sessionSerializer.save(filename)) {
A2_LOG_NOTICE(fmt(_("Serialized session to '%s' successfully."), A2_LOG_NOTICE(fmt(_("Serialized session to '%s' successfully."),
filename.c_str())); filename.c_str()));

View File

@ -60,11 +60,12 @@
namespace aria2 { namespace aria2 {
SessionSerializer::SessionSerializer SessionSerializer::SessionSerializer
(const std::shared_ptr<RequestGroupMan>& requestGroupMan): (RequestGroupMan* requestGroupMan)
rgman_(requestGroupMan), : rgman_{requestGroupMan},
saveError_(true), saveError_{true},
saveInProgress_(true), saveInProgress_{true},
saveWaiting_(true) {} saveWaiting_{true}
{}
bool SessionSerializer::save(const std::string& filename) const bool SessionSerializer::save(const std::string& filename) const
{ {

View File

@ -48,13 +48,13 @@ class IOFile;
class SessionSerializer { class SessionSerializer {
private: private:
std::shared_ptr<RequestGroupMan> rgman_; RequestGroupMan* rgman_;
bool saveError_; bool saveError_;
bool saveInProgress_; bool saveInProgress_;
bool saveWaiting_; bool saveWaiting_;
bool save(IOFile& fp) const; bool save(IOFile& fp) const;
public: public:
SessionSerializer(const std::shared_ptr<RequestGroupMan>& requestGroupMan); SessionSerializer(RequestGroupMan* requestGroupMan);
bool save(const std::string& filename) const; bool save(const std::string& filename) const;
}; };

View File

@ -525,7 +525,7 @@ GlobalStat getGlobalStat(Session* session)
{ {
const std::shared_ptr<DownloadEngine>& e = const std::shared_ptr<DownloadEngine>& e =
session->context->reqinfo->getDownloadEngine(); session->context->reqinfo->getDownloadEngine();
const std::shared_ptr<RequestGroupMan>& rgman = e->getRequestGroupMan(); auto& rgman = e->getRequestGroupMan();
TransferStat ts = rgman->calculateStat(); TransferStat ts = rgman->calculateStat();
GlobalStat res; GlobalStat res;
res.downloadSpeed = ts.downloadSpeed; res.downloadSpeed = ts.downloadSpeed;
@ -945,7 +945,7 @@ DownloadHandle* getDownloadHandle(Session* session, A2Gid gid)
{ {
const std::shared_ptr<DownloadEngine>& e = const std::shared_ptr<DownloadEngine>& e =
session->context->reqinfo->getDownloadEngine(); session->context->reqinfo->getDownloadEngine();
const std::shared_ptr<RequestGroupMan>& rgman = e->getRequestGroupMan(); auto& rgman = e->getRequestGroupMan();
std::shared_ptr<RequestGroup> group = rgman->findGroup(gid); std::shared_ptr<RequestGroup> group = rgman->findGroup(gid);
if(group) { if(group) {
return new RequestGroupDH(group); return new RequestGroupDH(group);

View File

@ -235,7 +235,7 @@ void Aria2ApiTest::testDownloadResultDH()
std::shared_ptr<DownloadResult> dr2 = std::shared_ptr<DownloadResult> dr2 =
createDownloadResult(error_code::NETWORK_PROBLEM, createDownloadResult(error_code::NETWORK_PROBLEM,
"http://example.org/network"); "http://example.org/network");
std::shared_ptr<RequestGroupMan> gman = auto& gman =
session_->context->reqinfo->getDownloadEngine()->getRequestGroupMan(); session_->context->reqinfo->getDownloadEngine()->getRequestGroupMan();
gman->addDownloadResult(dr1); gman->addDownloadResult(dr1);
gman->addDownloadResult(dr2); gman->addDownloadResult(dr2);

View File

@ -37,24 +37,23 @@ class RequestGroupManTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testAddDownloadResult); CPPUNIT_TEST(testAddDownloadResult);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
private: private:
std::shared_ptr<DownloadEngine> e_; std::unique_ptr<DownloadEngine> e_;
std::shared_ptr<Option> option_; std::shared_ptr<Option> option_;
std::shared_ptr<RequestGroupMan> rgman_; RequestGroupMan* rgman_;
public: public:
void setUp() void setUp()
{ {
option_.reset(new Option()); option_ = std::make_shared<Option>();
option_->put(PREF_PIECE_LENGTH, "1048576"); option_->put(PREF_PIECE_LENGTH, "1048576");
// To enable paused RequestGroup // To enable paused RequestGroup
option_->put(PREF_ENABLE_RPC, A2_V_TRUE); option_->put(PREF_ENABLE_RPC, A2_V_TRUE);
File(option_->get(PREF_DIR)).mkdirs(); File(option_->get(PREF_DIR)).mkdirs();
e_.reset e_ = make_unique<DownloadEngine>(std::make_shared<SelectEventPoll>());
(new DownloadEngine(std::shared_ptr<EventPoll>(new SelectEventPoll())));
e_->setOption(option_.get()); e_->setOption(option_.get());
rgman_ = std::shared_ptr<RequestGroupMan> auto rgman = make_unique<RequestGroupMan>
(new RequestGroupMan(std::vector<std::shared_ptr<RequestGroup> >(), (std::vector<std::shared_ptr<RequestGroup>>{}, 3, option_.get());
3, option_.get())); rgman_ = rgman.get();
e_->setRequestGroupMan(rgman_); e_->setRequestGroupMan(std::move(rgman));
} }
void testIsSameFileBeingDownloaded(); void testIsSameFileBeingDownloaded();

View File

@ -84,18 +84,16 @@ private:
public: public:
void setUp() void setUp()
{ {
option_.reset(new Option()); option_ = std::make_shared<Option>();
option_->put(PREF_DIR, A2_TEST_OUT_DIR"/aria2_RpcMethodTest"); option_->put(PREF_DIR, A2_TEST_OUT_DIR"/aria2_RpcMethodTest");
option_->put(PREF_PIECE_LENGTH, "1048576"); option_->put(PREF_PIECE_LENGTH, "1048576");
option_->put(PREF_MAX_DOWNLOAD_RESULT, "10"); option_->put(PREF_MAX_DOWNLOAD_RESULT, "10");
File(option_->get(PREF_DIR)).mkdirs(); File(option_->get(PREF_DIR)).mkdirs();
e_.reset e_ = make_unique<DownloadEngine>(std::make_shared<SelectEventPoll>());
(new DownloadEngine(std::shared_ptr<EventPoll>(new SelectEventPoll())));
e_->setOption(option_.get()); e_->setOption(option_.get());
e_->setRequestGroupMan e_->setRequestGroupMan
(std::shared_ptr<RequestGroupMan> (make_unique<RequestGroupMan>
(new RequestGroupMan(std::vector<std::shared_ptr<RequestGroup> >(), (std::vector<std::shared_ptr<RequestGroup>>{}, 1, option_.get()));
1, option_.get())));
} }
void testAddUri(); void testAddUri();
@ -182,7 +180,8 @@ void RpcMethodTest::testAddUri()
CPPUNIT_ASSERT_EQUAL(0, GroupId::toNumericId CPPUNIT_ASSERT_EQUAL(0, GroupId::toNumericId
(gid, downcast<String>(res.param)->s().c_str())); (gid, downcast<String>(res.param)->s().c_str()));
CPPUNIT_ASSERT_EQUAL(std::string("/sink"), CPPUNIT_ASSERT_EQUAL(std::string("/sink"),
findReservedGroup(e_->getRequestGroupMan(), gid)-> findReservedGroup(e_->getRequestGroupMan().get(),
gid)->
getOption()->get(PREF_DIR)); getOption()->get(PREF_DIR));
} }
} }
@ -239,7 +238,7 @@ void RpcMethodTest::testAddUri_withPosition()
m.execute(req2, e_.get()); m.execute(req2, e_.get());
std::string uri = std::string uri =
getReservedGroup(e_->getRequestGroupMan(), 0)-> getReservedGroup(e_->getRequestGroupMan().get(), 0)->
getDownloadContext()->getFirstFileEntry()->getRemainingUris()[0]; getDownloadContext()->getFirstFileEntry()->getRemainingUris()[0];
CPPUNIT_ASSERT_EQUAL(std::string("http://uri2"), uri); CPPUNIT_ASSERT_EQUAL(std::string("http://uri2"), uri);
@ -290,8 +289,7 @@ void RpcMethodTest::testAddTorrent()
CPPUNIT_ASSERT_EQUAL(0, GroupId::toNumericId CPPUNIT_ASSERT_EQUAL(0, GroupId::toNumericId
(gid, downcast<String>(res.param)->s().c_str())); (gid, downcast<String>(res.param)->s().c_str()));
std::shared_ptr<RequestGroup> group = auto group = findReservedGroup(e_->getRequestGroupMan().get(), gid);
findReservedGroup(e_->getRequestGroupMan(), gid);
CPPUNIT_ASSERT(group); CPPUNIT_ASSERT(group);
CPPUNIT_ASSERT_EQUAL(e_->getOption()->get(PREF_DIR)+"/aria2-0.8.2.tar.bz2", CPPUNIT_ASSERT_EQUAL(e_->getOption()->get(PREF_DIR)+"/aria2-0.8.2.tar.bz2",
group->getFirstFilePath()); group->getFirstFilePath());
@ -317,7 +315,8 @@ void RpcMethodTest::testAddTorrent()
(gid, downcast<String>(res.param)->s().c_str())); (gid, downcast<String>(res.param)->s().c_str()));
CPPUNIT_ASSERT_EQUAL CPPUNIT_ASSERT_EQUAL
(dir+"/aria2-0.8.2.tar.bz2", (dir+"/aria2-0.8.2.tar.bz2",
findReservedGroup(e_->getRequestGroupMan(), gid)->getFirstFilePath()); findReservedGroup(e_->getRequestGroupMan().get(), gid)
->getFirstFilePath());
CPPUNIT_ASSERT CPPUNIT_ASSERT
(File(dir+"/0a3893293e27ac0490424c06de4d09242215f0a6.torrent").exists()); (File(dir+"/0a3893293e27ac0490424c06de4d09242215f0a6.torrent").exists());
} }
@ -358,7 +357,7 @@ void RpcMethodTest::testAddTorrent_withPosition()
m.execute(req2, e_.get()); m.execute(req2, e_.get());
CPPUNIT_ASSERT_EQUAL((size_t)1, CPPUNIT_ASSERT_EQUAL((size_t)1,
getReservedGroup(e_->getRequestGroupMan(), 0)-> getReservedGroup(e_->getRequestGroupMan().get(), 0)->
getDownloadContext()->getFileEntries().size()); getDownloadContext()->getFileEntries().size());
} }
@ -408,13 +407,11 @@ void RpcMethodTest::testAddMetalink()
"/c908634fbc257fd56f0114912c2772aeeb4064f4.meta4").exists()); "/c908634fbc257fd56f0114912c2772aeeb4064f4.meta4").exists());
#endif // ENABLE_MESSAGE_DIGEST #endif // ENABLE_MESSAGE_DIGEST
std::shared_ptr<RequestGroup> tar = auto tar = findReservedGroup(e_->getRequestGroupMan().get(), gid3);
findReservedGroup(e_->getRequestGroupMan(), gid3);
CPPUNIT_ASSERT(tar); CPPUNIT_ASSERT(tar);
CPPUNIT_ASSERT_EQUAL(e_->getOption()->get(PREF_DIR)+"/aria2-5.0.0.tar.bz2", CPPUNIT_ASSERT_EQUAL(e_->getOption()->get(PREF_DIR)+"/aria2-5.0.0.tar.bz2",
tar->getFirstFilePath()); tar->getFirstFilePath());
std::shared_ptr<RequestGroup> deb = auto deb = findReservedGroup(e_->getRequestGroupMan().get(), gid4);
findReservedGroup(e_->getRequestGroupMan(), gid4);
CPPUNIT_ASSERT(deb); CPPUNIT_ASSERT(deb);
CPPUNIT_ASSERT_EQUAL(e_->getOption()->get(PREF_DIR)+"/aria2-5.0.0.deb", CPPUNIT_ASSERT_EQUAL(e_->getOption()->get(PREF_DIR)+"/aria2-5.0.0.deb",
deb->getFirstFilePath()); deb->getFirstFilePath());
@ -436,7 +433,8 @@ void RpcMethodTest::testAddMetalink()
(0, GroupId::toNumericId (0, GroupId::toNumericId
(gid5, downcast<String>(resParams->get(0))->s().c_str())); (gid5, downcast<String>(resParams->get(0))->s().c_str()));
CPPUNIT_ASSERT_EQUAL(dir+"/aria2-5.0.0.tar.bz2", CPPUNIT_ASSERT_EQUAL(dir+"/aria2-5.0.0.tar.bz2",
findReservedGroup(e_->getRequestGroupMan(), gid5)-> findReservedGroup
(e_->getRequestGroupMan().get(), gid5)->
getFirstFilePath()); getFirstFilePath());
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
CPPUNIT_ASSERT CPPUNIT_ASSERT
@ -481,7 +479,7 @@ void RpcMethodTest::testAddMetalink_withPosition()
CPPUNIT_ASSERT_EQUAL(0, res2.code); CPPUNIT_ASSERT_EQUAL(0, res2.code);
CPPUNIT_ASSERT_EQUAL(e_->getOption()->get(PREF_DIR)+"/aria2-5.0.0.tar.bz2", CPPUNIT_ASSERT_EQUAL(e_->getOption()->get(PREF_DIR)+"/aria2-5.0.0.tar.bz2",
getReservedGroup(e_->getRequestGroupMan(), 0)-> getReservedGroup(e_->getRequestGroupMan().get(), 0)->
getFirstFilePath()); getFirstFilePath());
} }
@ -712,7 +710,7 @@ void RpcMethodTest::testTellWaiting()
#else // !ENABLE_BITTORRENT #else // !ENABLE_BITTORRENT
addUri("http://4/", e_); addUri("http://4/", e_);
#endif // !ENABLE_BITTORRENT #endif // !ENABLE_BITTORRENT
const std::shared_ptr<RequestGroupMan>& rgman = e_->getRequestGroupMan(); auto& rgman = e_->getRequestGroupMan();
TellWaitingRpcMethod m; TellWaitingRpcMethod m;
RpcRequest req(TellWaitingRpcMethod::getMethodName(), List::g()); RpcRequest req(TellWaitingRpcMethod::getMethodName(), List::g());
req.params->append(Integer::g(1)); req.params->append(Integer::g(1));
@ -721,9 +719,11 @@ void RpcMethodTest::testTellWaiting()
CPPUNIT_ASSERT_EQUAL(0, res.code); CPPUNIT_ASSERT_EQUAL(0, res.code);
const List* resParams = downcast<List>(res.param); const List* resParams = downcast<List>(res.param);
CPPUNIT_ASSERT_EQUAL((size_t)2, resParams->size()); CPPUNIT_ASSERT_EQUAL((size_t)2, resParams->size());
CPPUNIT_ASSERT_EQUAL(GroupId::toHex(getReservedGroup(rgman, 1)->getGID()), CPPUNIT_ASSERT_EQUAL(GroupId::toHex(getReservedGroup(rgman.get(), 1)
->getGID()),
getString(downcast<Dict>(resParams->get(0)), "gid")); getString(downcast<Dict>(resParams->get(0)), "gid"));
CPPUNIT_ASSERT_EQUAL(GroupId::toHex(getReservedGroup(rgman, 2)->getGID()), CPPUNIT_ASSERT_EQUAL(GroupId::toHex(getReservedGroup(rgman.get(), 2)
->getGID()),
getString(downcast<Dict>(resParams->get(1)), "gid")); getString(downcast<Dict>(resParams->get(1)), "gid"));
// waiting.size() == offset+num // waiting.size() == offset+num
req = RpcRequest(TellWaitingRpcMethod::getMethodName(), List::g()); req = RpcRequest(TellWaitingRpcMethod::getMethodName(), List::g());
@ -779,9 +779,11 @@ void RpcMethodTest::testTellWaiting()
CPPUNIT_ASSERT_EQUAL(0, res.code); CPPUNIT_ASSERT_EQUAL(0, res.code);
resParams = downcast<List>(res.param); resParams = downcast<List>(res.param);
CPPUNIT_ASSERT_EQUAL((size_t)2, resParams->size()); CPPUNIT_ASSERT_EQUAL((size_t)2, resParams->size());
CPPUNIT_ASSERT_EQUAL(GroupId::toHex(getReservedGroup(rgman, 3)->getGID()), CPPUNIT_ASSERT_EQUAL(GroupId::toHex(getReservedGroup(rgman.get(),
3)->getGID()),
getString(downcast<Dict>(resParams->get(0)), "gid")); getString(downcast<Dict>(resParams->get(0)), "gid"));
CPPUNIT_ASSERT_EQUAL(GroupId::toHex(getReservedGroup(rgman, 2)->getGID()), CPPUNIT_ASSERT_EQUAL(GroupId::toHex(getReservedGroup(rgman.get(),
2)->getGID()),
getString(downcast<Dict>(resParams->get(1)), "gid")); getString(downcast<Dict>(resParams->get(1)), "gid"));
// negative offset and size < num // negative offset and size < num
req.params->set(1, Integer::g(100)); req.params->set(1, Integer::g(100));
@ -973,7 +975,7 @@ void RpcMethodTest::testChangePosition()
(std::shared_ptr<RequestGroup>(new RequestGroup(GroupId::create(), (std::shared_ptr<RequestGroup>(new RequestGroup(GroupId::create(),
util::copy(option_)))); util::copy(option_))));
a2_gid_t gid = getReservedGroup(e_->getRequestGroupMan(), 0)->getGID(); a2_gid_t gid = getReservedGroup(e_->getRequestGroupMan().get(), 0)->getGID();
ChangePositionRpcMethod m; ChangePositionRpcMethod m;
RpcRequest req(ChangePositionRpcMethod::getMethodName(), List::g()); RpcRequest req(ChangePositionRpcMethod::getMethodName(), List::g());
req.params->append(GroupId::toHex(gid)); req.params->append(GroupId::toHex(gid));
@ -983,7 +985,7 @@ void RpcMethodTest::testChangePosition()
CPPUNIT_ASSERT_EQUAL(0, res.code); CPPUNIT_ASSERT_EQUAL(0, res.code);
CPPUNIT_ASSERT_EQUAL((int64_t)1, downcast<Integer>(res.param)->i()); CPPUNIT_ASSERT_EQUAL((int64_t)1, downcast<Integer>(res.param)->i());
CPPUNIT_ASSERT_EQUAL CPPUNIT_ASSERT_EQUAL
(gid, getReservedGroup(e_->getRequestGroupMan(), 1)->getGID()); (gid, getReservedGroup(e_->getRequestGroupMan().get(), 1)->getGID());
} }
void RpcMethodTest::testChangePosition_fail() void RpcMethodTest::testChangePosition_fail()
@ -1246,10 +1248,12 @@ void RpcMethodTest::testSystemMulticall()
CPPUNIT_ASSERT_EQUAL(0, res.code); CPPUNIT_ASSERT_EQUAL(0, res.code);
const List* resParams = downcast<List>(res.param); const List* resParams = downcast<List>(res.param);
CPPUNIT_ASSERT_EQUAL((size_t)7, resParams->size()); CPPUNIT_ASSERT_EQUAL((size_t)7, resParams->size());
std::shared_ptr<RequestGroupMan> rgman = e_->getRequestGroupMan(); auto& rgman = e_->getRequestGroupMan();
CPPUNIT_ASSERT_EQUAL(GroupId::toHex(getReservedGroup(rgman, 0)->getGID()), CPPUNIT_ASSERT_EQUAL(GroupId::toHex(getReservedGroup(rgman.get(), 0)
->getGID()),
downcast<String>(downcast<List>(resParams->get(0))->get(0))->s()); downcast<String>(downcast<List>(resParams->get(0))->get(0))->s());
CPPUNIT_ASSERT_EQUAL(GroupId::toHex(getReservedGroup(rgman, 1)->getGID()), CPPUNIT_ASSERT_EQUAL(GroupId::toHex(getReservedGroup(rgman.get(), 1)
->getGID()),
downcast<String>(downcast<List>(resParams->get(1))->get(0))->s()); downcast<String>(downcast<List>(resParams->get(1))->get(0))->s());
CPPUNIT_ASSERT_EQUAL((int64_t)1, CPPUNIT_ASSERT_EQUAL((int64_t)1,
downcast<Integer> downcast<Integer>

View File

@ -48,9 +48,8 @@ void SessionSerializerTest::testSave()
CPPUNIT_ASSERT_EQUAL((size_t)5, result.size()); CPPUNIT_ASSERT_EQUAL((size_t)5, result.size());
result[4]->getOption()->put(PREF_PAUSE, A2_V_TRUE); result[4]->getOption()->put(PREF_PAUSE, A2_V_TRUE);
option->put(PREF_MAX_DOWNLOAD_RESULT, "10"); option->put(PREF_MAX_DOWNLOAD_RESULT, "10");
std::shared_ptr<RequestGroupMan> rgman RequestGroupMan rgman{result, 1, option.get()};
(new RequestGroupMan(result, 1, option.get())); SessionSerializer s(&rgman);
SessionSerializer s(rgman);
std::shared_ptr<DownloadResult> drs[] = { std::shared_ptr<DownloadResult> drs[] = {
// REMOVED downloads will not be saved. // REMOVED downloads will not be saved.
createDownloadResult(error_code::REMOVED, "http://removed"), createDownloadResult(error_code::REMOVED, "http://removed"),
@ -76,13 +75,13 @@ void SessionSerializerTest::testSave()
drs[3]->option->put(PREF_FORCE_SAVE, A2_V_TRUE); drs[3]->option->put(PREF_FORCE_SAVE, A2_V_TRUE);
for(size_t i = 0; i < sizeof(drs)/sizeof(drs[0]); ++i) { for(size_t i = 0; i < sizeof(drs)/sizeof(drs[0]); ++i) {
rgman->addDownloadResult(drs[i]); rgman.addDownloadResult(drs[i]);
} }
DownloadEngine e(std::shared_ptr<EventPoll>(new SelectEventPoll())); DownloadEngine e(std::shared_ptr<EventPoll>(new SelectEventPoll()));
e.setOption(option.get()); e.setOption(option.get());
rgman->fillRequestGroupFromReserver(&e); rgman.fillRequestGroupFromReserver(&e);
CPPUNIT_ASSERT_EQUAL((size_t)1, rgman->getRequestGroups().size()); CPPUNIT_ASSERT_EQUAL((size_t)1, rgman.getRequestGroups().size());
std::string filename = A2_TEST_OUT_DIR"/aria2_SessionSerializerTest_testSave"; std::string filename = A2_TEST_OUT_DIR"/aria2_SessionSerializerTest_testSave";
s.save(filename); s.save(filename);
@ -148,11 +147,10 @@ void SessionSerializerTest::testSaveErrorDownload()
(dr->fileEntries[0]->getRemainingUris()); (dr->fileEntries[0]->getRemainingUris());
std::shared_ptr<Option> option(new Option()); std::shared_ptr<Option> option(new Option());
option->put(PREF_MAX_DOWNLOAD_RESULT, "10"); option->put(PREF_MAX_DOWNLOAD_RESULT, "10");
std::shared_ptr<RequestGroupMan> rgman RequestGroupMan rgman{std::vector<std::shared_ptr<RequestGroup> >(), 1,
(new RequestGroupMan(std::vector<std::shared_ptr<RequestGroup> >(), 1, option.get()};
option.get())); rgman.addDownloadResult(dr);
rgman->addDownloadResult(dr); SessionSerializer s(&rgman);
SessionSerializer s(rgman);
std::string filename = std::string filename =
A2_TEST_OUT_DIR"/aria2_SessionSerializerTest_testSaveErrorDownload"; A2_TEST_OUT_DIR"/aria2_SessionSerializerTest_testSaveErrorDownload";
CPPUNIT_ASSERT(s.save(filename)); CPPUNIT_ASSERT(s.save(filename));

View File

@ -104,9 +104,9 @@ WrDiskCacheEntry::DataCell* createDataCell(int64_t goff,
} }
std::shared_ptr<RequestGroup> findReservedGroup std::shared_ptr<RequestGroup> findReservedGroup
(const std::shared_ptr<RequestGroupMan>& rgman, a2_gid_t gid) (RequestGroupMan* rgman, a2_gid_t gid)
{ {
std::shared_ptr<RequestGroup> rg = rgman->findGroup(gid); auto rg = rgman->findGroup(gid);
if(rg) { if(rg) {
if(rg->getState() == RequestGroup::STATE_WAITING) { if(rg->getState() == RequestGroup::STATE_WAITING) {
return rg; return rg;
@ -118,10 +118,10 @@ std::shared_ptr<RequestGroup> findReservedGroup
} }
std::shared_ptr<RequestGroup> getReservedGroup std::shared_ptr<RequestGroup> getReservedGroup
(const std::shared_ptr<RequestGroupMan>& rgman, size_t index) (RequestGroupMan* rgman, size_t index)
{ {
assert(rgman->getReservedGroups().size() > index); assert(rgman->getReservedGroups().size() > index);
RequestGroupList::const_iterator i = rgman->getReservedGroups().begin(); auto i = rgman->getReservedGroups().begin();
std::advance(i, index); std::advance(i, index);
return *i; return *i;
} }

View File

@ -60,10 +60,10 @@ WrDiskCacheEntry::DataCell* createDataCell(int64_t goff,
size_t offset = 0); size_t offset = 0);
std::shared_ptr<RequestGroup> findReservedGroup std::shared_ptr<RequestGroup> findReservedGroup
(const std::shared_ptr<RequestGroupMan>& rgman, a2_gid_t gid); (RequestGroupMan* rgman, a2_gid_t gid);
std::shared_ptr<RequestGroup> getReservedGroup std::shared_ptr<RequestGroup> getReservedGroup
(const std::shared_ptr<RequestGroupMan>& rgman, size_t index); (RequestGroupMan* rgman, size_t index);
std::shared_ptr<RequestGroup> createRequestGroup(int32_t pieceLength, std::shared_ptr<RequestGroup> createRequestGroup(int32_t pieceLength,
int64_t totalLength, int64_t totalLength,