CLOUD: Change Request::handle()
With new ConnectionManager upgrade Requests indicate that they are finished with RequestInfo.state. No need to use handle() return value anymore.
This commit is contained in:
parent
f4547f44df
commit
a7b28605a0
9 changed files with 16 additions and 29 deletions
|
@ -30,23 +30,23 @@ namespace Cloud {
|
||||||
DownloadRequest::DownloadRequest(Storage::BoolCallback callback, Networking::NetworkReadStream *stream, Common::DumpFile *dumpFile):
|
DownloadRequest::DownloadRequest(Storage::BoolCallback callback, Networking::NetworkReadStream *stream, Common::DumpFile *dumpFile):
|
||||||
Request(0), _boolCallback(callback), _remoteFileStream(stream), _localFile(dumpFile) {}
|
Request(0), _boolCallback(callback), _remoteFileStream(stream), _localFile(dumpFile) {}
|
||||||
|
|
||||||
bool DownloadRequest::handle() {
|
void DownloadRequest::handle() {
|
||||||
if (!_remoteFileStream) {
|
if (!_remoteFileStream) {
|
||||||
warning("DownloadRequest: no stream to read");
|
warning("DownloadRequest: no stream to read");
|
||||||
ConnMan.getRequestInfo(_id).state = Networking::FINISHED;
|
ConnMan.getRequestInfo(_id).state = Networking::FINISHED;
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_localFile) {
|
if (!_localFile) {
|
||||||
warning("DownloadRequest: no file to write");
|
warning("DownloadRequest: no file to write");
|
||||||
ConnMan.getRequestInfo(_id).state = Networking::FINISHED;
|
ConnMan.getRequestInfo(_id).state = Networking::FINISHED;
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_localFile->isOpen()) {
|
if (!_localFile->isOpen()) {
|
||||||
warning("DownloadRequest: failed to open file to write");
|
warning("DownloadRequest: failed to open file to write");
|
||||||
ConnMan.getRequestInfo(_id).state = Networking::FINISHED;
|
ConnMan.getRequestInfo(_id).state = Networking::FINISHED;
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int kBufSize = 640 * 1024; //640 KB is enough to everyone?..
|
const int kBufSize = 640 * 1024; //640 KB is enough to everyone?..
|
||||||
|
@ -58,7 +58,7 @@ bool DownloadRequest::handle() {
|
||||||
warning("DownloadRequest: unable to write all received bytes into output file");
|
warning("DownloadRequest: unable to write all received bytes into output file");
|
||||||
ConnMan.getRequestInfo(_id).state = Networking::FINISHED;
|
ConnMan.getRequestInfo(_id).state = Networking::FINISHED;
|
||||||
if (_boolCallback) (*_boolCallback)(Storage::RequestBoolPair(_id, false));
|
if (_boolCallback) (*_boolCallback)(Storage::RequestBoolPair(_id, false));
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_remoteFileStream->eos()) {
|
if (_remoteFileStream->eos()) {
|
||||||
|
@ -70,11 +70,8 @@ bool DownloadRequest::handle() {
|
||||||
ConnMan.getRequestInfo(_id).state = Networking::FINISHED;
|
ConnMan.getRequestInfo(_id).state = Networking::FINISHED;
|
||||||
if (_boolCallback) (*_boolCallback)(Storage::RequestBoolPair(_id, _remoteFileStream->httpResponseCode() == 200));
|
if (_boolCallback) (*_boolCallback)(Storage::RequestBoolPair(_id, _remoteFileStream->httpResponseCode() == 200));
|
||||||
|
|
||||||
_localFile->close(); //yes, I know it's closed automatically in ~DumpFile()
|
_localFile->close(); //yes, I know it's closed automatically in ~DumpFile()
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadRequest::restart() {
|
void DownloadRequest::restart() {
|
||||||
|
|
|
@ -39,7 +39,7 @@ public:
|
||||||
DownloadRequest(Storage::BoolCallback callback, Networking::NetworkReadStream *stream, Common::DumpFile *dumpFile);
|
DownloadRequest(Storage::BoolCallback callback, Networking::NetworkReadStream *stream, Common::DumpFile *dumpFile);
|
||||||
virtual ~DownloadRequest() { delete _localFile; }
|
virtual ~DownloadRequest() { delete _localFile; }
|
||||||
|
|
||||||
virtual bool handle();
|
virtual void handle();
|
||||||
virtual void restart();
|
virtual void restart();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -112,13 +112,11 @@ void DropboxListDirectoryRequest::responseCallback(Networking::RequestDataPair p
|
||||||
delete json;
|
delete json;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DropboxListDirectoryRequest::handle() {
|
void DropboxListDirectoryRequest::handle() {
|
||||||
if (_complete && _filesCallback) {
|
if (_complete) {
|
||||||
ConnMan.getRequestInfo(_id).state = Networking::FINISHED;
|
ConnMan.getRequestInfo(_id).state = Networking::FINISHED;
|
||||||
if (_filesCallback) (*_filesCallback)(Storage::RequestFileArrayPair(_id, _files));
|
if (_filesCallback) (*_filesCallback)(Storage::RequestFileArrayPair(_id, _files));
|
||||||
}
|
}
|
||||||
|
|
||||||
return _complete;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DropboxListDirectoryRequest::restart() {
|
void DropboxListDirectoryRequest::restart() {
|
||||||
|
|
|
@ -47,7 +47,7 @@ public:
|
||||||
DropboxListDirectoryRequest(Common::String token, Common::String path, Storage::FileArrayCallback cb, bool recursive = false);
|
DropboxListDirectoryRequest(Common::String token, Common::String path, Storage::FileArrayCallback cb, bool recursive = false);
|
||||||
virtual ~DropboxListDirectoryRequest() { delete _filesCallback; }
|
virtual ~DropboxListDirectoryRequest() { delete _filesCallback; }
|
||||||
|
|
||||||
virtual bool handle();
|
virtual void handle();
|
||||||
virtual void restart();
|
virtual void restart();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ char *CurlJsonRequest::getPreparedContents() {
|
||||||
return (char *)result;
|
return (char *)result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CurlJsonRequest::handle() {
|
void CurlJsonRequest::handle() {
|
||||||
if (!_stream) _stream = new NetworkReadStream(_url, _headersList, _postFields);
|
if (!_stream) _stream = new NetworkReadStream(_url, _headersList, _postFields);
|
||||||
|
|
||||||
if (_stream) {
|
if (_stream) {
|
||||||
|
@ -77,11 +77,8 @@ bool CurlJsonRequest::handle() {
|
||||||
Common::JSONValue *json = Common::JSON::parse(contents);
|
Common::JSONValue *json = Common::JSON::parse(contents);
|
||||||
(*_callback)(RequestDataPair(_id, json)); //potential memory leak, free it in your callbacks!
|
(*_callback)(RequestDataPair(_id, json)); //potential memory leak, free it in your callbacks!
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} //end of namespace Networking
|
} //end of namespace Networking
|
||||||
|
|
|
@ -40,7 +40,7 @@ public:
|
||||||
CurlJsonRequest(DataCallback cb, const char *url); //TODO: use some Callback<JSON> already
|
CurlJsonRequest(DataCallback cb, const char *url); //TODO: use some Callback<JSON> already
|
||||||
virtual ~CurlJsonRequest();
|
virtual ~CurlJsonRequest();
|
||||||
|
|
||||||
virtual bool handle();
|
virtual void handle();
|
||||||
};
|
};
|
||||||
|
|
||||||
} //end of namespace Networking
|
} //end of namespace Networking
|
||||||
|
|
|
@ -37,17 +37,14 @@ CurlRequest::~CurlRequest() {
|
||||||
if (_stream) delete _stream;
|
if (_stream) delete _stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CurlRequest::handle() {
|
void CurlRequest::handle() {
|
||||||
if (!_stream) _stream = new NetworkReadStream(_url, _headersList, _postFields);
|
if (!_stream) _stream = new NetworkReadStream(_url, _headersList, _postFields);
|
||||||
|
|
||||||
if (_stream && _stream->eos()) {
|
if (_stream && _stream->eos()) {
|
||||||
if (_stream->httpResponseCode() != 200)
|
if (_stream->httpResponseCode() != 200)
|
||||||
warning("HTTP response code is not 200 OK (it's %ld)", _stream->httpResponseCode());
|
warning("HTTP response code is not 200 OK (it's %ld)", _stream->httpResponseCode());
|
||||||
ConnMan.getRequestInfo(_id).state = Networking::FINISHED;
|
ConnMan.getRequestInfo(_id).state = Networking::FINISHED;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CurlRequest::restart() {
|
void CurlRequest::restart() {
|
||||||
|
|
|
@ -43,7 +43,7 @@ public:
|
||||||
CurlRequest(DataCallback cb, const char *url);
|
CurlRequest(DataCallback cb, const char *url);
|
||||||
virtual ~CurlRequest();
|
virtual ~CurlRequest();
|
||||||
|
|
||||||
virtual bool handle();
|
virtual void handle();
|
||||||
virtual void restart();
|
virtual void restart();
|
||||||
|
|
||||||
void addHeader(Common::String header);
|
void addHeader(Common::String header);
|
||||||
|
|
|
@ -55,11 +55,9 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method, which does actual work. Depends on what this Request is doing.
|
* Method, which does actual work. Depends on what this Request is doing.
|
||||||
*
|
|
||||||
* @return true if request's work is complete and it may be removed from Storage's list
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
virtual bool handle() = 0;
|
virtual void handle() = 0;
|
||||||
|
|
||||||
virtual void restart() = 0;
|
virtual void restart() = 0;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue