Browse Source

Added aria2.getGlobalStat RPC method.

It returns overall download/upload speed and the number of
active/stopped/waiting downloads.
Tatsuhiro Tsujikawa 14 years ago
parent
commit
cc7bc0aad3
4 changed files with 34 additions and 0 deletions
  1. 3 0
      doc/xmlrpc/aria2rpc
  2. 2 0
      src/RpcMethodFactory.cc
  3. 17 0
      src/RpcMethodImpl.cc
  4. 12 0
      src/RpcMethodImpl.h

+ 3 - 0
doc/xmlrpc/aria2rpc

@@ -255,6 +255,7 @@ Usage: #{program_name} addUri URI... [options]
        #{program_name} getSessionInfo [options]
        #{program_name} shutdown [options]
        #{program_name} forceShutdown [options]
+       #{program_name} getGlobalStat [options]
 Options:
 EOS
   
@@ -356,6 +357,8 @@ elsif command == "shutdown" then
   result=client.call("aria2."+command)
 elsif command == "forceShutdown" then
   result=client.call("aria2."+command)
+elsif command == "getGlobalStat" then
+  result=client.call("aria2."+command)
 else
   puts "Command not recognized"
   exit 1

+ 2 - 0
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 {

+ 17 - 0
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)
 {

+ 12 - 0
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