aboutsummaryrefslogtreecommitdiff
path: root/backends/cloud
diff options
context:
space:
mode:
authorAlexander Tkachev2016-05-26 17:56:13 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commit62ccf1f902100febfb1be02b67e84a6e4938ebbf (patch)
tree1f86b079605ac27d897ae9fc3f9e6cc84e8bf205 /backends/cloud
parenteda575a660543884b1a4addd21b676a67d2c2a31 (diff)
downloadscummvm-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')
-rw-r--r--backends/cloud/downloadrequest.cpp17
-rw-r--r--backends/cloud/downloadrequest.h1
-rw-r--r--backends/cloud/dropbox/dropboxlistdirectoryrequest.cpp34
-rw-r--r--backends/cloud/dropbox/dropboxlistdirectoryrequest.h6
4 files changed, 50 insertions, 8 deletions
diff --git a/backends/cloud/downloadrequest.cpp b/backends/cloud/downloadrequest.cpp
index e86b6552e9..a96c298fe8 100644
--- a/backends/cloud/downloadrequest.cpp
+++ b/backends/cloud/downloadrequest.cpp
@@ -21,6 +21,7 @@
*/
#include "backends/cloud/downloadrequest.h"
+#include "backends/networking/curl/connectionmanager.h"
#include "common/debug.h"
#include "common/textconsole.h"
@@ -32,16 +33,19 @@ DownloadRequest::DownloadRequest(Storage::BoolCallback callback, Networking::Net
bool DownloadRequest::handle() {
if (!_remoteFileStream) {
warning("DownloadRequest: no stream to read");
+ ConnMan.getRequestInfo(_id).state = Networking::FINISHED;
return true;
}
if (!_localFile) {
warning("DownloadRequest: no file to write");
+ ConnMan.getRequestInfo(_id).state = Networking::FINISHED;
return true;
}
if (!_localFile->isOpen()) {
warning("DownloadRequest: failed to open file to write");
+ ConnMan.getRequestInfo(_id).state = Networking::FINISHED;
return true;
}
@@ -52,7 +56,8 @@ bool DownloadRequest::handle() {
if (readBytes != 0)
if (_localFile->write(buf, readBytes) != readBytes) {
warning("DownloadRequest: unable to write all received bytes into output file");
- if (_boolCallback) (*_boolCallback)(false);
+ ConnMan.getRequestInfo(_id).state = Networking::FINISHED;
+ if (_boolCallback) (*_boolCallback)(false);
return true;
}
@@ -62,6 +67,7 @@ bool DownloadRequest::handle() {
//TODO: do something about it actually
}
+ ConnMan.getRequestInfo(_id).state = Networking::FINISHED;
if (_boolCallback) (*_boolCallback)(_remoteFileStream->httpResponseCode() == 200);
_localFile->close(); //yes, I know it's closed automatically in ~DumpFile()
@@ -71,4 +77,13 @@ bool DownloadRequest::handle() {
return false;
}
+void DownloadRequest::restart() {
+ //this request doesn't know anything about the _remoteFileStream it's reading
+ //thus, it can't restart it
+ warning("DownloadRequest: cannot be restarted");
+ ConnMan.getRequestInfo(_id).state = Networking::FINISHED;
+ if (_boolCallback) (*_boolCallback)(false);
+ //TODO: fix that
+}
+
} //end of namespace Cloud
diff --git a/backends/cloud/downloadrequest.h b/backends/cloud/downloadrequest.h
index b135b15f23..c1564100c2 100644
--- a/backends/cloud/downloadrequest.h
+++ b/backends/cloud/downloadrequest.h
@@ -40,6 +40,7 @@ public:
virtual ~DownloadRequest() { delete _localFile; }
virtual bool handle();
+ virtual void restart();
};
} //end of namespace Cloud
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