/* */ #include "FileAllocationCommand.h" #include "FileAllocationMan.h" #include "FileAllocationEntry.h" #include "DownloadEngine.h" #include "RequestGroup.h" #include "Logger.h" #include "LogFactory.h" #include "message.h" #include "prefs.h" #include "util.h" #include "DownloadEngine.h" #include "DownloadContext.h" #include "a2functional.h" #include "RecoverableException.h" #include "wallclock.h" #include "RequestGroupMan.h" #include "fmt.h" namespace aria2 { FileAllocationCommand::FileAllocationCommand (cuid_t cuid, RequestGroup* requestGroup, DownloadEngine* e, FileAllocationEntry* fileAllocationEntry) : RealtimeCommand{cuid, requestGroup, e}, fileAllocationEntry_{fileAllocationEntry} {} FileAllocationCommand::~FileAllocationCommand() { getDownloadEngine()->getFileAllocationMan()->dropPickedEntry(); } bool FileAllocationCommand::executeInternal() { if(getRequestGroup()->isHaltRequested()) { return true; } fileAllocationEntry_->allocateChunk(); if(fileAllocationEntry_->finished()) { A2_LOG_DEBUG (fmt(MSG_ALLOCATION_COMPLETED, static_cast(timer_.difference(global::wallclock())), getRequestGroup()->getTotalLength())); std::vector> commands; fileAllocationEntry_->prepareForNextAction(commands, getDownloadEngine()); getDownloadEngine()->addCommand(std::move(commands)); getDownloadEngine()->setNoWait(true); return true; } else { getDownloadEngine()->addCommand(std::unique_ptr(this)); return false; } } bool FileAllocationCommand::handleException(Exception& e) { A2_LOG_ERROR_EX(fmt(MSG_FILE_ALLOCATION_FAILURE, getCuid()), e); A2_LOG_ERROR (fmt(MSG_DOWNLOAD_NOT_COMPLETE, getCuid(), getRequestGroup()->getDownloadContext()->getBasePath().c_str())); return true; } } // namespace aria2