aboutsummaryrefslogtreecommitdiff
path: root/backends/networking
diff options
context:
space:
mode:
authorAlexander Tkachev2016-05-21 00:44:09 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commit17eb5f91433f2414dc73f89abfdd316407259b61 (patch)
tree0d605093c094c475ceb87f9aa1e394325f93d899 /backends/networking
parentf913675c43ada5c5f9128d904fd913129da35fe8 (diff)
downloadscummvm-rg350-17eb5f91433f2414dc73f89abfdd316407259b61.tar.gz
scummvm-rg350-17eb5f91433f2414dc73f89abfdd316407259b61.tar.bz2
scummvm-rg350-17eb5f91433f2414dc73f89abfdd316407259b61.zip
CLOUD: Add complex callbacks
Originally, I intended to add Storage API, StorageFile and StorageInfo stubs. When I tried to implement a simple info() call, I ended up fixing Request to contain some pointer field and all callbacks to have Request* parameter. And, now I have to place callback pointer into Request. which calls another callback. And, eventually, these "simple" callbacks would again require another pointer (to some caller class).
Diffstat (limited to 'backends/networking')
-rw-r--r--backends/networking/curl/curljsonrequest.cpp2
-rw-r--r--backends/networking/curl/request.h12
2 files changed, 12 insertions, 2 deletions
diff --git a/backends/networking/curl/curljsonrequest.cpp b/backends/networking/curl/curljsonrequest.cpp
index 59bc830692..929723c671 100644
--- a/backends/networking/curl/curljsonrequest.cpp
+++ b/backends/networking/curl/curljsonrequest.cpp
@@ -75,7 +75,7 @@ bool CurlJsonRequest::handle() {
if (_callback) {
char *contents = getPreparedContents();
Common::JSONValue *json = Common::JSON::parse(contents);
- _callback(json); //potential memory leak, free it in your callbacks!
+ _callback(this, json); //potential memory leak, free it in your callbacks!
}
return true;
}
diff --git a/backends/networking/curl/request.h b/backends/networking/curl/request.h
index 4f901f7c94..d405ec8551 100644
--- a/backends/networking/curl/request.h
+++ b/backends/networking/curl/request.h
@@ -27,7 +27,7 @@ namespace Networking {
class Request {
protected:
- typedef void(*Callback)(void *result);
+ typedef void(*Callback)(Request* request, void *result);
/**
* Callback, which should be called before Request returns true in handle().
@@ -36,6 +36,13 @@ protected:
Callback _callback;
+ /**
+ * Pointer, which could be set by Request creating code. It might be accessed
+ * from this Request when callback is called, for example.
+ */
+
+ void *_pointer;
+
public:
Request(Callback cb): _callback(cb) {};
virtual ~Request() {};
@@ -47,6 +54,9 @@ public:
*/
virtual bool handle() = 0;
+
+ void setPointer(void *ptr) { _pointer = ptr; }
+ void *pointer() const { return _pointer; }
};
} //end of namespace Cloud