ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

iddownloadrequest.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "backends/cloud/id/iddownloadrequest.h"
00024 #include "backends/cloud/id/idstorage.h"
00025 #include "backends/cloud/downloadrequest.h"
00026 
00027 namespace Cloud {
00028 namespace Id {
00029 
00030 IdDownloadRequest::IdDownloadRequest(IdStorage *storage, Common::String remotePath, Common::String localPath, Storage::BoolCallback cb, Networking::ErrorCallback ecb):
00031     Networking::Request(nullptr, ecb), _requestedFile(remotePath), _requestedLocalFile(localPath), _storage(storage), _boolCallback(cb),
00032     _workingRequest(nullptr), _ignoreCallback(false) {
00033     start();
00034 }
00035 
00036 IdDownloadRequest::~IdDownloadRequest() {
00037     _ignoreCallback = true;
00038     if (_workingRequest)
00039         _workingRequest->finish();
00040     delete _boolCallback;
00041 }
00042 
00043 void IdDownloadRequest::start() {
00044     //cleanup
00045     _ignoreCallback = true;
00046     if (_workingRequest)
00047         _workingRequest->finish();
00048     _workingRequest = nullptr;
00049     _ignoreCallback = false;
00050 
00051     //find file's id
00052     Storage::UploadCallback innerCallback = new Common::Callback<IdDownloadRequest, Storage::UploadResponse>(this, &IdDownloadRequest::idResolvedCallback);
00053     Networking::ErrorCallback innerErrorCallback = new Common::Callback<IdDownloadRequest, Networking::ErrorResponse>(this, &IdDownloadRequest::idResolveFailedCallback);
00054     _workingRequest = _storage->resolveFileId(_requestedFile, innerCallback, innerErrorCallback);
00055 }
00056 
00057 void IdDownloadRequest::idResolvedCallback(Storage::UploadResponse response) {
00058     _workingRequest = nullptr;
00059     if (_ignoreCallback)
00060         return;
00061 
00062     Storage::BoolCallback innerCallback = new Common::Callback<IdDownloadRequest, Storage::BoolResponse>(this, &IdDownloadRequest::downloadCallback);
00063     Networking::ErrorCallback innerErrorCallback = new Common::Callback<IdDownloadRequest, Networking::ErrorResponse>(this, &IdDownloadRequest::downloadErrorCallback);
00064     _workingRequest = _storage->downloadById(response.value.id(), _requestedLocalFile, innerCallback, innerErrorCallback);
00065 }
00066 
00067 void IdDownloadRequest::idResolveFailedCallback(Networking::ErrorResponse error) {
00068     _workingRequest = nullptr;
00069     if (_ignoreCallback)
00070         return;
00071     finishError(error);
00072 }
00073 
00074 void IdDownloadRequest::downloadCallback(Storage::BoolResponse response) {
00075     _workingRequest = nullptr;
00076     if (_ignoreCallback)
00077         return;
00078     finishDownload(response.value);
00079 }
00080 
00081 void IdDownloadRequest::downloadErrorCallback(Networking::ErrorResponse error) {
00082     _workingRequest = nullptr;
00083     if (_ignoreCallback)
00084         return;
00085     finishError(error);
00086 }
00087 
00088 void IdDownloadRequest::handle() {}
00089 
00090 void IdDownloadRequest::restart() { start(); }
00091 
00092 void IdDownloadRequest::finishDownload(bool success) {
00093     Request::finishSuccess();
00094     if (_boolCallback)
00095         (*_boolCallback)(Storage::BoolResponse(this, success));
00096 }
00097 
00098 double IdDownloadRequest::getProgress() const {
00099     DownloadRequest *downloadRequest = dynamic_cast<DownloadRequest *>(_workingRequest);
00100     if (downloadRequest == nullptr)
00101         return 0; // resolving id still
00102 
00103     // id resolve is 10 % and download is the other 90 %
00104     return 0.1 + 0.9 * downloadRequest->getProgress(); // downloading
00105 }
00106 
00107 } // End of namespace Id
00108 } // End of namespace Cloud


Generated on Sat Apr 20 2019 05:02:53 for ResidualVM by doxygen 1.7.1
curved edge   curved edge