/* */ #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, const SharedHandle& fileAllocationEntry): RealtimeCommand(cuid, requestGroup, e), fileAllocationEntry_(fileAllocationEntry) {} FileAllocationCommand::~FileAllocationCommand() {} bool FileAllocationCommand::executeInternal() { if(getRequestGroup()->isHaltRequested()) { getDownloadEngine()->getFileAllocationMan()->dropPickedEntry(); return true; } fileAllocationEntry_->allocateChunk(); if(fileAllocationEntry_->finished()) { A2_LOG_DEBUG (fmt(MSG_ALLOCATION_COMPLETED, static_cast(timer_.difference(global::wallclock())), util::itos(getRequestGroup()->getTotalLength(), true).c_str())); getDownloadEngine()->getFileAllocationMan()->dropPickedEntry(); std::vector* commands = new std::vector(); auto_delete_container > commandsDel(commands); fileAllocationEntry_->prepareForNextAction(*commands, getDownloadEngine()); getDownloadEngine()->addCommand(*commands); commands->clear(); getDownloadEngine()->setNoWait(true); return true; } else { getDownloadEngine()->addCommand(this); return false; } } bool FileAllocationCommand::handleException(Exception& e) { getDownloadEngine()->getFileAllocationMan()->dropPickedEntry(); 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