aboutsummaryrefslogtreecommitdiff
path: root/backends/cloud
diff options
context:
space:
mode:
authorAlexander Tkachev2016-07-14 16:01:05 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commitc431ae6d84be1ef73c44b84c58ee3d9edff3d5e3 (patch)
tree0a1a2a4ccfb0bfc603e62c9f7dbc06c05d577333 /backends/cloud
parent85adefdb86e914a789a0db18c767c8ef5902f846 (diff)
downloadscummvm-rg350-c431ae6d84be1ef73c44b84c58ee3d9edff3d5e3.tar.gz
scummvm-rg350-c431ae6d84be1ef73c44b84c58ee3d9edff3d5e3.tar.bz2
scummvm-rg350-c431ae6d84be1ef73c44b84c58ee3d9edff3d5e3.zip
CLOUD: Calculate FolderDownload download speed
Diffstat (limited to 'backends/cloud')
-rw-r--r--backends/cloud/cloudmanager.cpp10
-rw-r--r--backends/cloud/cloudmanager.h3
-rw-r--r--backends/cloud/folderdownloadrequest.cpp15
-rw-r--r--backends/cloud/folderdownloadrequest.h5
-rw-r--r--backends/cloud/storage.cpp9
-rw-r--r--backends/cloud/storage.h3
6 files changed, 40 insertions, 5 deletions
diff --git a/backends/cloud/cloudmanager.cpp b/backends/cloud/cloudmanager.cpp
index 80ee24808c..7156197368 100644
--- a/backends/cloud/cloudmanager.cpp
+++ b/backends/cloud/cloudmanager.cpp
@@ -349,13 +349,19 @@ double CloudManager::getDownloadingProgress() {
uint64 CloudManager::getDownloadBytesNumber() {
Storage *storage = getCurrentStorage();
if (storage) return storage->getDownloadBytesNumber();
- return 1;
+ return 0;
}
uint64 CloudManager::getDownloadTotalBytesNumber() {
Storage *storage = getCurrentStorage();
if (storage) return storage->getDownloadTotalBytesNumber();
- return 1;
+ return 0;
+}
+
+uint64 CloudManager::getDownloadSpeed() {
+ Storage *storage = getCurrentStorage();
+ if (storage) return storage->getDownloadSpeed();
+ return 0;
}
Common::String CloudManager::getDownloadRemoteDirectory() {
diff --git a/backends/cloud/cloudmanager.h b/backends/cloud/cloudmanager.h
index 0baede7fe9..15409ee3a1 100644
--- a/backends/cloud/cloudmanager.h
+++ b/backends/cloud/cloudmanager.h
@@ -250,6 +250,9 @@ public:
/** Returns a total number of bytes to be downloaded in current download progress. */
uint64 getDownloadTotalBytesNumber();
+ /** Returns download speed of current download progress. */
+ uint64 getDownloadSpeed();
+
/** Returns remote directory path. */
virtual Common::String getDownloadRemoteDirectory();
diff --git a/backends/cloud/folderdownloadrequest.cpp b/backends/cloud/folderdownloadrequest.cpp
index 6a7b5d3aaf..d506d80c48 100644
--- a/backends/cloud/folderdownloadrequest.cpp
+++ b/backends/cloud/folderdownloadrequest.cpp
@@ -25,6 +25,7 @@
#include "backends/cloud/id/iddownloadrequest.h"
#include "common/debug.h"
#include "gui/downloaddialog.h"
+#include <backends/networking/curl/connectionmanager.h>
namespace Cloud {
@@ -51,7 +52,7 @@ void FolderDownloadRequest::start() {
_failedFiles.clear();
_ignoreCallback = false;
_totalFiles = 0;
- _downloadedBytes = _totalBytes = 0;
+ _downloadedBytes = _totalBytes = _wasDownloadedBytes = _currentDownloadSpeed = 0;
//list directory first
_workingRequest = _storage->listDirectory(
@@ -139,7 +140,13 @@ void FolderDownloadRequest::downloadNextFile() {
);
}
-void FolderDownloadRequest::handle() {}
+void FolderDownloadRequest::handle() {
+ uint32 microsecondsPassed = Networking::ConnectionManager::getCloudRequestsPeriodInMicroseconds();
+ uint64 currentDownloadedBytes = getDownloadedBytes();
+ uint64 downloadedThisPeriod = currentDownloadedBytes - _wasDownloadedBytes;
+ _currentDownloadSpeed = downloadedThisPeriod * (1000000L / microsecondsPassed);
+ _wasDownloadedBytes = currentDownloadedBytes;
+}
void FolderDownloadRequest::restart() { start(); }
@@ -171,4 +178,8 @@ uint64 FolderDownloadRequest::getTotalBytesToDownload() const {
return _totalBytes;
}
+uint64 FolderDownloadRequest::getDownloadSpeed() const {
+ return _currentDownloadSpeed;
+}
+
} // End of namespace Cloud
diff --git a/backends/cloud/folderdownloadrequest.h b/backends/cloud/folderdownloadrequest.h
index 1a67f32165..9d8dea4d20 100644
--- a/backends/cloud/folderdownloadrequest.h
+++ b/backends/cloud/folderdownloadrequest.h
@@ -40,7 +40,7 @@ class FolderDownloadRequest: public Networking::Request, public GUI::CommandSend
Request *_workingRequest;
bool _ignoreCallback;
uint32 _totalFiles;
- uint64 _downloadedBytes, _totalBytes;
+ uint64 _downloadedBytes, _totalBytes, _wasDownloadedBytes, _currentDownloadSpeed;
void start();
void directoryListedCallback(Storage::ListDirectoryResponse response);
@@ -65,6 +65,9 @@ public:
/** Returns a total number of bytes to download. */
uint64 getTotalBytesToDownload() const;
+ /** Returns average download speed for the last second. */
+ uint64 getDownloadSpeed() const;
+
/** Returns remote directory path. */
Common::String getRemotePath() { return _remoteDirectoryPath; }
diff --git a/backends/cloud/storage.cpp b/backends/cloud/storage.cpp
index c9843d6188..c20ad865ad 100644
--- a/backends/cloud/storage.cpp
+++ b/backends/cloud/storage.cpp
@@ -259,6 +259,15 @@ uint64 Storage::getDownloadTotalBytesNumber() {
return result;
}
+uint64 Storage::getDownloadSpeed() {
+ uint64 result = 0;
+ _runningRequestsMutex.lock();
+ if (_downloadFolderRequest)
+ result = _downloadFolderRequest->getDownloadSpeed();
+ _runningRequestsMutex.unlock();
+ return result;
+}
+
Common::String Storage::getDownloadRemoteDirectory() {
Common::String result = "";
_runningRequestsMutex.lock();
diff --git a/backends/cloud/storage.h b/backends/cloud/storage.h
index 6d9db33bc6..a577b3c468 100644
--- a/backends/cloud/storage.h
+++ b/backends/cloud/storage.h
@@ -204,6 +204,9 @@ public:
/** Returns a total number of bytes to be downloaded in current download progress. */
virtual uint64 getDownloadTotalBytesNumber();
+ /** Returns download speed of current download progress. */
+ virtual uint64 getDownloadSpeed();
+
/** Returns remote directory path. */
virtual Common::String getDownloadRemoteDirectory();