diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2006-08-14 13:48:31 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2006-08-14 13:48:31 +0000 |
| commit | 2f14fec78dfc96b88a905621d35f1d726df0791d (patch) | |
| tree | 8eb4dc9cf94f021ccbdf77dca88924c2c9bf4cea /src/DownloadEngineFactory.cc | |
| parent | 43dae4fd916bb35bf7fd8554fc86ce34c3e7a31b (diff) | |
| parent | 7ca1b43eddd1aba1c71a38dfb46b5ac5685b43d0 (diff) | |
Tagging 0.7.0 release of aria2release-0.7.0
Diffstat (limited to 'src/DownloadEngineFactory.cc')
| -rw-r--r-- | src/DownloadEngineFactory.cc | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/src/DownloadEngineFactory.cc b/src/DownloadEngineFactory.cc new file mode 100644 index 00000000..52da662c --- /dev/null +++ b/src/DownloadEngineFactory.cc @@ -0,0 +1,123 @@ +/* <!-- copyright */ +/* + * aria2 - a simple utility for downloading files faster + * + * 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 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +/* copyright --> */ +#include "DownloadEngineFactory.h" +#include "prefs.h" +#include "DefaultDiskWriter.h" +#include "SplitSlowestSegmentSplitter.h" +#include "InitiateConnectionCommandFactory.h" +#include "ByteArrayDiskWriter.h" +#include "Util.h" +#ifdef ENABLE_BITTORRENT +# include "PeerListenCommand.h" +# include "TrackerWatcherCommand.h" +# include "TrackerUpdateCommand.h" +# include "TorrentAutoSaveCommand.h" +# include "PeerChokeCommand.h" +# include "HaveEraseCommand.h" +#endif // ENABLE_BITTORRENT + +ConsoleDownloadEngine* +DownloadEngineFactory::newConsoleEngine(const Option* op, + const Requests& requests, + const Requests& reserved) +{ + ConsoleDownloadEngine* e = new ConsoleDownloadEngine(); + e->option = op; + e->segmentMan = new SegmentMan(); + e->segmentMan->diskWriter = new DefaultDiskWriter(); + e->segmentMan->dir = op->get(PREF_DIR); + e->segmentMan->ufilename = op->get(PREF_OUT); + e->segmentMan->option = op; + e->segmentMan->splitter = new SplitSlowestSegmentSplitter(); + e->segmentMan->splitter->setMinSegmentSize(op->getAsLLInt(PREF_MIN_SEGMENT_SIZE)); + e->segmentMan->reserved = reserved; + + int cuidCounter = 1; + for(Requests::const_iterator itr = requests.begin(); + itr != requests.end(); + itr++, cuidCounter++) { + e->commands.push_back(InitiateConnectionCommandFactory::createInitiateConnectionCommand(cuidCounter, *itr, e)); + } + return e; +} + +#ifdef ENABLE_BITTORRENT +TorrentConsoleDownloadEngine* +DownloadEngineFactory::newTorrentConsoleEngine(const Option* op, + const string& torrentFile, + const Strings& targetFiles) +{ + Request* req = new Request(); + req->isTorrent = true; + req->setTrackerEvent(Request::STARTED); + TorrentConsoleDownloadEngine* te = new TorrentConsoleDownloadEngine(); + te->option = op; + ByteArrayDiskWriter* byteArrayDiskWriter = new ByteArrayDiskWriter(); + te->segmentMan = new SegmentMan(); + te->segmentMan->diskWriter = byteArrayDiskWriter; + te->segmentMan->option = op; + te->segmentMan->splitter = new SplitSlowestSegmentSplitter(); + te->segmentMan->splitter->setMinSegmentSize(op->getAsLLInt(PREF_MIN_SEGMENT_SIZE)); + te->torrentMan = new TorrentMan(); + te->torrentMan->setStoreDir(op->get(PREF_DIR)); + te->torrentMan->option = op; + te->torrentMan->req = req; + Integers selectIndexes; + Util::unfoldRange(op->get(PREF_SELECT_FILE), selectIndexes); + if(selectIndexes.size()) { + te->torrentMan->setup(torrentFile, selectIndexes); + } else { + te->torrentMan->setup(torrentFile, targetFiles); + } + + PeerListenCommand* listenCommand = + new PeerListenCommand(te->torrentMan->getNewCuid(), te); + int port; + int listenPort = op->getAsInt(PREF_LISTEN_PORT); + if(listenPort == -1) { + port = listenCommand->bindPort(6881, 6999); + } else { + port = listenCommand->bindPort(listenPort, listenPort); + } + if(port == -1) { + printf(_("Errors occurred while binding port.\n")); + exit(EXIT_FAILURE); + } + te->torrentMan->setPort(port); + te->commands.push_back(listenCommand); + + te->commands.push_back(new TrackerWatcherCommand(te->torrentMan->getNewCuid(), + te, + te->torrentMan->minInterval)); + te->commands.push_back(new TrackerUpdateCommand(te->torrentMan->getNewCuid(), + te)); + te->commands.push_back(new TorrentAutoSaveCommand(te->torrentMan->getNewCuid(), + te, + op->getAsInt(PREF_AUTO_SAVE_INTERVAL))); + te->commands.push_back(new PeerChokeCommand(te->torrentMan->getNewCuid(), + te, 10)); + te->commands.push_back(new HaveEraseCommand(te->torrentMan->getNewCuid(), + te, 10)); + + return te; +} +#endif // ENABLE_BITTORRENT |
