/* */ #include "RpcMethodFactory.h" #include "RpcMethodImpl.h" #include "OptionParser.h" #include "OptionHandler.h" namespace aria2 { namespace rpc { namespace { SharedHandle getNoSuchMethod() { static SharedHandle m(new NoSuchMethodRpcMethod()); return m; } } // namespace namespace { SharedHandle createMethod(const std::string& methodName) { if(methodName == AddUriRpcMethod::getMethodName()) { return SharedHandle(new AddUriRpcMethod()); #ifdef ENABLE_BITTORRENT } else if(methodName == AddTorrentRpcMethod::getMethodName()) { return SharedHandle(new AddTorrentRpcMethod()); #endif // ENABLE_BITTORRENT #ifdef ENABLE_METALINK } else if(methodName == AddMetalinkRpcMethod::getMethodName()) { return SharedHandle(new AddMetalinkRpcMethod()); #endif // ENABLE_METALINK } else if(methodName == RemoveRpcMethod::getMethodName()) { return SharedHandle(new RemoveRpcMethod()); } else if(methodName == PauseRpcMethod::getMethodName()) { return SharedHandle(new PauseRpcMethod()); } else if(methodName == ForcePauseRpcMethod::getMethodName()) { return SharedHandle(new ForcePauseRpcMethod()); } else if(methodName == PauseAllRpcMethod::getMethodName()) { return SharedHandle(new PauseAllRpcMethod()); } else if(methodName == ForcePauseAllRpcMethod::getMethodName()) { return SharedHandle(new ForcePauseAllRpcMethod()); } else if(methodName == UnpauseRpcMethod::getMethodName()) { return SharedHandle(new UnpauseRpcMethod()); } else if(methodName == UnpauseAllRpcMethod::getMethodName()) { return SharedHandle(new UnpauseAllRpcMethod()); } else if(methodName == ForceRemoveRpcMethod::getMethodName()) { return SharedHandle(new ForceRemoveRpcMethod()); } else if(methodName == ChangePositionRpcMethod::getMethodName()) { return SharedHandle(new ChangePositionRpcMethod()); } else if(methodName == TellStatusRpcMethod::getMethodName()) { return SharedHandle(new TellStatusRpcMethod()); } else if(methodName == GetUrisRpcMethod::getMethodName()) { return SharedHandle(new GetUrisRpcMethod()); } else if(methodName == GetFilesRpcMethod::getMethodName()) { return SharedHandle(new GetFilesRpcMethod()); #ifdef ENABLE_BITTORRENT } else if(methodName == GetPeersRpcMethod::getMethodName()) { return SharedHandle(new GetPeersRpcMethod()); #endif // ENABLE_BITTORRENT } else if(methodName == GetServersRpcMethod::getMethodName()) { return SharedHandle(new GetServersRpcMethod()); } else if(methodName == TellActiveRpcMethod::getMethodName()) { return SharedHandle(new TellActiveRpcMethod()); } else if(methodName == TellWaitingRpcMethod::getMethodName()) { return SharedHandle(new TellWaitingRpcMethod()); } else if(methodName == TellStoppedRpcMethod::getMethodName()) { return SharedHandle(new TellStoppedRpcMethod()); } else if(methodName == GetOptionRpcMethod::getMethodName()) { return SharedHandle(new GetOptionRpcMethod()); } else if(methodName == ChangeUriRpcMethod::getMethodName()) { return SharedHandle(new ChangeUriRpcMethod()); } else if(methodName == ChangeOptionRpcMethod::getMethodName()) { return SharedHandle(new ChangeOptionRpcMethod()); } else if(methodName == GetGlobalOptionRpcMethod::getMethodName()) { return SharedHandle(new GetGlobalOptionRpcMethod()); } else if(methodName == ChangeGlobalOptionRpcMethod::getMethodName()) { return SharedHandle(new ChangeGlobalOptionRpcMethod()); } else if(methodName == PurgeDownloadResultRpcMethod::getMethodName()) { return SharedHandle(new PurgeDownloadResultRpcMethod()); } else if(methodName == RemoveDownloadResultRpcMethod::getMethodName()) { return SharedHandle(new RemoveDownloadResultRpcMethod()); } else if(methodName == GetVersionRpcMethod::getMethodName()) { return SharedHandle(new GetVersionRpcMethod()); } else if(methodName == GetSessionInfoRpcMethod::getMethodName()) { return SharedHandle(new GetSessionInfoRpcMethod()); } else if(methodName == ShutdownRpcMethod::getMethodName()) { return SharedHandle(new ShutdownRpcMethod()); } else if(methodName == ForceShutdownRpcMethod::getMethodName()) { return SharedHandle(new ForceShutdownRpcMethod()); } else if(methodName == GetGlobalStatRpcMethod::getMethodName()) { return SharedHandle(new GetGlobalStatRpcMethod()); } else if(methodName == SystemMulticallRpcMethod::getMethodName()) { return SharedHandle(new SystemMulticallRpcMethod()); } else { return SharedHandle(); } } } // namespace std::map > RpcMethodFactory::cache_; SharedHandle RpcMethodFactory::create(const std::string& methodName) { std::map >::const_iterator itr = cache_.find(methodName); if(itr == cache_.end()) { SharedHandle m = createMethod(methodName); if(m) { cache_.insert(std::make_pair(methodName, m)); return m; } else { return getNoSuchMethod(); } } else { return (*itr).second; } } } // namespace rpc } // namespace aria2