aboutsummaryrefslogtreecommitdiff
path: root/backends/networking
diff options
context:
space:
mode:
authorAlexander Tkachev2016-05-26 19:22:27 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commitb246c17850687e7b15b644b761fbfe835ffc1c32 (patch)
treec8ddc679b4ccf46d291cfc4e7bab5d201d8e8771 /backends/networking
parenta7b28605a01b59de6f3acc9df4cd1cac707c39e7 (diff)
downloadscummvm-rg350-b246c17850687e7b15b644b761fbfe835ffc1c32.tar.gz
scummvm-rg350-b246c17850687e7b15b644b761fbfe835ffc1c32.tar.bz2
scummvm-rg350-b246c17850687e7b15b644b761fbfe835ffc1c32.zip
CLOUD: Fix CurlJsonRequest to use JsonCallback
Type safety first.
Diffstat (limited to 'backends/networking')
-rw-r--r--backends/networking/curl/curljsonrequest.cpp8
-rw-r--r--backends/networking/curl/curljsonrequest.h9
2 files changed, 11 insertions, 6 deletions
diff --git a/backends/networking/curl/curljsonrequest.cpp b/backends/networking/curl/curljsonrequest.cpp
index fd3d631ba9..a323b34ed2 100644
--- a/backends/networking/curl/curljsonrequest.cpp
+++ b/backends/networking/curl/curljsonrequest.cpp
@@ -31,8 +31,8 @@
namespace Networking {
-CurlJsonRequest::CurlJsonRequest(DataCallback cb, const char *url):
- CurlRequest(cb, url), _contentsStream(DisposeAfterUse::YES) {}
+CurlJsonRequest::CurlJsonRequest(JsonCallback cb, const char *url):
+ CurlRequest(0, url), _jsonCallback(cb), _contentsStream(DisposeAfterUse::YES) {}
CurlJsonRequest::~CurlJsonRequest() {}
@@ -70,12 +70,12 @@ void CurlJsonRequest::handle() {
warning("HTTP response code is not 200 OK (it's %ld)", _stream->httpResponseCode());
ConnMan.getRequestInfo(_id).state = Networking::FINISHED;
- if (_callback) {
+ if (_jsonCallback) {
char *contents = getPreparedContents();
if (_stream->httpResponseCode() != 200)
debug("%s", contents);
Common::JSONValue *json = Common::JSON::parse(contents);
- (*_callback)(RequestDataPair(_id, json)); //potential memory leak, free it in your callbacks!
+ (*_jsonCallback)(RequestJsonPair(_id, json)); //potential memory leak, free it in your callbacks!
}
}
}
diff --git a/backends/networking/curl/curljsonrequest.h b/backends/networking/curl/curljsonrequest.h
index 3d5dd7858b..75d4a6df81 100644
--- a/backends/networking/curl/curljsonrequest.h
+++ b/backends/networking/curl/curljsonrequest.h
@@ -25,19 +25,24 @@
#include "backends/networking/curl/curlrequest.h"
#include "common/memstream.h"
+#include "common/json.h"
namespace Networking {
class NetworkReadStream;
-class CurlJsonRequest: public CurlRequest {
+typedef RequestIdPair<Common::JSONValue*> RequestJsonPair;
+typedef Common::BaseCallback<RequestJsonPair> *JsonCallback;
+
+class CurlJsonRequest: public CurlRequest {
+ JsonCallback _jsonCallback;
Common::MemoryWriteStreamDynamic _contentsStream;
/** Prepares raw bytes from _contentsStream to be parsed with Common::JSON::parse(). */
char *getPreparedContents();
public:
- CurlJsonRequest(DataCallback cb, const char *url); //TODO: use some Callback<JSON> already
+ CurlJsonRequest(JsonCallback cb, const char *url);
virtual ~CurlJsonRequest();
virtual void handle();