Mercurial > hg > orthanc-stone
diff Platforms/Wasm/WasmWebService.cpp @ 299:3897f9f28cfa am-callable-and-promise
backup work in progress: updated messaging framework with ICallable
author | am@osimis.io |
---|---|
date | Fri, 14 Sep 2018 16:44:01 +0200 |
parents | 9afafb192180 |
children | ed1a4302154f |
line wrap: on
line diff
--- a/Platforms/Wasm/WasmWebService.cpp Mon Sep 10 12:22:26 2018 +0200 +++ b/Platforms/Wasm/WasmWebService.cpp Fri Sep 14 16:44:01 2018 +0200 @@ -11,7 +11,13 @@ const char* uri, const char* headersInJsonString, void* payload); - + + extern void WasmWebService_NewScheduleGetRequest(void* callableSuccess, + void* callableFailure, + const char* uri, + const char* headersInJsonString, + void* payload); + extern void WasmWebService_SchedulePostRequest(void* callback, const char* uri, const char* headersInJsonString, @@ -51,6 +57,38 @@ } } + void EMSCRIPTEN_KEEPALIVE WasmWebService_NewNotifyError(void* failureCallable, + const char* uri, + void* payload) + { + if (failureCallable == NULL) + { + throw; + } + else + { + reinterpret_cast<OrthancStone::MessageHandler<OrthancStone::IWebService::NewHttpRequestErrorMessage>*>(failureCallable)-> + Apply(OrthancStone::IWebService::NewHttpRequestErrorMessage(uri, reinterpret_cast<Orthanc::IDynamicObject*>(payload))); + } + } + + void EMSCRIPTEN_KEEPALIVE WasmWebService_NewNotifySuccess(void* successCallable, + const char* uri, + const void* body, + size_t bodySize, + void* payload) + { + if (successCallable == NULL) + { + throw; + } + else + { + reinterpret_cast<OrthancStone::MessageHandler<OrthancStone::IWebService::NewHttpRequestSuccessMessage>*>(successCallable)-> + Apply(OrthancStone::IWebService::NewHttpRequestSuccessMessage(uri, body, bodySize, reinterpret_cast<Orthanc::IDynamicObject*>(payload))); + } + } + void EMSCRIPTEN_KEEPALIVE WasmWebService_SetBaseUri(const char* baseUri) { OrthancStone::WasmWebService::GetInstance().SetBaseUri(baseUri); @@ -119,4 +157,17 @@ WasmWebService_SchedulePostRequest(&callback, uri.c_str(), headersInJsonString.c_str(), body.c_str(), body.size(), payload); } + + void WasmWebService::GetAsync(const std::string& relativeUri, + const Headers& headers, + Orthanc::IDynamicObject* payload, + MessageHandler<IWebService::NewHttpRequestSuccessMessage>* successCallable, + MessageHandler<IWebService::NewHttpRequestErrorMessage>* failureCallable) + { + std::string uri = baseUri_ + relativeUri; + std::string headersInJsonString; + ToJsonString(headersInJsonString, headers); + WasmWebService_NewScheduleGetRequest(successCallable, failureCallable, uri.c_str(), headersInJsonString.c_str(), payload); + } + }