mirror of https://github.com/aria2/aria2
2008-05-11 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
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.ccpull/1/head
parent
3884d710d3
commit
b96eb7fd79
21
ChangeLog
21
ChangeLog
|
@ -1,3 +1,24 @@
|
|||
2008-05-11 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
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 <tujikawa at rednoah dot com>
|
||||
|
||||
Rewritten AccRequestGroup
|
||||
|
|
|
@ -58,7 +58,9 @@ BtPostDownloadHandler::BtPostDownloadHandler()
|
|||
|
||||
BtPostDownloadHandler::~BtPostDownloadHandler() {}
|
||||
|
||||
RequestGroups BtPostDownloadHandler::getNextRequestGroups(RequestGroup* requestGroup)
|
||||
void BtPostDownloadHandler::getNextRequestGroups
|
||||
(std::deque<SharedHandle<RequestGroup> >& 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
|
||||
|
|
|
@ -46,8 +46,9 @@ public:
|
|||
|
||||
virtual ~BtPostDownloadHandler();
|
||||
|
||||
virtual std::deque<SharedHandle<RequestGroup> >
|
||||
getNextRequestGroups(RequestGroup* requestGroup);
|
||||
virtual void
|
||||
getNextRequestGroups(std::deque<SharedHandle<RequestGroup> >& groups,
|
||||
RequestGroup* requestGroup);
|
||||
};
|
||||
|
||||
typedef SharedHandle<BtPostDownloadHandler> BtPostDownloadHandlerHandle;
|
||||
|
|
|
@ -98,28 +98,32 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
std::deque<SharedHandle<RequestGroup> >
|
||||
Metalink2RequestGroup::generate(const std::string& metalinkFile)
|
||||
void
|
||||
Metalink2RequestGroup::generate(std::deque<SharedHandle<RequestGroup> >& groups,
|
||||
const std::string& metalinkFile)
|
||||
{
|
||||
std::deque<SharedHandle<MetalinkEntry> > entries = MetalinkHelper::parseAndQuery(metalinkFile,
|
||||
_option);
|
||||
return createRequestGroup(entries);
|
||||
createRequestGroup(groups, entries);
|
||||
}
|
||||
|
||||
std::deque<SharedHandle<RequestGroup> >
|
||||
Metalink2RequestGroup::generate(const SharedHandle<BinaryStream>& binaryStream)
|
||||
void
|
||||
Metalink2RequestGroup::generate(std::deque<SharedHandle<RequestGroup> >& groups,
|
||||
const SharedHandle<BinaryStream>& binaryStream)
|
||||
{
|
||||
std::deque<SharedHandle<MetalinkEntry> > entries = MetalinkHelper::parseAndQuery(binaryStream,
|
||||
_option);
|
||||
return createRequestGroup(entries);
|
||||
createRequestGroup(groups, entries);
|
||||
}
|
||||
|
||||
std::deque<SharedHandle<RequestGroup> >
|
||||
Metalink2RequestGroup::createRequestGroup(std::deque<SharedHandle<MetalinkEntry> > entries)
|
||||
void
|
||||
Metalink2RequestGroup::createRequestGroup
|
||||
(std::deque<SharedHandle<RequestGroup> >& groups,
|
||||
std::deque<SharedHandle<MetalinkEntry> > entries)
|
||||
{
|
||||
if(entries.size() == 0) {
|
||||
_logger->notice(EX_NO_RESULT_WITH_YOUR_PREFS);
|
||||
return std::deque<SharedHandle<RequestGroup> >();
|
||||
return;
|
||||
}
|
||||
std::deque<int32_t> selectIndexes = Util::parseIntRange(_option->get(PREF_SELECT_FILE)).flush();
|
||||
bool useIndex;
|
||||
|
@ -128,7 +132,6 @@ Metalink2RequestGroup::createRequestGroup(std::deque<SharedHandle<MetalinkEntry>
|
|||
} else {
|
||||
useIndex = false;
|
||||
}
|
||||
std::deque<SharedHandle<RequestGroup> > groups;
|
||||
unsigned int count = 0;
|
||||
for(std::deque<SharedHandle<MetalinkEntry> >::iterator itr = entries.begin(); itr != entries.end();
|
||||
itr++, ++count) {
|
||||
|
@ -235,7 +238,6 @@ Metalink2RequestGroup::createRequestGroup(std::deque<SharedHandle<MetalinkEntry>
|
|||
#endif // ENABLE_BITTORRENT
|
||||
groups.push_back(rg);
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -54,16 +54,19 @@ private:
|
|||
|
||||
Logger* _logger;
|
||||
|
||||
std::deque<SharedHandle<RequestGroup> >
|
||||
createRequestGroup(std::deque<SharedHandle<MetalinkEntry> > entries);
|
||||
void
|
||||
createRequestGroup(std::deque<SharedHandle<RequestGroup> >& groups,
|
||||
std::deque<SharedHandle<MetalinkEntry> > entries);
|
||||
public:
|
||||
Metalink2RequestGroup(const Option* option);
|
||||
|
||||
~Metalink2RequestGroup();
|
||||
|
||||
std::deque<SharedHandle<RequestGroup> > generate(const std::string& metalinkFile);
|
||||
void generate(std::deque<SharedHandle<RequestGroup> >& groups,
|
||||
const std::string& metalinkFile);
|
||||
|
||||
std::deque<SharedHandle<RequestGroup> > generate(const SharedHandle<BinaryStream>& binaryStream);
|
||||
void generate(std::deque<SharedHandle<RequestGroup> >& groups,
|
||||
const SharedHandle<BinaryStream>& binaryStream);
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -54,8 +54,9 @@ MetalinkPostDownloadHandler::MetalinkPostDownloadHandler()
|
|||
|
||||
MetalinkPostDownloadHandler::~MetalinkPostDownloadHandler() {}
|
||||
|
||||
std::deque<SharedHandle<RequestGroup> >
|
||||
MetalinkPostDownloadHandler::getNextRequestGroups(RequestGroup* requestGroup)
|
||||
void MetalinkPostDownloadHandler::getNextRequestGroups
|
||||
(std::deque<SharedHandle<RequestGroup> >& 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> diskAdaptor = requestGroup->getPieceStorage()->getDiskAdaptor();
|
||||
try {
|
||||
diskAdaptor->openExistingFile();
|
||||
std::deque<SharedHandle<RequestGroup> > rgs = Metalink2RequestGroup(op).generate(diskAdaptor);
|
||||
Metalink2RequestGroup(op).generate(groups, diskAdaptor);
|
||||
diskAdaptor->closeFile();
|
||||
return rgs;
|
||||
} catch(Exception& e) {
|
||||
diskAdaptor->closeFile();
|
||||
throw;
|
||||
|
|
|
@ -46,8 +46,9 @@ public:
|
|||
|
||||
virtual ~MetalinkPostDownloadHandler();
|
||||
|
||||
virtual std::deque<SharedHandle<RequestGroup> >
|
||||
getNextRequestGroups(RequestGroup* requestGroup);
|
||||
virtual void
|
||||
getNextRequestGroups(std::deque<SharedHandle<RequestGroup> >& groups,
|
||||
RequestGroup* requestGroup);
|
||||
};
|
||||
|
||||
typedef SharedHandle<MetalinkPostDownloadHandler> MetalinkPostDownloadHandlerHandle;
|
||||
|
|
|
@ -46,8 +46,9 @@ public:
|
|||
|
||||
virtual ~PostDownloadHandler() {}
|
||||
|
||||
virtual std::deque<SharedHandle<RequestGroup> >
|
||||
getNextRequestGroups(RequestGroup* requestGroup) = 0;
|
||||
virtual void
|
||||
getNextRequestGroups(std::deque<SharedHandle<RequestGroup> >& groups,
|
||||
RequestGroup* requestGroup) = 0;
|
||||
};
|
||||
|
||||
typedef SharedHandle<PostDownloadHandler> PostDownloadHandlerHandle;
|
||||
|
|
|
@ -706,22 +706,22 @@ void RequestGroup::preDownloadProcessing()
|
|||
return;
|
||||
}
|
||||
|
||||
RequestGroups RequestGroup::postDownloadProcessing()
|
||||
void RequestGroup::postDownloadProcessing
|
||||
(std::deque<SharedHandle<RequestGroup> >& 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()
|
||||
|
|
|
@ -283,7 +283,7 @@ public:
|
|||
|
||||
void releaseRuntimeResource();
|
||||
|
||||
std::deque<SharedHandle<RequestGroup> > postDownloadProcessing();
|
||||
void postDownloadProcessing(std::deque<SharedHandle<RequestGroup> >& groups);
|
||||
|
||||
void addPostDownloadHandler(const SharedHandle<PostDownloadHandler>& handler);
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -190,7 +190,8 @@ int32_t downloadBitTorrent(Option* op, const std::deque<std::string>& 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<SharedHandle<RequestGroup> > 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.
|
||||
|
|
|
@ -71,7 +71,8 @@ void BtPostDownloadHandlerTest::testGetNextRequestGroups()
|
|||
rg.initPieceStorage();
|
||||
|
||||
BtPostDownloadHandler handler;
|
||||
std::deque<SharedHandle<RequestGroup> > groups = handler.getNextRequestGroups(&rg);
|
||||
std::deque<SharedHandle<RequestGroup> > groups;
|
||||
handler.getNextRequestGroups(groups, &rg);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, groups.size());
|
||||
SharedHandle<BtContext> btctx
|
||||
(dynamic_pointer_cast<BtContext>(groups.front()->getDownloadContext()));
|
||||
|
|
|
@ -32,8 +32,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION( Metalink2RequestGroupTest );
|
|||
|
||||
void Metalink2RequestGroupTest::testGenerate()
|
||||
{
|
||||
std::deque<SharedHandle<RequestGroup> > groups =
|
||||
Metalink2RequestGroup(_option.get()).generate("test.xml");
|
||||
std::deque<SharedHandle<RequestGroup> > groups;
|
||||
Metalink2RequestGroup(_option.get()).generate(groups, "test.xml");
|
||||
// first file
|
||||
{
|
||||
SharedHandle<RequestGroup> rg = groups[0];
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue