/* */ #ifndef D_RPC_METHOD_H #define D_RPC_METHOD_H #include "common.h" #include #include "SharedHandle.h" #include "ValueBase.h" namespace aria2 { class DownloadEngine; class OptionParser; class Option; class Exception; namespace rpc { struct RpcRequest; struct RpcResponse; // This class offers abstract implementation of processing RPC // request. You have to inherit this class and implement process() // method to add new RPC API. The derived class must be stateless // since we reuse the instances. // // There is RpcMethodFactory class which instantiates RpcMethod // subclass. If you add new RpcMethod subclass, don't forget to add it // to RpcMethodFactory. class RpcMethod { private: SharedHandle optionParser_; protected: // Subclass must implement this function to fulfil RpcRequest req. // The return value of this method is used as a return value of RPC // request. virtual SharedHandle process (const RpcRequest& req, DownloadEngine* e) = 0; void gatherRequestOption(Option* option, const Dict* optionsDict); void gatherChangeableOption(Option* option, const Dict* optionDict); void gatherChangeableOptionForReserved (Option* option, const Dict* optionsDict); void gatherChangeableGlobalOption(Option* option, const Dict* optionDict); SharedHandle createErrorResponse (const Exception& e, const RpcRequest& req); const SharedHandle& getOptionParser() const { return optionParser_; } public: RpcMethod(); virtual ~RpcMethod(); // Do work to fulfill RpcRequest req and returns its result as // RpcResponse. This method delegates to process() method. RpcResponse execute(const RpcRequest& req, DownloadEngine* e); }; } // namespace rpc } // namespace aria2 #endif // D_RPC_METHOD_H