/* */ #include "TimeBasedCommand.h" #include "DownloadEngine.h" #include "wallclock.h" namespace aria2 { TimeBasedCommand::TimeBasedCommand(cuid_t cuid, DownloadEngine* e, time_t interval, bool routineCommand) : Command(cuid), e_(e), checkPoint_(global::wallclock()), interval_(interval), exit_(false), routineCommand_(routineCommand) {} TimeBasedCommand::~TimeBasedCommand() {} bool TimeBasedCommand::execute() { preProcess(); if(exit_) { return true; } if(checkPoint_.difference(global::wallclock()) >= interval_) { checkPoint_ = global::wallclock(); process(); if(exit_) { return true; } } postProcess(); if(exit_) { return true; } if(routineCommand_) { e_->addRoutineCommand(std::unique_ptr(this)); } else { e_->addCommand(std::unique_ptr(this)); } return false; } } // namespace aria2