Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "backends/networking/curl/request.h"
00024
00025 namespace Networking {
00026
00027 ErrorResponse::ErrorResponse(Request *rq, Common::String resp):
00028 request(rq), interrupted(false), failed(true), response(resp), httpResponseCode(-1) {}
00029
00030 ErrorResponse::ErrorResponse(Request *rq, bool interrupt, bool failure, Common::String resp, long httpCode):
00031 request(rq), interrupted(interrupt), failed(failure), response(resp), httpResponseCode(httpCode) {}
00032
00033 Request::Request(DataCallback cb, ErrorCallback ecb):
00034 _callback(cb), _errorCallback(ecb), _state(PROCESSING), _retryInSeconds(0) {}
00035
00036 Request::~Request() {
00037 delete _callback;
00038 delete _errorCallback;
00039 }
00040
00041 void Request::handleRetry() {
00042 if (_retryInSeconds > 0) {
00043 --_retryInSeconds;
00044 } else {
00045 _state = PROCESSING;
00046 restart();
00047 }
00048 }
00049
00050 void Request::pause() { _state = PAUSED; }
00051
00052 void Request::finish() {
00053 ErrorResponse error(this, true, false, "Request::finish() was called (i.e. interrupted)", -1);
00054 finishError(error);
00055 }
00056
00057 void Request::retry(uint32 seconds) {
00058 _state = RETRY;
00059 _retryInSeconds = seconds;
00060 }
00061
00062 RequestState Request::state() const { return _state; }
00063
00064 Common::String Request::date() const { return ""; }
00065
00066 void Request::finishError(ErrorResponse error) {
00067 _state = FINISHED;
00068 if (_errorCallback)
00069 (*_errorCallback)(error);
00070 }
00071
00072 void Request::finishSuccess() { _state = FINISHED; }
00073
00074 }