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& e = + session->context->reqinfo->getDownloadEngine(); + const SharedHandle& 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 getActiveDownload(Session* session) { const SharedHandle& 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 @@ -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 *