/* */ #ifndef D_RPC_METHOD_H #define D_RPC_METHOD_H #include "common.h" #include #include #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: std::shared_ptr 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 std::unique_ptr process(const RpcRequest& req, DownloadEngine* e) = 0; void gatherRequestOption(Option* option, const Dict* optionsDict); void gatherChangeableOption(Option* option, Option* pendingOption, const Dict* optionDict); void gatherChangeableOptionForReserved(Option* option, const Dict* optionsDict); void gatherChangeableGlobalOption(Option* option, const Dict* optionDict); std::unique_ptr createErrorResponse(const Exception& e, const RpcRequest& req); const std::shared_ptr& getOptionParser() const { return optionParser_; } public: RpcMethod(); virtual ~RpcMethod(); virtual void authorize(RpcRequest& req, DownloadEngine* e); // Do work to fulfill RpcRequest req and returns its result as // RpcResponse. This method delegates to process() method. virtual RpcResponse execute(RpcRequest req, DownloadEngine* e); }; } // namespace rpc } // namespace aria2 #endif // D_RPC_METHOD_H