diff options
author | Alexander Tkachev | 2016-05-26 19:02:55 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | f4547f44df32ce1f49a6a36df083e7703751adcd (patch) | |
tree | a69e2f703a42348d9766ad128bb88b2c169719ad /backends/networking/curl | |
parent | 62ccf1f902100febfb1be02b67e84a6e4938ebbf (diff) | |
download | scummvm-rg350-f4547f44df32ce1f49a6a36df083e7703751adcd.tar.gz scummvm-rg350-f4547f44df32ce1f49a6a36df083e7703751adcd.tar.bz2 scummvm-rg350-f4547f44df32ce1f49a6a36df083e7703751adcd.zip |
CLOUD: Add RequestIdPair struct
Can be used with Callback<T> (means it's still type safe). It's used to
pass not only Request id to user's callback, but also a value user
wanted.
void *data field is removed from RequestInfo.
Diffstat (limited to 'backends/networking/curl')
-rw-r--r-- | backends/networking/curl/connectionmanager.h | 7 | ||||
-rw-r--r-- | backends/networking/curl/curljsonrequest.cpp | 4 | ||||
-rw-r--r-- | backends/networking/curl/curljsonrequest.h | 2 | ||||
-rw-r--r-- | backends/networking/curl/curlrequest.cpp | 2 | ||||
-rw-r--r-- | backends/networking/curl/curlrequest.h | 2 | ||||
-rw-r--r-- | backends/networking/curl/request.h | 14 |
6 files changed, 20 insertions, 11 deletions
diff --git a/backends/networking/curl/connectionmanager.h b/backends/networking/curl/connectionmanager.h index 9ae52b3eeb..15327a28b2 100644 --- a/backends/networking/curl/connectionmanager.h +++ b/backends/networking/curl/connectionmanager.h @@ -46,12 +46,11 @@ enum RequestState { struct RequestInfo { int32 id; Request *request; - RequestState state; - void *data; + RequestState state; uint32 retryInSeconds; - RequestInfo() : id(-1), request(0), state(FINISHED), data(0), retryInSeconds(0) {} - RequestInfo(int32 rqId, Request *rq) : id(rqId), request(rq), state(PROCESSING), data(0), retryInSeconds(0) {} + RequestInfo() : id(-1), request(0), state(FINISHED), retryInSeconds(0) {} + RequestInfo(int32 rqId, Request *rq) : id(rqId), request(rq), state(PROCESSING), retryInSeconds(0) {} }; class ConnectionManager : public Common::Singleton<ConnectionManager> { diff --git a/backends/networking/curl/curljsonrequest.cpp b/backends/networking/curl/curljsonrequest.cpp index 21c0a0f644..11eeb2904a 100644 --- a/backends/networking/curl/curljsonrequest.cpp +++ b/backends/networking/curl/curljsonrequest.cpp @@ -31,7 +31,7 @@ namespace Networking { -CurlJsonRequest::CurlJsonRequest(Common::BaseCallback<> *cb, const char *url): +CurlJsonRequest::CurlJsonRequest(DataCallback cb, const char *url): CurlRequest(cb, url), _contentsStream(DisposeAfterUse::YES) {} CurlJsonRequest::~CurlJsonRequest() {} @@ -75,7 +75,7 @@ bool CurlJsonRequest::handle() { if (_stream->httpResponseCode() != 200) debug("%s", contents); Common::JSONValue *json = Common::JSON::parse(contents); - (*_callback)(json); //potential memory leak, free it in your callbacks! + (*_callback)(RequestDataPair(_id, json)); //potential memory leak, free it in your callbacks! } return true; } diff --git a/backends/networking/curl/curljsonrequest.h b/backends/networking/curl/curljsonrequest.h index cfb82e97e3..9b23cd79f4 100644 --- a/backends/networking/curl/curljsonrequest.h +++ b/backends/networking/curl/curljsonrequest.h @@ -37,7 +37,7 @@ class CurlJsonRequest: public CurlRequest { char *getPreparedContents(); public: - CurlJsonRequest(Common::BaseCallback<> *cb, const char *url); + CurlJsonRequest(DataCallback cb, const char *url); //TODO: use some Callback<JSON> already virtual ~CurlJsonRequest(); virtual bool handle(); diff --git a/backends/networking/curl/curlrequest.cpp b/backends/networking/curl/curlrequest.cpp index e1c8f2b18c..6f5c612bdf 100644 --- a/backends/networking/curl/curlrequest.cpp +++ b/backends/networking/curl/curlrequest.cpp @@ -30,7 +30,7 @@ namespace Networking { -CurlRequest::CurlRequest(Common::BaseCallback<> *cb, const char *url): +CurlRequest::CurlRequest(DataCallback cb, const char *url): Request(cb), _url(url), _stream(0), _headersList(0) {} CurlRequest::~CurlRequest() { diff --git a/backends/networking/curl/curlrequest.h b/backends/networking/curl/curlrequest.h index ec1a9e33c6..c7f07fcb18 100644 --- a/backends/networking/curl/curlrequest.h +++ b/backends/networking/curl/curlrequest.h @@ -40,7 +40,7 @@ protected: Common::String _postFields; public: - CurlRequest(Common::BaseCallback<> *cb, const char *url); + CurlRequest(DataCallback cb, const char *url); virtual ~CurlRequest(); virtual bool handle(); diff --git a/backends/networking/curl/request.h b/backends/networking/curl/request.h index 136f007920..f2c2f1f247 100644 --- a/backends/networking/curl/request.h +++ b/backends/networking/curl/request.h @@ -28,6 +28,16 @@ namespace Networking { +template<typename T> struct RequestIdPair { + int32 id; + T value; + + RequestIdPair(int32 rid, T v) : id(rid), value(v) {} +}; + +typedef RequestIdPair<void *> RequestDataPair; +typedef Common::BaseCallback<RequestDataPair> *DataCallback; + class Request { protected: /** @@ -35,12 +45,12 @@ protected: * That's the way Requests pass the result to the code which asked to create this request. */ - Common::BaseCallback<> *_callback; + DataCallback _callback; int32 _id; public: - Request(Common::BaseCallback<> *cb): _callback(cb), _id(-1) {} + Request(DataCallback cb): _callback(cb), _id(-1) {} virtual ~Request() { delete _callback; } /** |