2006-08-07 16:05:00 +00:00
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
2006-09-21 15:31:24 +00:00
|
|
|
* aria2 - The high speed download utility
|
2006-08-07 16:05:00 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2006-09-21 15:31:24 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give
|
|
|
|
* permission to link the code of portions of this program with the
|
|
|
|
* OpenSSL library under certain conditions as described in each
|
|
|
|
* individual source file, and distribute linked combinations
|
|
|
|
* including the two.
|
|
|
|
* You must obey the GNU General Public License in all respects
|
|
|
|
* for all of the code used other than OpenSSL. If you modify
|
|
|
|
* file(s) with this exception, you may extend this exception to your
|
|
|
|
* version of the file(s), but you are not obligated to do so. If you
|
|
|
|
* do not wish to do so, delete this exception statement from your
|
|
|
|
* version. If you delete this exception statement from all source
|
|
|
|
* files in the program, then also delete it here.
|
2006-08-07 16:05:00 +00:00
|
|
|
*/
|
|
|
|
/* copyright --> */
|
|
|
|
#include "DownloadEngineFactory.h"
|
2007-10-11 16:58:24 +00:00
|
|
|
#include "LogFactory.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "Logger.h"
|
2007-10-11 16:58:24 +00:00
|
|
|
#include "Option.h"
|
|
|
|
#include "RequestGroup.h"
|
|
|
|
#include "DownloadEngine.h"
|
|
|
|
#include "RequestGroupMan.h"
|
|
|
|
#include "FileAllocationMan.h"
|
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
|
|
|
# include "CheckIntegrityMan.h"
|
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2006-08-07 16:05:00 +00:00
|
|
|
#include "prefs.h"
|
2007-05-20 13:51:52 +00:00
|
|
|
#include "CUIDCounter.h"
|
2007-10-11 16:58:24 +00:00
|
|
|
#include "FillRequestGroupCommand.h"
|
2007-05-20 13:51:52 +00:00
|
|
|
#include "FileAllocationDispatcherCommand.h"
|
2007-09-03 10:32:19 +00:00
|
|
|
#include "AutoSaveCommand.h"
|
2007-10-11 16:58:24 +00:00
|
|
|
#include "HaveEraseCommand.h"
|
2008-02-11 05:07:08 +00:00
|
|
|
#include "TimedHaltCommand.h"
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
#include "DownloadResult.h"
|
2008-02-08 18:39:26 +00:00
|
|
|
#include <algorithm>
|
2006-08-07 16:05:00 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
DownloadEngineFactory::DownloadEngineFactory():
|
|
|
|
_logger(LogFactory::getInstance()) {}
|
|
|
|
|
|
|
|
DownloadEngineHandle
|
|
|
|
DownloadEngineFactory::newDownloadEngine(Option* op,
|
|
|
|
const RequestGroups& requestGroups)
|
2007-05-20 13:51:52 +00:00
|
|
|
{
|
|
|
|
RequestGroups workingSet;
|
|
|
|
RequestGroups reservedSet;
|
2008-03-09 12:24:01 +00:00
|
|
|
if((size_t)op->getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS) < requestGroups.size()) {
|
2008-02-08 18:39:26 +00:00
|
|
|
std::copy(requestGroups.begin(), requestGroups.begin()+op->getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS), std::back_inserter(workingSet));
|
|
|
|
std::copy(requestGroups.begin()+op->getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS),
|
|
|
|
requestGroups.end(), std::back_inserter(reservedSet));
|
2007-05-20 13:51:52 +00:00
|
|
|
} else {
|
|
|
|
workingSet = requestGroups;
|
|
|
|
}
|
|
|
|
|
2008-04-20 00:50:22 +00:00
|
|
|
DownloadEngineHandle e(new DownloadEngine());
|
2007-05-20 13:51:52 +00:00
|
|
|
e->option = op;
|
2008-04-20 00:50:22 +00:00
|
|
|
RequestGroupManHandle
|
|
|
|
requestGroupMan(new RequestGroupMan(workingSet,
|
|
|
|
op->getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS)));
|
2007-05-20 13:51:52 +00:00
|
|
|
requestGroupMan->addReservedGroup(reservedSet);
|
|
|
|
e->_requestGroupMan = requestGroupMan;
|
2008-04-20 00:50:22 +00:00
|
|
|
e->_fileAllocationMan.reset(new FileAllocationMan());
|
2007-07-04 16:04:57 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2008-04-20 00:50:22 +00:00
|
|
|
e->_checkIntegrityMan.reset(new CheckIntegrityMan());
|
2007-07-04 16:04:57 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2007-10-11 16:58:24 +00:00
|
|
|
e->commands.push_back(new FillRequestGroupCommand(CUIDCounterSingletonHolder::instance()->newID(), e.get(), 1));
|
|
|
|
e->commands.push_back(new FileAllocationDispatcherCommand(CUIDCounterSingletonHolder::instance()->newID(), e.get()));
|
|
|
|
e->commands.push_back(new AutoSaveCommand(CUIDCounterSingletonHolder::instance()->newID(), e.get(), op->getAsInt(PREF_AUTO_SAVE_INTERVAL)));
|
|
|
|
e->commands.push_back(new HaveEraseCommand(CUIDCounterSingletonHolder::instance()->newID(), e.get(), 10));
|
2008-02-11 05:07:08 +00:00
|
|
|
{
|
2008-03-09 12:24:01 +00:00
|
|
|
time_t stopSec = op->getAsInt(PREF_STOP);
|
2008-02-20 12:33:16 +00:00
|
|
|
if(stopSec > 0) {
|
|
|
|
e->commands.push_back(new TimedHaltCommand(CUIDCounterSingletonHolder::instance()->newID(), e.get(), stopSec));
|
2008-02-11 05:07:08 +00:00
|
|
|
}
|
|
|
|
}
|
2007-10-11 16:58:24 +00:00
|
|
|
return e;
|
2006-08-07 16:05:00 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
} // namespace aria2
|