/* */ #ifndef _D_DOWNLOAD_ENGINE_H_ #define _D_DOWNLOAD_ENGINE_H_ #include "common.h" #include "a2netcompat.h" #include "Command.h" class SocketCore; typedef SharedHandle SocketHandle; typedef deque Sockets; class Logger; class Option; class NameResolver; typedef SharedHandle NameResolverHandle; class RequestGroupMan; typedef SharedHandle RequestGroupManHandle; class FileAllocationMan; typedef SharedHandle FileAllocationManHandle; class StatCalc; typedef SharedHandle StatCalcHandle; class CheckIntegrityMan; typedef SharedHandle CheckIntegrityManHandle; class SocketEntry { public: enum TYPE { TYPE_RD, TYPE_WR, }; SocketHandle socket; Command* command; TYPE type; public: SocketEntry(const SocketHandle& socket, Command* command, TYPE type); bool operator==(const SocketEntry& entry); }; typedef deque SocketEntries; #ifdef ENABLE_ASYNC_DNS class NameResolverEntry { public: NameResolverHandle nameResolver; Command* command; public: NameResolverEntry(const NameResolverHandle& nameResolver, Command* command); bool operator==(const NameResolverEntry& entry); }; typedef 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; StatCalcHandle _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; Commands commands; RequestGroupManHandle _requestGroupMan; FileAllocationManHandle _fileAllocationMan; CheckIntegrityManHandle _checkIntegrityMan; const Option* option; DownloadEngine(); virtual ~DownloadEngine(); void run(); void cleanQueue(); void updateFdSet(); bool addSocketForReadCheck(const SocketHandle& socket, Command* command); bool deleteSocketForReadCheck(const SocketHandle& socket, Command* command); bool addSocketForWriteCheck(const SocketHandle& socket, Command* command); bool deleteSocketForWriteCheck(const SocketHandle& socket, Command* command); #ifdef ENABLE_ASYNC_DNS bool addNameResolverCheck(const NameResolverHandle& resolver, Command* command); bool deleteNameResolverCheck(const NameResolverHandle& resolver, Command* command); #endif // ENABLE_ASYNC_DNS void addCommand(const Commands& commands); void fillCommand(); void setStatCalc(const StatCalcHandle& statCalc); bool isHaltRequested() const { return _haltRequested; } }; typedef SharedHandle DownloadEngineHandle; #endif // _D_DOWNLOAD_ENGINE_H_