瀏覽代碼

Add getGlobalStat API

Tatsuhiro Tsujikawa 12 年之前
父節點
當前提交
a4b29ac2f7
共有 2 個文件被更改,包括 51 次插入0 次删除
  1. 15 0
      src/aria2api.cc
  2. 36 0
      src/includes/aria2/aria2.h

+ 15 - 0
src/aria2api.cc

@@ -521,6 +521,21 @@ int changeGlobalOption(Session* session, const KeyVals& options)
   return 0;
 }
 
+GlobalStat getGlobalStat(Session* session)
+{
+  const SharedHandle<DownloadEngine>& e =
+    session->context->reqinfo->getDownloadEngine();
+  const SharedHandle<RequestGroupMan>& rgman = e->getRequestGroupMan();
+  TransferStat ts = rgman->calculateStat();
+  GlobalStat res;
+  res.downloadSpeed = ts.downloadSpeed;
+  res.uploadSpeed = ts.uploadSpeed;
+  res.numActive = rgman->getRequestGroups().size();
+  res.numWaiting = rgman->getReservedGroups().size();
+  res.numStopped = rgman->getDownloadResults().size();
+  return res;
+}
+
 std::vector<A2Gid> getActiveDownload(Session* session)
 {
   const SharedHandle<DownloadEngine>& e =

+ 36 - 0
src/includes/aria2/aria2.h

@@ -485,6 +485,42 @@ KeyVals getGlobalOptions(Session* session);
  */
 int changeGlobalOption(Session* session, const KeyVals& options);
 
+/**
+ * @struct
+ *
+ * Global statistics of current aria2 session.
+ */
+struct GlobalStat {
+  /**
+   * Overall download speed (byte/sec).
+   */
+  int downloadSpeed;
+  /**
+   * Overall upload speed(byte/sec).
+   */
+  int uploadSpeed;
+  /**
+   * The number of active downloads.
+   */
+  int numActive;
+  /**
+   * The number of waiting downloads.
+   */
+  int numWaiting;
+  /**
+   * The number of stopped downloads.
+   */
+  int numStopped;
+};
+
+/**
+ * @function
+ *
+ * Returns global statistics such as overall download and upload
+ * speed.
+ */
+GlobalStat getGlobalStat(Session* session);
+
 /**
  * @enum
  *