summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2013-05-18 15:41:40 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2013-05-18 15:41:40 +0900
commita4b29ac2f7edfc77911cc92e08e345c1235cf6b9 (patch)
treee999ff32f663bea28c00e7125084b69712f40136
parentc688f51f2e8c436fec55fc1f06e2bbb52b6592f4 (diff)
Add getGlobalStat API
-rw-r--r--src/aria2api.cc15
-rw-r--r--src/includes/aria2/aria2.h36
2 files changed, 51 insertions, 0 deletions
diff --git a/src/aria2api.cc b/src/aria2api.cc
index 27ed6680..545d2bf6 100644
--- a/src/aria2api.cc
+++ b/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 =
diff --git a/src/includes/aria2/aria2.h b/src/includes/aria2/aria2.h
index fe4fb1b4..9aa76735 100644
--- a/src/includes/aria2/aria2.h
+++ b/src/includes/aria2/aria2.h
@@ -486,6 +486,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
*
* Constants how to re-position a download.