From b246c17850687e7b15b644b761fbfe835ffc1c32 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Thu, 26 May 2016 19:22:27 +0600 Subject: CLOUD: Fix CurlJsonRequest to use JsonCallback Type safety first. --- backends/networking/curl/curljsonrequest.cpp | 8 ++++---- backends/networking/curl/curljsonrequest.h | 9 +++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'backends/networking') 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 RequestJsonPair; +typedef Common::BaseCallback *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 already + CurlJsonRequest(JsonCallback cb, const char *url); virtual ~CurlJsonRequest(); virtual void handle(); -- cgit v1.2.3