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)
pull/1/head
Tatsuhiro Tsujikawa 2007-09-03 10:32:19 +00:00
parent 57471aac9c
commit cf5cb05816
9 changed files with 276 additions and 11 deletions

View File

@ -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

8
TODO
View File

@ -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

47
src/AutoSaveCommand.cc Normal file
View File

@ -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();
}

53
src/AutoSaveCommand.h Normal file
View File

@ -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_

View File

@ -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;
}

View File

@ -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

View File

@ -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@

56
src/TimeBasedCommand.cc Normal file
View File

@ -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;
}

84
src/TimeBasedCommand.h Normal file
View File

@ -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_