2007-09-03 10:32:19 +00:00
|
|
|
/* <!-- 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
|
2010-01-05 16:01:46 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2007-09-03 10:32:19 +00:00
|
|
|
*
|
|
|
|
* 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"
|
2007-10-11 16:58:24 +00:00
|
|
|
#include "DownloadEngine.h"
|
2010-03-06 08:29:53 +00:00
|
|
|
#include "wallclock.h"
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
|
|
|
|
2010-03-20 14:30:36 +00:00
|
|
|
TimeBasedCommand::TimeBasedCommand(cuid_t cuid, DownloadEngine* e,
|
2010-01-05 16:01:46 +00:00
|
|
|
time_t interval,
|
|
|
|
bool routineCommand):
|
2010-06-21 13:51:56 +00:00
|
|
|
Command(cuid), e_(e),exit_(false), interval_(interval),
|
2011-08-09 16:17:28 +00:00
|
|
|
routineCommand_(routineCommand), checkPoint_(global::wallclock()) {}
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
TimeBasedCommand::~TimeBasedCommand() {}
|
2007-09-03 10:32:19 +00:00
|
|
|
|
|
|
|
bool TimeBasedCommand::execute()
|
|
|
|
{
|
|
|
|
preProcess();
|
2010-06-21 13:51:56 +00:00
|
|
|
if(exit_) {
|
2007-09-03 10:32:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-08-09 16:17:28 +00:00
|
|
|
if(checkPoint_.difference(global::wallclock()) >= interval_) {
|
|
|
|
checkPoint_ = global::wallclock();
|
2007-09-03 10:32:19 +00:00
|
|
|
process();
|
2010-06-21 13:51:56 +00:00
|
|
|
if(exit_) {
|
2007-09-03 10:32:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
postProcess();
|
2010-06-21 13:51:56 +00:00
|
|
|
if(exit_) {
|
2007-09-03 10:32:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
if(routineCommand_) {
|
2013-06-23 12:55:52 +00:00
|
|
|
e_->addRoutineCommand(std::unique_ptr<Command>(this));
|
2008-04-20 05:42:15 +00:00
|
|
|
} else {
|
2013-06-23 12:55:52 +00:00
|
|
|
e_->addCommand(std::unique_ptr<Command>(this));
|
2008-04-20 05:42:15 +00:00
|
|
|
}
|
2007-09-03 10:32:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
} // namespace aria2
|