/* */ #include "RpcMethodFactory.h" #include "RpcMethodImpl.h" #include "OptionParser.h" #include "OptionHandler.h" namespace aria2 { namespace rpc { namespace { std::map> cache; } // namespace namespace { std::unique_ptr noSuchRpcMethod; } // namespace namespace { std::unique_ptr createMethod(const std::string& methodName) { if (methodName == AddUriRpcMethod::getMethodName()) { return make_unique(); } #ifdef ENABLE_BITTORRENT if (methodName == AddTorrentRpcMethod::getMethodName()) { return make_unique(); } if (methodName == GetPeersRpcMethod::getMethodName()) { return make_unique(); } #endif // ENABLE_BITTORRENT #ifdef ENABLE_METALINK if (methodName == AddMetalinkRpcMethod::getMethodName()) { return make_unique(); } #endif // ENABLE_METALINK if (methodName == RemoveRpcMethod::getMethodName()) { return make_unique(); } if (methodName == PauseRpcMethod::getMethodName()) { return make_unique(); } if (methodName == ForcePauseRpcMethod::getMethodName()) { return make_unique(); } if (methodName == PauseAllRpcMethod::getMethodName()) { return make_unique(); } if (methodName == ForcePauseAllRpcMethod::getMethodName()) { return make_unique(); } if (methodName == UnpauseRpcMethod::getMethodName()) { return make_unique(); } if (methodName == UnpauseAllRpcMethod::getMethodName()) { return make_unique(); } if (methodName == ForceRemoveRpcMethod::getMethodName()) { return make_unique(); } if (methodName == ChangePositionRpcMethod::getMethodName()) { return make_unique(); } if (methodName == TellStatusRpcMethod::getMethodName()) { return make_unique(); } if (methodName == GetUrisRpcMethod::getMethodName()) { return make_unique(); } if (methodName == GetFilesRpcMethod::getMethodName()) { return make_unique(); } if (methodName == GetServersRpcMethod::getMethodName()) { return make_unique(); } if (methodName == TellActiveRpcMethod::getMethodName()) { return make_unique(); } if (methodName == TellWaitingRpcMethod::getMethodName()) { return make_unique(); } if (methodName == TellStoppedRpcMethod::getMethodName()) { return make_unique(); } if (methodName == GetOptionRpcMethod::getMethodName()) { return make_unique(); } if (methodName == ChangeUriRpcMethod::getMethodName()) { return make_unique(); } if (methodName == ChangeOptionRpcMethod::getMethodName()) { return make_unique(); } if (methodName == GetGlobalOptionRpcMethod::getMethodName()) { return make_unique(); } if (methodName == ChangeGlobalOptionRpcMethod::getMethodName()) { return make_unique(); } if (methodName == PurgeDownloadResultRpcMethod::getMethodName()) { return make_unique(); } if (methodName == RemoveDownloadResultRpcMethod::getMethodName()) { return make_unique(); } if (methodName == GetVersionRpcMethod::getMethodName()) { return make_unique(); } if (methodName == GetSessionInfoRpcMethod::getMethodName()) { return make_unique(); } if (methodName == ShutdownRpcMethod::getMethodName()) { return make_unique(); } if (methodName == ForceShutdownRpcMethod::getMethodName()) { return make_unique(); } if (methodName == GetGlobalStatRpcMethod::getMethodName()) { return make_unique(); } if (methodName == SaveSessionRpcMethod::getMethodName()) { return make_unique(); } if (methodName == SystemMulticallRpcMethod::getMethodName()) { return make_unique(); } return nullptr; } } // namespace RpcMethod* getMethod(const std::string& methodName) { auto itr = cache.find(methodName); if (itr == std::end(cache)) { auto m = createMethod(methodName); if (m) { auto rv = cache.insert(std::make_pair(methodName, std::move(m))); return (*rv.first).second.get(); } if (!noSuchRpcMethod) { noSuchRpcMethod = make_unique(); } return noSuchRpcMethod.get(); } return (*itr).second.get(); } } // namespace rpc } // namespace aria2