/* */ #include "TimeBasedCommand.h" #include "DownloadEngine.h" #include "wallclock.h" namespace aria2 { TimeBasedCommand::TimeBasedCommand(cuid_t cuid, DownloadEngine* e, std::chrono::seconds interval, bool routineCommand) : Command(cuid), e_(e), checkPoint_(global::wallclock()), interval_(std::move(interval)), exit_(false), routineCommand_(routineCommand) { } TimeBasedCommand::~TimeBasedCommand() = default; 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