From b96eb7fd79cb357358fdfe06dbb5dda4a59a162f Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 11 May 2008 13:59:27 +0000 Subject: [PATCH] 2008-05-11 Tatsuhiro Tsujikawa Changed method signature: PostDownloadHandler::getNextRequestGroups Metalink2RequestGroup::generate RequestGroup::postDownloadProcessing * src/BtPostDownloadHandler.cc * src/BtPostDownloadHandler.h * src/Metalink2RequestGroup.cc * src/Metalink2RequestGroup.h * src/MetalinkPostDownloadHandler.cc * src/MetalinkPostDownloadHandler.h * src/PostDownloadHandler.h * src/RequestGroup.cc * src/RequestGroup.h * src/RequestGroupMan.cc * src/main.cc * test/BtPostDownloadHandlerTest.cc * test/Metalink2RequestGroupTest.cc * test/MetalinkPostDownloadHandlerTest.cc --- ChangeLog | 21 +++++++++++++++++++++ src/BtPostDownloadHandler.cc | 6 +++--- src/BtPostDownloadHandler.h | 5 +++-- src/Metalink2RequestGroup.cc | 24 +++++++++++++----------- src/Metalink2RequestGroup.h | 11 +++++++---- src/MetalinkPostDownloadHandler.cc | 8 ++++---- src/MetalinkPostDownloadHandler.h | 5 +++-- src/PostDownloadHandler.h | 5 +++-- src/RequestGroup.cc | 8 ++++---- src/RequestGroup.h | 2 +- src/RequestGroupMan.cc | 3 ++- src/main.cc | 7 +++---- test/BtPostDownloadHandlerTest.cc | 3 ++- test/Metalink2RequestGroupTest.cc | 4 ++-- test/MetalinkPostDownloadHandlerTest.cc | 3 ++- 15 files changed, 73 insertions(+), 42 deletions(-) diff --git a/ChangeLog b/ChangeLog index b8907a10..498badd5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2008-05-11 Tatsuhiro Tsujikawa + + Changed method signature: + PostDownloadHandler::getNextRequestGroups + Metalink2RequestGroup::generate + RequestGroup::postDownloadProcessing + * src/BtPostDownloadHandler.cc + * src/BtPostDownloadHandler.h + * src/Metalink2RequestGroup.cc + * src/Metalink2RequestGroup.h + * src/MetalinkPostDownloadHandler.cc + * src/MetalinkPostDownloadHandler.h + * src/PostDownloadHandler.h + * src/RequestGroup.cc + * src/RequestGroup.h + * src/RequestGroupMan.cc + * src/main.cc + * test/BtPostDownloadHandlerTest.cc + * test/Metalink2RequestGroupTest.cc + * test/MetalinkPostDownloadHandlerTest.cc + 2008-05-11 Tatsuhiro Tsujikawa Rewritten AccRequestGroup diff --git a/src/BtPostDownloadHandler.cc b/src/BtPostDownloadHandler.cc index 92a68b77..68be6fea 100644 --- a/src/BtPostDownloadHandler.cc +++ b/src/BtPostDownloadHandler.cc @@ -58,7 +58,9 @@ BtPostDownloadHandler::BtPostDownloadHandler() BtPostDownloadHandler::~BtPostDownloadHandler() {} -RequestGroups BtPostDownloadHandler::getNextRequestGroups(RequestGroup* requestGroup) +void BtPostDownloadHandler::getNextRequestGroups +(std::deque >& groups, + RequestGroup* requestGroup) { const Option* op = requestGroup->getOption(); _logger->debug("Generating RequestGroups for Torrent file %s", @@ -83,9 +85,7 @@ RequestGroups BtPostDownloadHandler::getNextRequestGroups(RequestGroup* requestG rg->setDownloadContext(btContext); btContext->setOwnerRequestGroup(rg.get()); - RequestGroups groups; groups.push_back(rg); - return groups; } } // namespace aria2 diff --git a/src/BtPostDownloadHandler.h b/src/BtPostDownloadHandler.h index 4d10f035..0d05f925 100644 --- a/src/BtPostDownloadHandler.h +++ b/src/BtPostDownloadHandler.h @@ -46,8 +46,9 @@ public: virtual ~BtPostDownloadHandler(); - virtual std::deque > - getNextRequestGroups(RequestGroup* requestGroup); + virtual void + getNextRequestGroups(std::deque >& groups, + RequestGroup* requestGroup); }; typedef SharedHandle BtPostDownloadHandlerHandle; diff --git a/src/Metalink2RequestGroup.cc b/src/Metalink2RequestGroup.cc index e62c8c7f..c8a23826 100644 --- a/src/Metalink2RequestGroup.cc +++ b/src/Metalink2RequestGroup.cc @@ -98,28 +98,32 @@ public: } }; -std::deque > -Metalink2RequestGroup::generate(const std::string& metalinkFile) +void +Metalink2RequestGroup::generate(std::deque >& groups, + const std::string& metalinkFile) { std::deque > entries = MetalinkHelper::parseAndQuery(metalinkFile, _option); - return createRequestGroup(entries); + createRequestGroup(groups, entries); } -std::deque > -Metalink2RequestGroup::generate(const SharedHandle& binaryStream) +void +Metalink2RequestGroup::generate(std::deque >& groups, + const SharedHandle& binaryStream) { std::deque > entries = MetalinkHelper::parseAndQuery(binaryStream, _option); - return createRequestGroup(entries); + createRequestGroup(groups, entries); } -std::deque > -Metalink2RequestGroup::createRequestGroup(std::deque > entries) +void +Metalink2RequestGroup::createRequestGroup +(std::deque >& groups, + std::deque > entries) { if(entries.size() == 0) { _logger->notice(EX_NO_RESULT_WITH_YOUR_PREFS); - return std::deque >(); + return; } std::deque selectIndexes = Util::parseIntRange(_option->get(PREF_SELECT_FILE)).flush(); bool useIndex; @@ -128,7 +132,6 @@ Metalink2RequestGroup::createRequestGroup(std::deque } else { useIndex = false; } - std::deque > groups; unsigned int count = 0; for(std::deque >::iterator itr = entries.begin(); itr != entries.end(); itr++, ++count) { @@ -235,7 +238,6 @@ Metalink2RequestGroup::createRequestGroup(std::deque #endif // ENABLE_BITTORRENT groups.push_back(rg); } - return groups; } } // namespace aria2 diff --git a/src/Metalink2RequestGroup.h b/src/Metalink2RequestGroup.h index fd591678..276c2a00 100644 --- a/src/Metalink2RequestGroup.h +++ b/src/Metalink2RequestGroup.h @@ -54,16 +54,19 @@ private: Logger* _logger; - std::deque > - createRequestGroup(std::deque > entries); + void + createRequestGroup(std::deque >& groups, + std::deque > entries); public: Metalink2RequestGroup(const Option* option); ~Metalink2RequestGroup(); - std::deque > generate(const std::string& metalinkFile); + void generate(std::deque >& groups, + const std::string& metalinkFile); - std::deque > generate(const SharedHandle& binaryStream); + void generate(std::deque >& groups, + const SharedHandle& binaryStream); }; } // namespace aria2 diff --git a/src/MetalinkPostDownloadHandler.cc b/src/MetalinkPostDownloadHandler.cc index bd2cebd4..95344f65 100644 --- a/src/MetalinkPostDownloadHandler.cc +++ b/src/MetalinkPostDownloadHandler.cc @@ -54,8 +54,9 @@ MetalinkPostDownloadHandler::MetalinkPostDownloadHandler() MetalinkPostDownloadHandler::~MetalinkPostDownloadHandler() {} -std::deque > -MetalinkPostDownloadHandler::getNextRequestGroups(RequestGroup* requestGroup) +void MetalinkPostDownloadHandler::getNextRequestGroups +(std::deque >& groups, + RequestGroup* requestGroup) { const Option* op = requestGroup->getOption(); _logger->debug("Generating RequestGroups for Metalink file %s", @@ -63,9 +64,8 @@ MetalinkPostDownloadHandler::getNextRequestGroups(RequestGroup* requestGroup) SharedHandle diskAdaptor = requestGroup->getPieceStorage()->getDiskAdaptor(); try { diskAdaptor->openExistingFile(); - std::deque > rgs = Metalink2RequestGroup(op).generate(diskAdaptor); + Metalink2RequestGroup(op).generate(groups, diskAdaptor); diskAdaptor->closeFile(); - return rgs; } catch(Exception& e) { diskAdaptor->closeFile(); throw; diff --git a/src/MetalinkPostDownloadHandler.h b/src/MetalinkPostDownloadHandler.h index 78590662..00566e30 100644 --- a/src/MetalinkPostDownloadHandler.h +++ b/src/MetalinkPostDownloadHandler.h @@ -46,8 +46,9 @@ public: virtual ~MetalinkPostDownloadHandler(); - virtual std::deque > - getNextRequestGroups(RequestGroup* requestGroup); + virtual void + getNextRequestGroups(std::deque >& groups, + RequestGroup* requestGroup); }; typedef SharedHandle MetalinkPostDownloadHandlerHandle; diff --git a/src/PostDownloadHandler.h b/src/PostDownloadHandler.h index 7e6c8fb5..56456a85 100644 --- a/src/PostDownloadHandler.h +++ b/src/PostDownloadHandler.h @@ -46,8 +46,9 @@ public: virtual ~PostDownloadHandler() {} - virtual std::deque > - getNextRequestGroups(RequestGroup* requestGroup) = 0; + virtual void + getNextRequestGroups(std::deque >& groups, + RequestGroup* requestGroup) = 0; }; typedef SharedHandle PostDownloadHandlerHandle; diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index 072a1f36..e761ea28 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -706,22 +706,22 @@ void RequestGroup::preDownloadProcessing() return; } -RequestGroups RequestGroup::postDownloadProcessing() +void RequestGroup::postDownloadProcessing +(std::deque >& groups) { _logger->debug("Finding PostDownloadHandler for path %s.", getFilePath().c_str()); try { for(PostDownloadHandlers::const_iterator itr = _postDownloadHandlers.begin(); itr != _postDownloadHandlers.end(); ++itr) { if((*itr)->canHandle(this)) { - return (*itr)->getNextRequestGroups(this); + (*itr)->getNextRequestGroups(groups, this); + return; } } } catch(RecoverableException& ex) { _logger->error(EX_EXCEPTION_CAUGHT, ex); - return RequestGroups(); } _logger->debug("No PostDownloadHandler found."); - return RequestGroups(); } void RequestGroup::initializePreDownloadHandler() diff --git a/src/RequestGroup.h b/src/RequestGroup.h index 764079fd..96ef2163 100644 --- a/src/RequestGroup.h +++ b/src/RequestGroup.h @@ -283,7 +283,7 @@ public: void releaseRuntimeResource(); - std::deque > postDownloadProcessing(); + void postDownloadProcessing(std::deque >& groups); void addPostDownloadHandler(const SharedHandle& handler); diff --git a/src/RequestGroupMan.cc b/src/RequestGroupMan.cc index c46fa1b7..9c05cc1e 100644 --- a/src/RequestGroupMan.cc +++ b/src/RequestGroupMan.cc @@ -117,7 +117,8 @@ void RequestGroupMan::removeStoppedGroup() } else { (*itr)->getProgressInfoFile()->save(); } - RequestGroups nextGroups = (*itr)->postDownloadProcessing(); + RequestGroups nextGroups; + (*itr)->postDownloadProcessing(nextGroups); if(nextGroups.size() > 0) { _logger->debug("Adding %u RequestGroups as a result of PostDownloadHandler.", nextGroups.size()); std::copy(nextGroups.rbegin(), nextGroups.rend(), std::front_inserter(_reservedGroups)); diff --git a/src/main.cc b/src/main.cc index b6b7d364..fbd0e5e0 100644 --- a/src/main.cc +++ b/src/main.cc @@ -190,7 +190,8 @@ int32_t downloadBitTorrent(Option* op, const std::deque& uri) #ifdef ENABLE_METALINK int32_t downloadMetalink(Option* op) { - RequestGroups groups = Metalink2RequestGroup(op).generate(op->get(PREF_METALINK_FILE)); + RequestGroups groups; + Metalink2RequestGroup(op).generate(groups, op->get(PREF_METALINK_FILE)); if(groups.empty()) { throw FatalException("No files to download."); } @@ -234,9 +235,7 @@ public: #ifdef ENABLE_METALINK else if(_detector.guessMetalinkFile(uri)) { try { - std::deque > metalinkGroups = - Metalink2RequestGroup(_op).generate(uri); - _requestGroups.insert(_requestGroups.end(), metalinkGroups.begin(), metalinkGroups.end()); + Metalink2RequestGroup(_op).generate(_requestGroups, uri); } catch(RecoverableException& e) { // error occurred while parsing metalink file. // We simply ignore it. diff --git a/test/BtPostDownloadHandlerTest.cc b/test/BtPostDownloadHandlerTest.cc index 1c457459..cc202dc6 100644 --- a/test/BtPostDownloadHandlerTest.cc +++ b/test/BtPostDownloadHandlerTest.cc @@ -71,7 +71,8 @@ void BtPostDownloadHandlerTest::testGetNextRequestGroups() rg.initPieceStorage(); BtPostDownloadHandler handler; - std::deque > groups = handler.getNextRequestGroups(&rg); + std::deque > groups; + handler.getNextRequestGroups(groups, &rg); CPPUNIT_ASSERT_EQUAL((size_t)1, groups.size()); SharedHandle btctx (dynamic_pointer_cast(groups.front()->getDownloadContext())); diff --git a/test/Metalink2RequestGroupTest.cc b/test/Metalink2RequestGroupTest.cc index 8a906163..4a2ec4f2 100644 --- a/test/Metalink2RequestGroupTest.cc +++ b/test/Metalink2RequestGroupTest.cc @@ -32,8 +32,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION( Metalink2RequestGroupTest ); void Metalink2RequestGroupTest::testGenerate() { - std::deque > groups = - Metalink2RequestGroup(_option.get()).generate("test.xml"); + std::deque > groups; + Metalink2RequestGroup(_option.get()).generate(groups, "test.xml"); // first file { SharedHandle rg = groups[0]; diff --git a/test/MetalinkPostDownloadHandlerTest.cc b/test/MetalinkPostDownloadHandlerTest.cc index 86b71903..87d13974 100644 --- a/test/MetalinkPostDownloadHandlerTest.cc +++ b/test/MetalinkPostDownloadHandlerTest.cc @@ -70,7 +70,8 @@ void MetalinkPostDownloadHandlerTest::testGetNextRequestGroups() rg.initPieceStorage(); MetalinkPostDownloadHandler handler; - RequestGroups groups = handler.getNextRequestGroups(&rg); + RequestGroups groups; + handler.getNextRequestGroups(groups, &rg); #ifdef ENABLE_BITTORRENT CPPUNIT_ASSERT_EQUAL((size_t)6/* 5 + 1 torrent file download */, groups.size()); #else