diff options
author | Alexander Tkachev | 2016-05-30 18:13:31 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | aa987e5c52899bfafff4f1f84479a67761569109 (patch) | |
tree | 468f076020836c51647b7708558832193cffceab /backends/cloud/onedrive/onedrivelistdirectoryrequest.cpp | |
parent | a19fc52c329fdb0611eee7aedfb20fb0d1b9269c (diff) | |
download | scummvm-rg350-aa987e5c52899bfafff4f1f84479a67761569109.tar.gz scummvm-rg350-aa987e5c52899bfafff4f1f84479a67761569109.tar.bz2 scummvm-rg350-aa987e5c52899bfafff4f1f84479a67761569109.zip |
CLOUD: Add ListDirectoryStatus struct
It contains flags to indicate whether Request was interrupted or failed,
so dependent Requests may see that list is incomplete.
Diffstat (limited to 'backends/cloud/onedrive/onedrivelistdirectoryrequest.cpp')
-rw-r--r-- | backends/cloud/onedrive/onedrivelistdirectoryrequest.cpp | 52 |
1 files changed, 32 insertions, 20 deletions
diff --git a/backends/cloud/onedrive/onedrivelistdirectoryrequest.cpp b/backends/cloud/onedrive/onedrivelistdirectoryrequest.cpp index f1402c43b2..dbd5e44c0b 100644 --- a/backends/cloud/onedrive/onedrivelistdirectoryrequest.cpp +++ b/backends/cloud/onedrive/onedrivelistdirectoryrequest.cpp @@ -25,18 +25,25 @@ #include "backends/cloud/onedrive/onedrivetokenrefresher.h" #include "backends/cloud/iso8601.h" #include "backends/networking/curl/connectionmanager.h" +#include "backends/networking/curl/networkreadstream.h" #include "common/json.h" namespace Cloud { namespace OneDrive { -OneDriveListDirectoryRequest::OneDriveListDirectoryRequest(OneDriveStorage *storage, Common::String path, Storage::FileArrayCallback cb, bool recursive): +OneDriveListDirectoryRequest::OneDriveListDirectoryRequest(OneDriveStorage *storage, Common::String path, Storage::ListDirectoryCallback cb, bool recursive): Networking::Request(0), - _requestedPath(path), _requestedRecursive(recursive), _storage(storage), _filesCallback(cb), + _requestedPath(path), _requestedRecursive(recursive), _storage(storage), _listDirectoryCallback(cb), _workingRequest(nullptr), _ignoreCallback(false) { start(); } +OneDriveListDirectoryRequest::~OneDriveListDirectoryRequest() { + _ignoreCallback = true; + if (_workingRequest) _workingRequest->finish(); + delete _listDirectoryCallback; +} + void OneDriveListDirectoryRequest::start() { //cleanup _ignoreCallback = true; @@ -48,12 +55,12 @@ void OneDriveListDirectoryRequest::start() { _ignoreCallback = false; _directoriesQueue.push_back(_requestedPath); - listNextDirectory(); + listNextDirectory(_files); } -void OneDriveListDirectoryRequest::listNextDirectory() { +void OneDriveListDirectoryRequest::listNextDirectory(ListDirectoryStatus status) { if (_directoriesQueue.empty()) { - finishFiles(_files); + finishStatus(status); return; } @@ -76,7 +83,8 @@ void OneDriveListDirectoryRequest::makeRequest(Common::String url) { _workingRequest = ConnMan.addRequest(request); } -void OneDriveListDirectoryRequest::listedDirectoryCallback(Networking::JsonResponse pair) { +void OneDriveListDirectoryRequest::listedDirectoryCallback(Networking::JsonResponse pair) { + _workingRequest = nullptr; Common::JSONValue *json = pair.value; if (_ignoreCallback) { @@ -84,26 +92,29 @@ void OneDriveListDirectoryRequest::listedDirectoryCallback(Networking::JsonRespo return; } + ListDirectoryStatus status(_files); + Networking::CurlJsonRequest *rq = (Networking::CurlJsonRequest *)pair.request; + if (rq && rq->getNetworkReadStream()) + status.httpResponseCode = rq->getNetworkReadStream()->httpResponseCode(); + if (!json) { - finish(); + status.failed = true; + finishStatus(status); return; } Common::JSONObject response = json->asObject(); - //TODO: check that all keys exist to avoid segfaults + //TODO: check that ALL keys exist AND HAVE RIGHT TYPE to avoid segfaults Common::JSONArray items = response.getVal("value")->asArray(); for (uint32 i = 0; i < items.size(); ++i) { Common::JSONObject item = items[i]->asObject(); Common::String path = _currentDirectory + item.getVal("name")->asString(); - bool isDirectory = item.contains("folder"); - uint32 size = 0, timestamp = 0; - //if (!isDirectory) { - size = item.getVal("size")->asNumber(); - timestamp = ISO8601::convertToTimestamp(item.getVal("lastModifiedDateTime")->asString()); - //} + bool isDirectory = item.contains("folder"); + uint32 size = item.getVal("size")->asIntegerNumber(); + uint32 timestamp = ISO8601::convertToTimestamp(item.getVal("lastModifiedDateTime")->asString()); StorageFile file(path, size, timestamp, isDirectory); _files.push_back(file); @@ -116,21 +127,22 @@ void OneDriveListDirectoryRequest::listedDirectoryCallback(Networking::JsonRespo if (hasMore) { makeRequest(response.getVal("@odata.nextLink")->asString()); } else { - listNextDirectory(); + listNextDirectory(status); } delete json; } -void OneDriveListDirectoryRequest::finish() { - //TODO: indicate it's interrupted +void OneDriveListDirectoryRequest::finish() { Common::Array<StorageFile> files; - finishFiles(files); + ListDirectoryStatus status(files); + status.interrupted = true; + finishStatus(status); } -void OneDriveListDirectoryRequest::finishFiles(Common::Array<StorageFile> &files) { +void OneDriveListDirectoryRequest::finishStatus(ListDirectoryStatus status) { Request::finish(); - if (_filesCallback) (*_filesCallback)(Storage::FileArrayResponse(this, files)); + if (_listDirectoryCallback) (*_listDirectoryCallback)(Storage::ListDirectoryResponse(this, status)); } } // End of namespace OneDrive |