/* */ #ifndef D_SEQUENTIAL_DISPATCHER_COMMAND_H #define D_SEQUENTIAL_DISPATCHER_COMMAND_H #include "Command.h" #include #include "SequentialPicker.h" #include "DownloadEngine.h" #include "RequestGroupMan.h" namespace aria2 { class DownloadEngine; template class SequentialDispatcherCommand : public Command { private: SequentialPicker* picker_; DownloadEngine* e_; protected: DownloadEngine* getDownloadEngine() const { return e_; } public: SequentialDispatcherCommand(cuid_t cuid, SequentialPicker* picker, DownloadEngine* e) : Command{cuid}, picker_{picker}, e_{e} { setStatusRealtime(); } virtual bool execute() CXX11_OVERRIDE { if (e_->getRequestGroupMan()->downloadFinished() || e_->isHaltRequested()) { return true; } if (picker_->hasNext() && !picker_->isPicked()) { e_->addCommand(createCommand(picker_->pickNext())); e_->setNoWait(true); } e_->addRoutineCommand(std::unique_ptr(this)); return false; } protected: virtual std::unique_ptr createCommand(T* entry) = 0; }; } // namespace aria2 #endif // D_SEQUENTIAL_DISPATCHER_COMMAND_H