diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2011-06-17 22:45:42 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2011-06-17 22:45:42 +0900 |
| commit | cc7bc0aad3f27b4201ce5870d018cb40599389ca (patch) | |
| tree | 78dbec15ecfa01da8d8d6d0e6030ad03a7657f87 /src | |
| parent | bb7e2e69db46c1abd51cdfc5dbfe11814adc06f4 (diff) | |
Added aria2.getGlobalStat RPC method.
It returns overall download/upload speed and the number of
active/stopped/waiting downloads.
Diffstat (limited to 'src')
| -rw-r--r-- | src/RpcMethodFactory.cc | 2 | ||||
| -rw-r--r-- | src/RpcMethodImpl.cc | 17 | ||||
| -rw-r--r-- | src/RpcMethodImpl.h | 12 |
3 files changed, 31 insertions, 0 deletions
diff --git a/src/RpcMethodFactory.cc b/src/RpcMethodFactory.cc index 088f2ba9..5e73c1a1 100644 --- a/src/RpcMethodFactory.cc +++ b/src/RpcMethodFactory.cc @@ -124,6 +124,8 @@ createMethod(const std::string& methodName) return SharedHandle<RpcMethod>(new ShutdownRpcMethod()); } else if(methodName == ForceShutdownRpcMethod::getMethodName()) { return SharedHandle<RpcMethod>(new ForceShutdownRpcMethod()); + } else if(methodName == GetGlobalStatRpcMethod::getMethodName()) { + return SharedHandle<RpcMethod>(new GetGlobalStatRpcMethod()); } else if(methodName == SystemMulticallRpcMethod::getMethodName()) { return SharedHandle<RpcMethod>(new SystemMulticallRpcMethod()); } else { diff --git a/src/RpcMethodImpl.cc b/src/RpcMethodImpl.cc index 3012c218..4f14561f 100644 --- a/src/RpcMethodImpl.cc +++ b/src/RpcMethodImpl.cc @@ -138,6 +138,9 @@ const std::string KEY_COMMENT = "comment"; const std::string KEY_CREATION_DATE = "creationDate"; const std::string KEY_MODE = "mode"; const std::string KEY_SERVERS = "servers"; +const std::string KEY_NUM_WAITING = "numWaiting"; +const std::string KEY_NUM_STOPPED = "numStopped"; +const std::string KEY_NUM_ACTIVE = "numActive"; } // namespace namespace { @@ -1363,6 +1366,20 @@ SharedHandle<ValueBase> ForceShutdownRpcMethod::process return goingShutdown(req, e, true); } +SharedHandle<ValueBase> GetGlobalStatRpcMethod::process +(const RpcRequest& req, DownloadEngine* e) +{ + const SharedHandle<RequestGroupMan>& rgman = e->getRequestGroupMan(); + TransferStat ts = rgman->calculateStat(); + SharedHandle<Dict> res = Dict::g(); + res->put(KEY_DOWNLOAD_SPEED, util::uitos(ts.downloadSpeed)); + res->put(KEY_UPLOAD_SPEED, util::uitos(ts.uploadSpeed)); + res->put(KEY_NUM_WAITING, util::uitos(rgman->getReservedGroups().size())); + res->put(KEY_NUM_STOPPED, util::uitos(rgman->getDownloadResults().size())); + res->put(KEY_NUM_ACTIVE, util::uitos(rgman->getRequestGroups().size())); + return res; +} + SharedHandle<ValueBase> SystemMulticallRpcMethod::process (const RpcRequest& req, DownloadEngine* e) { diff --git a/src/RpcMethodImpl.h b/src/RpcMethodImpl.h index b83c4dfe..e3fbc338 100644 --- a/src/RpcMethodImpl.h +++ b/src/RpcMethodImpl.h @@ -530,6 +530,18 @@ public: } }; +class GetGlobalStatRpcMethod:public RpcMethod { +protected: + virtual SharedHandle<ValueBase> process + (const RpcRequest& req, DownloadEngine* e); +public: + static const std::string& getMethodName() + { + static std::string methodName = "aria2.getGlobalStat"; + return methodName; + } +}; + class ForceShutdownRpcMethod:public RpcMethod { protected: virtual SharedHandle<ValueBase> process |
