/* */ #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::vector rpcMethodNames = { "aria2.addUri", #ifdef ENABLE_BITTORRENT "aria2.addTorrent", "aria2.getPeers", #endif // ENABLE_BITTORRENT #ifdef ENABLE_METALINK "aria2.addMetalink", #endif // ENABLE_METALINK "aria2.remove", "aria2.pause", "aria2.forcePause", "aria2.pauseAll", "aria2.forcePauseAll", "aria2.unpause", "aria2.unpauseAll", "aria2.forceRemove", "aria2.changePosition", "aria2.tellStatus", "aria2.getUris", "aria2.getFiles", "aria2.getServers", "aria2.tellActive", "aria2.tellWaiting", "aria2.tellStopped", "aria2.getOption", "aria2.changeUri", "aria2.changeOption", "aria2.getGlobalOption", "aria2.changeGlobalOption", "aria2.purgeDownloadResult", "aria2.removeDownloadResult", "aria2.getVersion", "aria2.getSessionInfo", "aria2.shutdown", "aria2.forceShutdown", "aria2.getGlobalStat", "aria2.saveSession", "system.multicall", "system.listMethods", "system.listNotifications", }; } // namespace const std::vector& allMethodNames() { return rpcMethodNames; } namespace { std::vector rpcNotificationsNames = { "aria2.onDownloadStart", "aria2.onDownloadPause", "aria2.onDownloadStop", "aria2.onDownloadComplete", "aria2.onDownloadError", #ifdef ENABLE_BITTORRENT "aria2.onBtDownloadComplete", #endif // ENABLE_BITTORRENT }; } // namespace const std::vector& allNotificationsNames() { return rpcNotificationsNames; } 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(); } if (methodName == SystemListMethodsRpcMethod::getMethodName()) { return make_unique(); } if (methodName == SystemListNotificationsRpcMethod::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