summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2009-01-24 09:49:37 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2009-01-24 09:49:37 +0000
commita20aa3c7e544c0fc32fb1d8a5f04b24cfd026267 (patch)
tree6dd27346a525c639e02d27a7d27ec8012d1cb107 /src
parent8ca9db9f3ee007d40b85339f81a39ea3c1a22616 (diff)
2009-01-24 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Rewritten FileAllocationDispatcherCommand using brand new SequentialDispatcherCommand. * src/DownloadEngineFactory.cc * src/FileAllocationCommand.cc * src/FileAllocationDispatcherCommand.cc * src/FileAllocationDispatcherCommand.h * src/Makefile.am * src/SequentialDispatcherCommand.h
Diffstat (limited to 'src')
-rw-r--r--src/DownloadEngineFactory.cc4
-rw-r--r--src/FileAllocationCommand.cc1
-rw-r--r--src/FileAllocationDispatcherCommand.cc39
-rw-r--r--src/FileAllocationDispatcherCommand.h22
-rw-r--r--src/Makefile.am3
-rw-r--r--src/Makefile.in21
-rw-r--r--src/SequentialDispatcherCommand.h81
7 files changed, 121 insertions, 50 deletions
diff --git a/src/DownloadEngineFactory.cc b/src/DownloadEngineFactory.cc
index a8b826a9..206e9e06 100644
--- a/src/DownloadEngineFactory.cc
+++ b/src/DownloadEngineFactory.cc
@@ -116,8 +116,8 @@ DownloadEngineFactory::newDownloadEngine(Option* op,
e->_checkIntegrityMan.reset(new CheckIntegrityMan());
#endif // ENABLE_MESSAGE_DIGEST
e->addRoutineCommand(new FillRequestGroupCommand(e->newCUID(), e.get(), 1));
- e->addRoutineCommand(new FileAllocationDispatcherCommand(e->newCUID(),
- e.get()));
+ e->addRoutineCommand(new FileAllocationDispatcherCommand
+ (e->newCUID(), e->_fileAllocationMan, e.get()));
if(op->getAsInt(PREF_AUTO_SAVE_INTERVAL) > 0) {
e->addRoutineCommand
(new AutoSaveCommand(e->newCUID(), e.get(),
diff --git a/src/FileAllocationCommand.cc b/src/FileAllocationCommand.cc
index 5f39c52c..db4967a2 100644
--- a/src/FileAllocationCommand.cc
+++ b/src/FileAllocationCommand.cc
@@ -41,6 +41,7 @@
#include "message.h"
#include "prefs.h"
#include "Util.h"
+#include "DownloadEngine.h"
namespace aria2 {
diff --git a/src/FileAllocationDispatcherCommand.cc b/src/FileAllocationDispatcherCommand.cc
index b6ee18fa..5e5e996c 100644
--- a/src/FileAllocationDispatcherCommand.cc
+++ b/src/FileAllocationDispatcherCommand.cc
@@ -33,9 +33,6 @@
*/
/* copyright --> */
#include "FileAllocationDispatcherCommand.h"
-#include "DownloadEngine.h"
-#include "RequestGroupMan.h"
-#include "FileAllocationMan.h"
#include "FileAllocationEntry.h"
#include "FileAllocationCommand.h"
#include "message.h"
@@ -43,35 +40,23 @@
namespace aria2 {
-FileAllocationDispatcherCommand::FileAllocationDispatcherCommand(int32_t cuid, DownloadEngine* e):
- Command(cuid), _e(e)
+FileAllocationDispatcherCommand::FileAllocationDispatcherCommand
+(int32_t cuid,
+ const SharedHandle<FileAllocationMan>& fileAllocMan,
+ DownloadEngine* e):SequentialDispatcherCommand<FileAllocationEntry>
+ (cuid, fileAllocMan, e)
{
setStatusRealtime();
}
-FileAllocationDispatcherCommand::~FileAllocationDispatcherCommand() {}
-
-bool FileAllocationDispatcherCommand::execute()
+Command* FileAllocationDispatcherCommand::createCommand
+(const SharedHandle<FileAllocationEntry>& entry)
{
- if(_e->_requestGroupMan->downloadFinished() || _e->isHaltRequested()) {
- return true;
- }
- if(_e->_fileAllocationMan->hasNext() && !_e->_fileAllocationMan->isPicked()) {
- FileAllocationEntryHandle entry = _e->_fileAllocationMan->pickNext();
- int32_t newCUID = _e->newCUID();
- logger->info(MSG_FILE_ALLOCATION_DISPATCH, newCUID);
- FileAllocationCommand* command =
- new FileAllocationCommand(newCUID,
- entry->getRequestGroup(),
- _e,
- entry);
- _e->commands.push_back(command);
- _e->setNoWait(true);
- }
-
- _e->addRoutineCommand(this);
-
- return false;
+ int32_t newCUID = _e->newCUID();
+ logger->info(MSG_FILE_ALLOCATION_DISPATCH, newCUID);
+ FileAllocationCommand* command =
+ new FileAllocationCommand(newCUID, entry->getRequestGroup(), _e, entry);
+ return command;
}
} // namespace aria2
diff --git a/src/FileAllocationDispatcherCommand.h b/src/FileAllocationDispatcherCommand.h
index f45cd2f5..beba1504 100644
--- a/src/FileAllocationDispatcherCommand.h
+++ b/src/FileAllocationDispatcherCommand.h
@@ -35,21 +35,23 @@
#ifndef _D_FILE_ALLOCATION_DISPATCHER_COMMAND_H_
#define _D_FILE_ALLOCATION_DISPATCHER_COMMAND_H_
-#include "Command.h"
+#include "SequentialDispatcherCommand.h"
+#include "FileAllocationMan.h"
namespace aria2 {
-class DownloadEngine;
+class FileAllocationEntry;
-class FileAllocationDispatcherCommand : public Command {
-private:
- DownloadEngine* _e;
+class FileAllocationDispatcherCommand :
+ public SequentialDispatcherCommand<FileAllocationEntry> {
public:
- FileAllocationDispatcherCommand(int32_t cuid, DownloadEngine* e);
-
- virtual ~FileAllocationDispatcherCommand();
-
- virtual bool execute();
+ FileAllocationDispatcherCommand
+ (int32_t cuid,
+ const SharedHandle<FileAllocationMan>& fileAllocMan,
+ DownloadEngine* e);
+protected:
+ virtual Command* createCommand
+ (const SharedHandle<FileAllocationEntry>& entry);
};
} // namespace aria2
diff --git a/src/Makefile.am b/src/Makefile.am
index ea2abc18..073c670b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -199,7 +199,8 @@ SRCS = Socket.h\
URIResult.cc URIResult.h\
EventPoll.h\
SelectEventPoll.cc SelectEventPoll.h\
- SequentialPicker.h
+ SequentialPicker.h\
+ SequentialDispatcherCommand.h
if HAVE_EPOLL
SRCS += EpollEventPoll.cc EpollEventPoll.h
diff --git a/src/Makefile.in b/src/Makefile.in
index 6050c4ad..3a215eaa 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -413,8 +413,9 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
SocketBuffer.h OptionHandlerException.cc \
OptionHandlerException.h bencode.cc bencode.h URIResult.cc \
URIResult.h EventPoll.h SelectEventPoll.cc SelectEventPoll.h \
- SequentialPicker.h EpollEventPoll.cc EpollEventPoll.h \
- TLSContext.h LibgnutlsTLSContext.cc LibgnutlsTLSContext.h \
+ SequentialPicker.h SequentialDispatcherCommand.h \
+ EpollEventPoll.cc EpollEventPoll.h TLSContext.h \
+ LibgnutlsTLSContext.cc LibgnutlsTLSContext.h \
LibsslTLSContext.cc LibsslTLSContext.h GZipDecoder.cc \
GZipDecoder.h Sqlite3MozCookieParser.cc \
Sqlite3MozCookieParser.h AsyncNameResolver.cc \
@@ -1139,14 +1140,14 @@ SRCS = Socket.h SocketCore.cc SocketCore.h BinaryStream.h Command.cc \
SocketBuffer.h OptionHandlerException.cc \
OptionHandlerException.h bencode.cc bencode.h URIResult.cc \
URIResult.h EventPoll.h SelectEventPoll.cc SelectEventPoll.h \
- SequentialPicker.h $(am__append_1) $(am__append_2) \
- $(am__append_3) $(am__append_4) $(am__append_5) \
- $(am__append_6) $(am__append_7) $(am__append_8) \
- $(am__append_9) $(am__append_10) $(am__append_11) \
- $(am__append_12) $(am__append_13) $(am__append_14) \
- $(am__append_15) $(am__append_16) $(am__append_17) \
- $(am__append_18) $(am__append_19) $(am__append_20) \
- $(am__append_21)
+ SequentialPicker.h SequentialDispatcherCommand.h \
+ $(am__append_1) $(am__append_2) $(am__append_3) \
+ $(am__append_4) $(am__append_5) $(am__append_6) \
+ $(am__append_7) $(am__append_8) $(am__append_9) \
+ $(am__append_10) $(am__append_11) $(am__append_12) \
+ $(am__append_13) $(am__append_14) $(am__append_15) \
+ $(am__append_16) $(am__append_17) $(am__append_18) \
+ $(am__append_19) $(am__append_20) $(am__append_21)
noinst_LIBRARIES = libaria2c.a
libaria2c_a_SOURCES = $(SRCS)
aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@ @LIBGNUTLS_LIBS@\
diff --git a/src/SequentialDispatcherCommand.h b/src/SequentialDispatcherCommand.h
new file mode 100644
index 00000000..6fad70ca
--- /dev/null
+++ b/src/SequentialDispatcherCommand.h
@@ -0,0 +1,81 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2009 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., 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.
+ */
+/* copyright --> */
+#ifndef _D_SEQUENTIAL_DISPATCHER_COMMAND_H_
+#define _D_SEQUENTIAL_DISPATCHER_COMMAND_H_
+
+#include "Command.h"
+#include "SharedHandle.h"
+#include "SequentialPicker.h"
+#include "DownloadEngine.h"
+#include "RequestGroupMan.h"
+
+namespace aria2 {
+
+class DownloadEngine;
+
+template<typename T>
+class SequentialDispatcherCommand : public Command {
+protected:
+ SharedHandle<SequentialPicker<T> > _picker;
+
+ DownloadEngine* _e;
+public:
+ SequentialDispatcherCommand(int32_t cuid,
+ const SharedHandle<SequentialPicker<T> >& picker,
+ DownloadEngine* e):
+ Command(cuid), _picker(picker), _e(e) {}
+
+ virtual bool execute()
+ {
+ if(_e->_requestGroupMan->downloadFinished() || _e->isHaltRequested()) {
+ return true;
+ }
+ if(_picker->hasNext() && !_picker->isPicked()) {
+ _e->commands.push_back(createCommand(_picker->pickNext()));
+
+ _e->setNoWait(true);
+ }
+
+ _e->addRoutineCommand(this);
+ return false;
+ }
+
+protected:
+ virtual Command* createCommand(const SharedHandle<T>& entry) = 0;
+};
+
+} // namespace aria2
+
+#endif // _D_SEQUENTIAL_DISPATCHER_COMMAND_H_