diff options
author | Alexander Tkachev | 2016-05-26 17:56:13 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | 62ccf1f902100febfb1be02b67e84a6e4938ebbf (patch) | |
tree | 1f86b079605ac27d897ae9fc3f9e6cc84e8bf205 /backends/cloud/dropbox | |
parent | eda575a660543884b1a4addd21b676a67d2c2a31 (diff) | |
download | scummvm-rg350-62ccf1f902100febfb1be02b67e84a6e4938ebbf.tar.gz scummvm-rg350-62ccf1f902100febfb1be02b67e84a6e4938ebbf.tar.bz2 scummvm-rg350-62ccf1f902100febfb1be02b67e84a6e4938ebbf.zip |
CLOUD: Add RequestInfo struct
ConnectionManager upgrade: it now contains a special struct for each
request, so you can access request status and data by request id.
Diffstat (limited to 'backends/cloud/dropbox')
-rw-r--r-- | backends/cloud/dropbox/dropboxlistdirectoryrequest.cpp | 34 | ||||
-rw-r--r-- | backends/cloud/dropbox/dropboxlistdirectoryrequest.h | 6 |
2 files changed, 33 insertions, 7 deletions
diff --git a/backends/cloud/dropbox/dropboxlistdirectoryrequest.cpp b/backends/cloud/dropbox/dropboxlistdirectoryrequest.cpp index 5e5957b12c..3dada884a0 100644 --- a/backends/cloud/dropbox/dropboxlistdirectoryrequest.cpp +++ b/backends/cloud/dropbox/dropboxlistdirectoryrequest.cpp @@ -30,24 +30,33 @@ namespace Cloud { namespace Dropbox { DropboxListDirectoryRequest::DropboxListDirectoryRequest(Common::String token, Common::String path, Storage::FileArrayCallback cb, bool recursive): - Networking::Request(0), _filesCallback(cb), _token(token), _complete(false) { - Common::BaseCallback<> *innerCallback = new Common::Callback<DropboxListDirectoryRequest>(this, &DropboxListDirectoryRequest::responseCallback);//new Common::GlobalFunctionCallback(printJson); //okay + Networking::Request(0), _requestedPath(path), _requestedRecursive(recursive), _filesCallback(cb), + _token(token), _complete(false), _requestId(-1) { + startupWork(); +} + +void DropboxListDirectoryRequest::startupWork() { + _files.clear(); + _complete = false; + + Common::BaseCallback<> *innerCallback = new Common::Callback<DropboxListDirectoryRequest>(this, &DropboxListDirectoryRequest::responseCallback); Networking::CurlJsonRequest *request = new Networking::CurlJsonRequest(innerCallback, "https://api.dropboxapi.com/2/files/list_folder"); request->addHeader("Authorization: Bearer " + _token); request->addHeader("Content-Type: application/json"); Common::JSONObject jsonRequestParameters; - jsonRequestParameters.setVal("path", new Common::JSONValue(path)); - jsonRequestParameters.setVal("recursive", new Common::JSONValue(recursive)); + jsonRequestParameters.setVal("path", new Common::JSONValue(_requestedPath)); + jsonRequestParameters.setVal("recursive", new Common::JSONValue(_requestedRecursive)); jsonRequestParameters.setVal("include_media_info", new Common::JSONValue(false)); jsonRequestParameters.setVal("include_deleted", new Common::JSONValue(false)); Common::JSONValue value(jsonRequestParameters); request->addPostField(Common::JSON::stringify(&value)); - ConnMan.addRequest(request); + _requestId = ConnMan.addRequest(request); } + void DropboxListDirectoryRequest::responseCallback(void *jsonPtr) { Common::JSONValue *json = (Common::JSONValue *)jsonPtr; if (json) { @@ -103,13 +112,24 @@ void DropboxListDirectoryRequest::responseCallback(void *jsonPtr) { } bool DropboxListDirectoryRequest::handle() { - if (_complete && _filesCallback) { - (*_filesCallback)(_files); + if (_complete && _filesCallback) { + ConnMan.getRequestInfo(_id).state = Networking::FINISHED; + if (_filesCallback) (*_filesCallback)(_files); } return _complete; } +void DropboxListDirectoryRequest::restart() { + if (_requestId != -1) { + Networking::RequestInfo &info = ConnMan.getRequestInfo(_requestId); + //TODO: I'm really not sure some CurlRequest would handle this (it must stop corresponding CURL transfer) + info.state = Networking::FINISHED; //may be CANCELED or INTERRUPTED or something? + _requestId = -1; + } + + startupWork(); +} } //end of namespace Dropbox } //end of namespace Cloud diff --git a/backends/cloud/dropbox/dropboxlistdirectoryrequest.h b/backends/cloud/dropbox/dropboxlistdirectoryrequest.h index 0c10512782..36070a2a32 100644 --- a/backends/cloud/dropbox/dropboxlistdirectoryrequest.h +++ b/backends/cloud/dropbox/dropboxlistdirectoryrequest.h @@ -31,18 +31,24 @@ namespace Cloud { namespace Dropbox { class DropboxListDirectoryRequest: public Networking::Request { + Common::String _requestedPath; + bool _requestedRecursive; + Storage::FileArrayCallback _filesCallback; Common::String _token; bool _complete; Common::Array<StorageFile> _files; + int32 _requestId; void responseCallback(void *jsonPtr); + void startupWork(); public: DropboxListDirectoryRequest(Common::String token, Common::String path, Storage::FileArrayCallback cb, bool recursive = false); virtual ~DropboxListDirectoryRequest() { delete _filesCallback; } virtual bool handle(); + virtual void restart(); }; } //end of namespace Dropbox |