/* */ #ifndef _D_DOWNLOAD_ENGINE_H_ #define _D_DOWNLOAD_ENGINE_H_ #include "common.h" #include "SharedHandle.h" #include "Command.h" #include #include namespace aria2 { class Logger; class Option; class NameResolver; class RequestGroupMan; class FileAllocationMan; class StatCalc; class CheckIntegrityMan; class SocketCore; class SocketEntry { public: enum TYPE { TYPE_RD, TYPE_WR, }; SharedHandle socket; Command* command; TYPE type; public: SocketEntry(const SharedHandle& socket, Command* command, TYPE type); bool operator==(const SocketEntry& entry); }; typedef std::deque SocketEntries; #ifdef ENABLE_ASYNC_DNS class NameResolverEntry { public: SharedHandle nameResolver; Command* command; public: NameResolverEntry(const SharedHandle& nameResolver, Command* command); bool operator==(const NameResolverEntry& entry); }; typedef std::deque NameResolverEntries; #endif // ENABLE_ASYNC_DNS class DownloadEngine { private: void waitData(); SocketEntries socketEntries; #ifdef ENABLE_ASYNC_DNS NameResolverEntries nameResolverEntries; #endif // ENABLE_ASYNC_DNS fd_set rfdset; fd_set wfdset; int32_t fdmax; const Logger* logger; SharedHandle _statCalc; bool _haltRequested; void shortSleep() const; bool addSocket(const SocketEntry& socketEntry); bool deleteSocket(const SocketEntry& socketEntry); void executeCommand(Command::STATUS statusFilter); /** * Delegates to StatCalc */ void calculateStatistics(); void onEndOfRun(); void afterEachIteration(); public: bool noWait; std::deque commands; SharedHandle _requestGroupMan; SharedHandle _fileAllocationMan; SharedHandle _checkIntegrityMan; const Option* option; DownloadEngine(); virtual ~DownloadEngine(); void run(); void cleanQueue(); void updateFdSet(); bool addSocketForReadCheck(const SharedHandle& socket, Command* command); bool deleteSocketForReadCheck(const SharedHandle& socket, Command* command); bool addSocketForWriteCheck(const SharedHandle& socket, Command* command); bool deleteSocketForWriteCheck(const SharedHandle& socket, Command* command); #ifdef ENABLE_ASYNC_DNS bool addNameResolverCheck(const SharedHandle& resolver, Command* command); bool deleteNameResolverCheck(const SharedHandle& resolver, Command* command); #endif // ENABLE_ASYNC_DNS void addCommand(const Commands& commands); void fillCommand(); void setStatCalc(const SharedHandle& statCalc); bool isHaltRequested() const { return _haltRequested; } void requestHalt(); }; typedef SharedHandle DownloadEngineHandle; } // namespace aria2 #endif // _D_DOWNLOAD_ENGINE_H_