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

idstreamfilerequest.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/idstreamfilerequest.h"
00024 #include "backends/cloud/id/idstorage.h"
00025 
00026 namespace Cloud {
00027 namespace Id {
00028 
00029 IdStreamFileRequest::IdStreamFileRequest(IdStorage *storage, Common::String path, Networking::NetworkReadStreamCallback cb, Networking::ErrorCallback ecb):
00030     Networking::Request(nullptr, ecb), _requestedFile(path), _storage(storage), _streamCallback(cb),
00031     _workingRequest(nullptr), _ignoreCallback(false) {
00032     start();
00033 }
00034 
00035 IdStreamFileRequest::~IdStreamFileRequest() {
00036     _ignoreCallback = true;
00037     if (_workingRequest)
00038         _workingRequest->finish();
00039     delete _streamCallback;
00040 }
00041 
00042 void IdStreamFileRequest::start() {
00043     //cleanup
00044     _ignoreCallback = true;
00045     if (_workingRequest)
00046         _workingRequest->finish();
00047     _workingRequest = nullptr;
00048     _ignoreCallback = false;
00049 
00050     //find file's id
00051     Storage::UploadCallback innerCallback = new Common::Callback<IdStreamFileRequest, Storage::UploadResponse>(this, &IdStreamFileRequest::idResolvedCallback);
00052     Networking::ErrorCallback innerErrorCallback = new Common::Callback<IdStreamFileRequest, Networking::ErrorResponse>(this, &IdStreamFileRequest::idResolveFailedCallback);
00053     _workingRequest = _storage->resolveFileId(_requestedFile, innerCallback, innerErrorCallback);
00054 }
00055 
00056 void IdStreamFileRequest::idResolvedCallback(Storage::UploadResponse response) {
00057     _workingRequest = nullptr;
00058     if (_ignoreCallback)
00059         return;
00060 
00061     Networking::NetworkReadStreamCallback innerCallback = new Common::Callback<IdStreamFileRequest, Networking::NetworkReadStreamResponse>(this, &IdStreamFileRequest::streamFileCallback);
00062     Networking::ErrorCallback innerErrorCallback = new Common::Callback<IdStreamFileRequest, Networking::ErrorResponse>(this, &IdStreamFileRequest::streamFileErrorCallback);
00063     _workingRequest = _storage->streamFileById(response.value.id(), innerCallback, innerErrorCallback);
00064 }
00065 
00066 void IdStreamFileRequest::idResolveFailedCallback(Networking::ErrorResponse error) {
00067     _workingRequest = nullptr;
00068     if (_ignoreCallback)
00069         return;
00070     finishError(error);
00071 }
00072 
00073 void IdStreamFileRequest::streamFileCallback(Networking::NetworkReadStreamResponse response) {
00074     _workingRequest = nullptr;
00075     if (_ignoreCallback)
00076         return;
00077     finishStream(response.value);
00078 }
00079 
00080 void IdStreamFileRequest::streamFileErrorCallback(Networking::ErrorResponse error) {
00081     _workingRequest = nullptr;
00082     if (_ignoreCallback)
00083         return;
00084     finishError(error);
00085 }
00086 
00087 void IdStreamFileRequest::handle() {}
00088 
00089 void IdStreamFileRequest::restart() { start(); }
00090 
00091 void IdStreamFileRequest::finishStream(Networking::NetworkReadStream *stream) {
00092     Request::finishSuccess();
00093     if (_streamCallback)
00094         (*_streamCallback)(Networking::NetworkReadStreamResponse(this, stream));
00095 }
00096 
00097 } // End of namespace Id
00098 } // End of namespace Cloud


Generated on Sat Feb 9 2019 05:00:34 for ResidualVM by doxygen 1.7.1
curved edge   curved edge