summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-09-03 10:32:19 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-09-03 10:32:19 +0000
commitcf5cb05816fd25b43b271c6175494f6b976ba7bc (patch)
treed14b18bcead2c0434c6189f71bee5e93e97c352a
parent57471aac9c81eb297da2b2bf286cec4865df0e94 (diff)
2007-09-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Automatically save *.aria2 control file of http/ftp download in every 60 seconds. * src/AutoSaveCommand.{h, cc}: New class. * src/TimeBasedCommand.{h, cc}: New class. * src/DownloadEngineFactory.cc (newConsoleEngine)
-rw-r--r--ChangeLog8
-rw-r--r--TODO8
-rw-r--r--src/AutoSaveCommand.cc47
-rw-r--r--src/AutoSaveCommand.h53
-rw-r--r--src/DownloadEngineFactory.cc2
-rw-r--r--src/Makefile.am4
-rw-r--r--src/Makefile.in25
-rw-r--r--src/TimeBasedCommand.cc56
-rw-r--r--src/TimeBasedCommand.h84
9 files changed, 276 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 6654c83a..6c0ec18b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-09-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
+
+ Automatically save *.aria2 control file of http/ftp download in every
+ 60 seconds.
+ * src/AutoSaveCommand.{h, cc}: New class.
+ * src/TimeBasedCommand.{h, cc}: New class.
+ * src/DownloadEngineFactory.cc (newConsoleEngine)
+
2007-09-02 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Now *.aria2 contorol file is first saved to *.aria2__temp and if
diff --git a/TODO b/TODO
index f2a7cbf0..eed20372 100644
--- a/TODO
+++ b/TODO
@@ -39,4 +39,12 @@
* used globally -> common.h
* Add pgp verification support. I have to use libgpgme??
+
+* Rewrite following classes using TimeBasedCommand
+ src/ActivePeerConnectionCommand.h
+ src/FillRequestGroupCommand.h
+ src/HaveEraseCommand.h
+ src/PeerChokeCommand.h
+ src/TorrentAutoSaveCommand.h
* Rewrite MetaFileUtil
+* Integrate FTP/HTTP/BitTorrent downloads from metalinks
diff --git a/src/AutoSaveCommand.cc b/src/AutoSaveCommand.cc
new file mode 100644
index 00000000..a894ac7e
--- /dev/null
+++ b/src/AutoSaveCommand.cc
@@ -0,0 +1,47 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * 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., 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 --> */
+#include "AutoSaveCommand.h"
+
+void AutoSaveCommand::preProcess()
+{
+ if(_e->_requestGroupMan->downloadFinished()) {
+ _exit = true;
+ }
+}
+
+void AutoSaveCommand::process()
+{
+ _e->_requestGroupMan->save();
+}
diff --git a/src/AutoSaveCommand.h b/src/AutoSaveCommand.h
new file mode 100644
index 00000000..6a1f23ff
--- /dev/null
+++ b/src/AutoSaveCommand.h
@@ -0,0 +1,53 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * 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., 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_AUTO_SAVE_COMMAND_H_
+#define _D_AUTO_SAVE_COMMAND_H_
+
+#include "TimeBasedCommand.h"
+
+class AutoSaveCommand : public TimeBasedCommand
+{
+public:
+ AutoSaveCommand(int32_t cuid, DownloadEngine* e, int32_t interval):
+ TimeBasedCommand(cuid, e, interval) {}
+
+ virtual ~AutoSaveCommand() {}
+
+ virtual void preProcess();
+
+ virtual void process();
+};
+
+#endif // _D_AUTO_SAVE_COMMAND_H_
diff --git a/src/DownloadEngineFactory.cc b/src/DownloadEngineFactory.cc
index eb3ea985..2c8f5b24 100644
--- a/src/DownloadEngineFactory.cc
+++ b/src/DownloadEngineFactory.cc
@@ -43,6 +43,7 @@
#include "CUIDCounter.h"
#include "FileAllocationDispatcherCommand.h"
#include "FileAllocationMan.h"
+#include "AutoSaveCommand.h"
#ifdef ENABLE_MESSAGE_DIGEST
# include "CheckIntegrityMan.h"
#endif // ENABLE_MESSAGE_DIGEST
@@ -94,6 +95,7 @@ DownloadEngineFactory::newConsoleEngine(const Option* op,
#endif // ENABLE_MESSAGE_DIGEST
e->commands.push_back(new FillRequestGroupCommand(CUIDCounterSingletonHolder::instance()->newID(), e, 1));
e->commands.push_back(new FileAllocationDispatcherCommand(CUIDCounterSingletonHolder::instance()->newID(), e));
+ e->commands.push_back(new AutoSaveCommand(CUIDCounterSingletonHolder::instance()->newID(), e, op->getAsInt(PREF_AUTO_SAVE_INTERVAL)));
return e;
}
diff --git a/src/Makefile.am b/src/Makefile.am
index 697b4af4..39441014 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -108,7 +108,9 @@ SRCS = Socket.h\
ParameterizedStringParser.cc ParameterizedStringParser.h\
FixedWidthNumberDecorator.h\
NumberDecorator.h\
- AlphaNumberDecorator.h
+ AlphaNumberDecorator.h\
+ TimeBasedCommand.cc TimeBasedCommand.h\
+ AutoSaveCommand.cc AutoSaveCommand.h
# debug_new.cpp
if ENABLE_MESSAGE_DIGEST
diff --git a/src/Makefile.in b/src/Makefile.in
index cba6ff5d..92fbf514 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -261,7 +261,8 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
PStringBuildVisitor.cc PStringBuildVisitor.h \
ParameterizedStringParser.cc ParameterizedStringParser.h \
FixedWidthNumberDecorator.h NumberDecorator.h \
- AlphaNumberDecorator.h ChunkChecksumValidator.cc \
+ AlphaNumberDecorator.h TimeBasedCommand.cc TimeBasedCommand.h \
+ AutoSaveCommand.cc AutoSaveCommand.h ChunkChecksumValidator.cc \
ChunkChecksumValidator.h IteratableChunkChecksumValidator.cc \
IteratableChunkChecksumValidator.h \
IteratableChecksumValidator.cc IteratableChecksumValidator.h \
@@ -471,11 +472,11 @@ am__objects_12 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
CookieBoxFactory.$(OBJEXT) HttpHeaderProcessor.$(OBJEXT) \
FileEntry.$(OBJEXT) Platform.$(OBJEXT) \
PStringSegment.$(OBJEXT) PStringBuildVisitor.$(OBJEXT) \
- ParameterizedStringParser.$(OBJEXT) $(am__objects_1) \
- $(am__objects_2) $(am__objects_3) $(am__objects_4) \
- $(am__objects_5) $(am__objects_6) $(am__objects_7) \
- $(am__objects_8) $(am__objects_9) $(am__objects_10) \
- $(am__objects_11)
+ ParameterizedStringParser.$(OBJEXT) TimeBasedCommand.$(OBJEXT) \
+ AutoSaveCommand.$(OBJEXT) $(am__objects_1) $(am__objects_2) \
+ $(am__objects_3) $(am__objects_4) $(am__objects_5) \
+ $(am__objects_6) $(am__objects_7) $(am__objects_8) \
+ $(am__objects_9) $(am__objects_10) $(am__objects_11)
am_libaria2c_a_OBJECTS = $(am__objects_12)
libaria2c_a_OBJECTS = $(am_libaria2c_a_OBJECTS)
am__installdirs = "$(DESTDIR)$(bindir)"
@@ -733,10 +734,12 @@ SRCS = Socket.h SocketCore.cc SocketCore.h Command.cc Command.h \
PStringBuildVisitor.cc PStringBuildVisitor.h \
ParameterizedStringParser.cc ParameterizedStringParser.h \
FixedWidthNumberDecorator.h NumberDecorator.h \
- AlphaNumberDecorator.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)
+ AlphaNumberDecorator.h TimeBasedCommand.cc TimeBasedCommand.h \
+ AutoSaveCommand.cc AutoSaveCommand.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)
noinst_LIBRARIES = libaria2c.a
libaria2c_a_SOURCES = $(SRCS)
aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@ @LIBGNUTLS_LIBS@\
@@ -832,6 +835,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ActivePeerConnectionCommand.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AnnounceList.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AuthConfig.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AutoSaveCommand.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Base64.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BitfieldMan.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BitfieldManFactory.Po@am__quote@
@@ -970,6 +974,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SocketCore.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SpeedCalc.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TimeA2.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TimeBasedCommand.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TorrentAutoSaveCommand.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TorrentConsoleDownloadEngine.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TorrentDownloadEngine.Po@am__quote@
diff --git a/src/TimeBasedCommand.cc b/src/TimeBasedCommand.cc
new file mode 100644
index 00000000..1803a38e
--- /dev/null
+++ b/src/TimeBasedCommand.cc
@@ -0,0 +1,56 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * 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., 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 --> */
+#include "TimeBasedCommand.h"
+
+bool TimeBasedCommand::execute()
+{
+ preProcess();
+ if(_exit) {
+ return true;
+ }
+ if(_checkPoint.elapsed(_interval)) {
+ _checkPoint.reset();
+ process();
+ if(_exit) {
+ return true;
+ }
+ }
+ postProcess();
+ if(_exit) {
+ return true;
+ }
+ _e->commands.push_back(this);
+ return false;
+}
diff --git a/src/TimeBasedCommand.h b/src/TimeBasedCommand.h
new file mode 100644
index 00000000..f23353f6
--- /dev/null
+++ b/src/TimeBasedCommand.h
@@ -0,0 +1,84 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * 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., 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_TIME_BASED_COMMAND_H_
+#define _D_TIME_BASED_COMMAND_H_
+
+#include "Command.h"
+#include "TimeA2.h"
+#include "DownloadEngine.h"
+
+class TimeBasedCommand : public Command
+{
+protected:
+ DownloadEngine* _e;
+
+ /**
+ * setting _exit to true if this command's job has finished and you want to
+ * delete this command.
+ * The _exit variable is evaluated after preProcess(), process(),
+ * postProcess(), and terminate processing immediately and excute() returns
+ * true.
+ */
+ bool _exit;
+private:
+ int32_t _interval; // unit: sec
+ Time _checkPoint;
+public:
+ /**
+ * preProcess() is called each time when excute() is called.
+ */
+ virtual void preProcess() {};
+
+ /**
+ * process() is called only when excute() is called and specified time has
+ * elapsed.
+ */
+ virtual void process() = 0;
+
+ /**
+ * postProcess() is called each time when excute() is called.
+ */
+ virtual void postProcess() {};
+
+public:
+ TimeBasedCommand(int32_t cuid, DownloadEngine* e, int32_t interval):
+ Command(cuid), _e(e),_exit(false), _interval(interval) {}
+
+ virtual ~TimeBasedCommand() {}
+
+ virtual bool execute();
+};
+
+#endif // _D_TIME_BASED_COMMAND_H_