diff options
author | Alexander Tkachev | 2016-07-14 16:01:05 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | c431ae6d84be1ef73c44b84c58ee3d9edff3d5e3 (patch) | |
tree | 0a1a2a4ccfb0bfc603e62c9f7dbc06c05d577333 | |
parent | 85adefdb86e914a789a0db18c767c8ef5902f846 (diff) | |
download | scummvm-rg350-c431ae6d84be1ef73c44b84c58ee3d9edff3d5e3.tar.gz scummvm-rg350-c431ae6d84be1ef73c44b84c58ee3d9edff3d5e3.tar.bz2 scummvm-rg350-c431ae6d84be1ef73c44b84c58ee3d9edff3d5e3.zip |
CLOUD: Calculate FolderDownload download speed
-rw-r--r-- | backends/cloud/cloudmanager.cpp | 10 | ||||
-rw-r--r-- | backends/cloud/cloudmanager.h | 3 | ||||
-rw-r--r-- | backends/cloud/folderdownloadrequest.cpp | 15 | ||||
-rw-r--r-- | backends/cloud/folderdownloadrequest.h | 5 | ||||
-rw-r--r-- | backends/cloud/storage.cpp | 9 | ||||
-rw-r--r-- | backends/cloud/storage.h | 3 | ||||
-rw-r--r-- | backends/networking/curl/connectionmanager.cpp | 4 | ||||
-rw-r--r-- | backends/networking/curl/connectionmanager.h | 2 | ||||
-rw-r--r-- | gui/downloaddialog.cpp | 2 |
9 files changed, 47 insertions, 6 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(); diff --git a/backends/networking/curl/connectionmanager.cpp b/backends/networking/curl/connectionmanager.cpp index f7c8e2c92d..415151d40d 100644 --- a/backends/networking/curl/connectionmanager.cpp +++ b/backends/networking/curl/connectionmanager.cpp @@ -91,6 +91,10 @@ Common::String ConnectionManager::urlEncode(Common::String s) { return ""; } +uint32 ConnectionManager::getCloudRequestsPeriodInMicroseconds() { + return TIMER_INTERVAL * FRAMES_PER_SECOND / CLOUD_PERIOD; +} + //private goes here: void connectionsThread(void *ignored) { diff --git a/backends/networking/curl/connectionmanager.h b/backends/networking/curl/connectionmanager.h index 602f8930cd..0da5d5ad84 100644 --- a/backends/networking/curl/connectionmanager.h +++ b/backends/networking/curl/connectionmanager.h @@ -120,6 +120,8 @@ public: /** Return URL-encoded version of given string. */ Common::String urlEncode(Common::String s); + + static uint32 getCloudRequestsPeriodInMicroseconds(); }; /** Shortcut for accessing the connection manager. */ diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp index fde560f271..d734839cea 100644 --- a/gui/downloaddialog.cpp +++ b/gui/downloaddialog.cpp @@ -192,7 +192,7 @@ void DownloadDialog::refreshWidgets() { _remoteDirectoryLabel->setLabel(_("From: ") + CloudMan.getDownloadRemoteDirectory()); _localDirectoryLabel->setLabel(_("To: ") + _localDirectory); uint32 progress = (uint32)(100 * CloudMan.getDownloadingProgress()); - _percentLabel->setLabel(Common::String::format("%u %% (%u bytes out of %u)", progress, CloudMan.getDownloadBytesNumber(), CloudMan.getDownloadTotalBytesNumber())); + _percentLabel->setLabel(Common::String::format("%u %% (%u bytes out of %u - %u bytes per second)", progress, CloudMan.getDownloadBytesNumber(), CloudMan.getDownloadTotalBytesNumber(), CloudMan.getDownloadSpeed())); _progressBar->setValue(progress); } |