aboutsummaryrefslogtreecommitdiff
path: root/backends/networking/curl/curljsonrequest.cpp
diff options
context:
space:
mode:
authorAlexander Tkachev2016-05-27 15:21:06 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commit98150beb38f73b56c7bc76f95dcc1d72290e4ac7 (patch)
treec56f8d97d30fb15f41f07f402c80e83a13cc03fc /backends/networking/curl/curljsonrequest.cpp
parent83b349a033d71e92e292d1f1da0578d557ec6411 (diff)
downloadscummvm-rg350-98150beb38f73b56c7bc76f95dcc1d72290e4ac7.tar.gz
scummvm-rg350-98150beb38f73b56c7bc76f95dcc1d72290e4ac7.tar.bz2
scummvm-rg350-98150beb38f73b56c7bc76f95dcc1d72290e4ac7.zip
CLOUD: Refactor ConnectionManager/Requests system
ConnectionManager now storages Request * (not generates ids for it), Requests have control on their RequestState, RequestIdPair is now called Response and storages Request * with some response together. All related classes are changed to use it in more clean and understandable way. Request, RequestState and Response are carefully commented/documented.
Diffstat (limited to 'backends/networking/curl/curljsonrequest.cpp')
-rw-r--r--backends/networking/curl/curljsonrequest.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/backends/networking/curl/curljsonrequest.cpp b/backends/networking/curl/curljsonrequest.cpp
index 326d8e27a0..3c598d7f18 100644
--- a/backends/networking/curl/curljsonrequest.cpp
+++ b/backends/networking/curl/curljsonrequest.cpp
@@ -69,14 +69,11 @@ void CurlJsonRequest::handle() {
if (_stream->httpResponseCode() != 200)
warning("HTTP response code is not 200 OK (it's %ld)", _stream->httpResponseCode());
- ConnMan.getRequestInfo(_id).state = Networking::FINISHED;
- if (_jsonCallback) {
- char *contents = getPreparedContents();
- if (_stream->httpResponseCode() != 200)
- debug("%s", contents);
- Common::JSONValue *json = Common::JSON::parse(contents);
- (*_jsonCallback)(RequestJsonPair(_id, json)); //potential memory leak, free it in your callbacks!
- }
+ char *contents = getPreparedContents();
+ if (_stream->httpResponseCode() != 200)
+ debug("%s", contents);
+ Common::JSONValue *json = Common::JSON::parse(contents);
+ finishJson(json);
}
}
}
@@ -88,4 +85,14 @@ void CurlJsonRequest::restart() {
//with no stream available next handle() will create another one
}
+void CurlJsonRequest::finishJson(Common::JSONValue *json) {
+ Request::finish();
+ if (_jsonCallback) (*_jsonCallback)(JsonResponse(this, json)); //potential memory leak, free it in your callbacks!
+ else delete json;
+}
+
+void CurlJsonRequest::finish() {
+ finishJson(0);
+}
+
} //end of namespace Networking