CLOUD: Calculate FolderDownload download speed

This commit is contained in:
Alexander Tkachev 2016-07-14 16:01:05 +06:00
parent 85adefdb86
commit c431ae6d84
9 changed files with 47 additions and 6 deletions

View File

@ -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() {

View File

@ -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();

View File

@ -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

View File

@ -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; }

View File

@ -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();

View File

@ -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();

View File

@ -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) {

View File

@ -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. */

View File

@ -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);
}