1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "backends/networking/curl/request.h"
24 
25 namespace Networking {
26 
ErrorResponse(Request * rq,Common::String resp)27 ErrorResponse::ErrorResponse(Request *rq, Common::String resp):
28 	request(rq), interrupted(false), failed(true), response(resp), httpResponseCode(-1) {}
29 
ErrorResponse(Request * rq,bool interrupt,bool failure,Common::String resp,long httpCode)30 ErrorResponse::ErrorResponse(Request *rq, bool interrupt, bool failure, Common::String resp, long httpCode):
31 	request(rq), interrupted(interrupt), failed(failure), response(resp), httpResponseCode(httpCode) {}
32 
Request(DataCallback cb,ErrorCallback ecb)33 Request::Request(DataCallback cb, ErrorCallback ecb):
34 	_callback(cb), _errorCallback(ecb), _state(PROCESSING), _retryInSeconds(0) {}
35 
~Request()36 Request::~Request() {
37 	delete _callback;
38 	delete _errorCallback;
39 }
40 
handleRetry()41 void Request::handleRetry() {
42 	if (_retryInSeconds > 0) {
43 		--_retryInSeconds;
44 	} else {
45 		_state = PROCESSING;
46 		restart();
47 	}
48 }
49 
pause()50 void Request::pause() { _state = PAUSED; }
51 
finish()52 void Request::finish() {
53 	ErrorResponse error(this, true, false, "Request::finish() was called (i.e. interrupted)", -1);
54 	finishError(error);
55 }
56 
retry(uint32 seconds)57 void Request::retry(uint32 seconds) {
58 	_state = RETRY;
59 	_retryInSeconds = seconds;
60 }
61 
state() const62 RequestState Request::state() const { return _state; }
63 
date() const64 Common::String Request::date() const { return ""; }
65 
finishError(ErrorResponse error)66 void Request::finishError(ErrorResponse error) {
67 	_state = FINISHED;
68 	if (_errorCallback)
69 		(*_errorCallback)(error);
70 }
71 
finishSuccess()72 void Request::finishSuccess() { _state = FINISHED; }
73 
74 } // End of namespace Networking
75