CLOUD: Extend Storage & SavesSyncRequest
Now one can learn whether SavesSyncRequest is running, its progress and which files are being synced.
This commit is contained in:
parent
1bcbab7ad2
commit
e98b0b12ad
4 changed files with 77 additions and 5 deletions
|
@ -30,7 +30,7 @@
|
|||
|
||||
namespace Cloud {
|
||||
|
||||
Storage::Storage(): _runningRequestsCount(0) {}
|
||||
Storage::Storage(): _runningRequestsCount(0), _savesSyncRequest(nullptr) {}
|
||||
|
||||
Storage::~Storage() {}
|
||||
|
||||
|
@ -53,6 +53,8 @@ Networking::Request *Storage::addRequest(Networking::Request *request) {
|
|||
|
||||
void Storage::requestFinishedCallback(Networking::Request *invalidRequestPointer) {
|
||||
_runningRequestsMutex.lock();
|
||||
if (invalidRequestPointer == _savesSyncRequest)
|
||||
_savesSyncRequest = nullptr;
|
||||
--_runningRequestsCount;
|
||||
if (_runningRequestsCount == 0) debug("Storage is not working now");
|
||||
_runningRequestsMutex.unlock();
|
||||
|
@ -96,8 +98,16 @@ Networking::Request *Storage::downloadFolder(Common::String remotePath, Common::
|
|||
}
|
||||
|
||||
Networking::Request *Storage::syncSaves(BoolCallback callback, Networking::ErrorCallback errorCallback) {
|
||||
_runningRequestsMutex.lock();
|
||||
if (_savesSyncRequest) {
|
||||
warning("Storage::syncSaves: there is a sync in progress already");
|
||||
_runningRequestsMutex.unlock();
|
||||
return _savesSyncRequest;
|
||||
}
|
||||
if (!errorCallback) errorCallback = getErrorPrintingCallback();
|
||||
return addRequest(new SavesSyncRequest(this, callback, errorCallback));
|
||||
_savesSyncRequest = new SavesSyncRequest(this, callback, errorCallback);
|
||||
_runningRequestsMutex.unlock();
|
||||
return addRequest(_savesSyncRequest);
|
||||
}
|
||||
|
||||
bool Storage::isWorking() {
|
||||
|
@ -107,5 +117,30 @@ bool Storage::isWorking() {
|
|||
return working;
|
||||
}
|
||||
|
||||
bool Storage::isSyncing() {
|
||||
_runningRequestsMutex.lock();
|
||||
bool syncing = _savesSyncRequest != nullptr;
|
||||
_runningRequestsMutex.unlock();
|
||||
return syncing;
|
||||
}
|
||||
|
||||
double Storage::getSyncProgress() {
|
||||
double result = 1;
|
||||
_runningRequestsMutex.lock();
|
||||
if (_savesSyncRequest)
|
||||
result = _savesSyncRequest->getProgress();
|
||||
_runningRequestsMutex.unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
Common::Array<Common::String> Storage::getSyncingFiles() {
|
||||
Common::Array<Common::String> result;
|
||||
_runningRequestsMutex.lock();
|
||||
if (_savesSyncRequest)
|
||||
result = _savesSyncRequest->getFilesToUpload();
|
||||
_runningRequestsMutex.unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
} // End of namespace Cloud
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue