# HG changeset patch # User am@osimis.io # Date 1537287446 -7200 # Node ID ed1a4302154f41024f5d17a771e2531910e6cdd0 # Parent 4a79193ffb58bda4940a7ce7122e22e4fe29ea2b new messages in wasm too diff -r 4a79193ffb58 -r ed1a4302154f Platforms/Wasm/WasmWebService.cpp --- a/Platforms/Wasm/WasmWebService.cpp Tue Sep 18 18:04:53 2018 +0200 +++ b/Platforms/Wasm/WasmWebService.cpp Tue Sep 18 18:17:26 2018 +0200 @@ -7,57 +7,22 @@ extern "C" { #endif - extern void WasmWebService_ScheduleGetRequest(void* callback, - 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, - const void* body, - size_t bodySize, - void* payload); + extern void WasmWebService_GetAsync(void* callableSuccess, + void* callableFailure, + const char* uri, + const char* headersInJsonString, + void* payload); - void EMSCRIPTEN_KEEPALIVE WasmWebService_NotifyError(void* callback, - const char* uri, - void* payload) - { - if (callback == NULL) - { - throw; - } - else - { - reinterpret_cast(callback)-> - OnHttpRequestError(uri, reinterpret_cast(payload)); - } - } + extern void WasmWebService_PostAsync(void* callableSuccess, + void* callableFailure, + const char* uri, + const char* headersInJsonString, + const void* body, + size_t bodySize, + void* payload); - void EMSCRIPTEN_KEEPALIVE WasmWebService_NotifySuccess(void* callback, - const char* uri, - const void* body, - size_t bodySize, - void* payload) - { - if (callback == NULL) - { - throw; - } - else - { - reinterpret_cast(callback)-> - OnHttpRequestSuccess(uri, body, bodySize, reinterpret_cast(payload)); - } - } - void EMSCRIPTEN_KEEPALIVE WasmWebService_NewNotifyError(void* failureCallable, + void EMSCRIPTEN_KEEPALIVE WasmWebService_NotifyError(void* failureCallable, const char* uri, void* payload) { @@ -67,12 +32,12 @@ } else { - reinterpret_cast*>(failureCallable)-> - Apply(OrthancStone::IWebService::NewHttpRequestErrorMessage(uri, reinterpret_cast(payload))); + reinterpret_cast*>(failureCallable)-> + Apply(OrthancStone::IWebService::HttpRequestErrorMessage(uri, reinterpret_cast(payload))); } } - void EMSCRIPTEN_KEEPALIVE WasmWebService_NewNotifySuccess(void* successCallable, + void EMSCRIPTEN_KEEPALIVE WasmWebService_NotifySuccess(void* successCallable, const char* uri, const void* body, size_t bodySize, @@ -84,8 +49,8 @@ } else { - reinterpret_cast*>(successCallable)-> - Apply(OrthancStone::IWebService::NewHttpRequestSuccessMessage(uri, body, bodySize, reinterpret_cast(payload))); + reinterpret_cast*>(successCallable)-> + Apply(OrthancStone::IWebService::HttpRequestSuccessMessage(uri, body, bodySize, reinterpret_cast(payload))); } } @@ -134,40 +99,30 @@ output = outputStr.str(); } - void WasmWebService::ScheduleGetRequest(ICallback& callback, - const std::string& relativeUri, - const Headers& headers, - Orthanc::IDynamicObject* payload) + void WasmWebService::PostAsync(const std::string& relativeUri, + const Headers& headers, + const std::string& body, + Orthanc::IDynamicObject* payload, + MessageHandler* successCallable, + MessageHandler* failureCallable) { std::string uri = baseUri_ + relativeUri; std::string headersInJsonString; ToJsonString(headersInJsonString, headers); - WasmWebService_ScheduleGetRequest(&callback, uri.c_str(), headersInJsonString.c_str(), payload); - } - - void WasmWebService::SchedulePostRequest(ICallback& callback, - const std::string& relativeUri, - const Headers& headers, - const std::string& body, - Orthanc::IDynamicObject* payload) - { - std::string uri = baseUri_ + relativeUri; - std::string headersInJsonString; - ToJsonString(headersInJsonString, headers); - WasmWebService_SchedulePostRequest(&callback, uri.c_str(), headersInJsonString.c_str(), + WasmWebService_PostAsync(successCallable, failureCallable, 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* successCallable, - MessageHandler* failureCallable) + MessageHandler* successCallable, + MessageHandler* failureCallable) { std::string uri = baseUri_ + relativeUri; std::string headersInJsonString; ToJsonString(headersInJsonString, headers); - WasmWebService_NewScheduleGetRequest(successCallable, failureCallable, uri.c_str(), headersInJsonString.c_str(), payload); + WasmWebService_GetAsync(successCallable, failureCallable, uri.c_str(), headersInJsonString.c_str(), payload); } } diff -r 4a79193ffb58 -r ed1a4302154f Platforms/Wasm/WasmWebService.h --- a/Platforms/Wasm/WasmWebService.h Tue Sep 18 18:04:53 2018 +0200 +++ b/Platforms/Wasm/WasmWebService.h Tue Sep 18 18:17:26 2018 +0200 @@ -37,22 +37,18 @@ void SetBaseUri(const std::string baseUri); - virtual void ScheduleGetRequest(ICallback& callback, - const std::string& uri, - const Headers& headers, - Orthanc::IDynamicObject* payload); - - virtual void SchedulePostRequest(ICallback& callback, - const std::string& uri, - const Headers& headers, - const std::string& body, - Orthanc::IDynamicObject* payload); - - virtual void GetAsync(const std::string& relativeUri, + virtual void GetAsync(const std::string& uri, const Headers& headers, Orthanc::IDynamicObject* payload, - MessageHandler* successCallback, - MessageHandler* failureCallback); + MessageHandler* successCallable, + MessageHandler* failureCallable); + + virtual void PostAsync(const std::string& uri, + const Headers& headers, + const std::string& body, + Orthanc::IDynamicObject* payload, + MessageHandler* successCallable, + MessageHandler* failureCallable); virtual void Start() { diff -r 4a79193ffb58 -r ed1a4302154f Platforms/Wasm/WasmWebService.js --- a/Platforms/Wasm/WasmWebService.js Tue Sep 18 18:04:53 2018 +0200 +++ b/Platforms/Wasm/WasmWebService.js Tue Sep 18 18:17:26 2018 +0200 @@ -1,36 +1,5 @@ mergeInto(LibraryManager.library, { - WasmWebService_ScheduleGetRequest: function(callback, url, headersInJsonString, payload) { - // Directly use XMLHttpRequest (no jQuery) to retrieve the raw binary data - // http://www.henryalgus.com/reading-binary-files-using-jquery-ajax/ - var xhr = new XMLHttpRequest(); - var url_ = UTF8ToString(url); - var headersInJsonString_ = UTF8ToString(headersInJsonString); - - xhr.open('GET', url_, true); - xhr.responseType = 'arraybuffer'; - var headers = JSON.parse(headersInJsonString_); - for (var key in headers) { - xhr.setRequestHeader(key, headers[key]); - } - // console.log(xhr); - xhr.onreadystatechange = function() { - if (this.readyState == XMLHttpRequest.DONE) { - if (xhr.status === 200) { - // TODO - Is "new Uint8Array()" necessary? This copies the - // answer to the WebAssembly stack, hence necessitating - // increasing the TOTAL_STACK parameter of Emscripten - WasmWebService_NotifySuccess(callback, url_, new Uint8Array(this.response), - this.response.byteLength, payload); - } else { - WasmWebService_NotifyError(callback, url_, payload); - } - } - } - - xhr.send(); - }, - - WasmWebService_NewScheduleGetRequest: function(callableSuccess, callableFailure, url, headersInJsonString, payload) { + WasmWebService_GetAsync: function(callableSuccess, callableFailure, url, headersInJsonString, payload) { // Directly use XMLHttpRequest (no jQuery) to retrieve the raw binary data // http://www.henryalgus.com/reading-binary-files-using-jquery-ajax/ var xhr = new XMLHttpRequest(); @@ -50,13 +19,10 @@ // TODO - Is "new Uint8Array()" necessary? This copies the // answer to the WebAssembly stack, hence necessitating // increasing the TOTAL_STACK parameter of Emscripten - console.log("WasmWebService success", this.response); - WasmWebService_NewNotifySuccess(callableSuccess, url_, new Uint8Array(this.response), + WasmWebService_NotifySuccess(callableSuccess, url_, new Uint8Array(this.response), this.response.byteLength, payload); - console.log("WasmWebService success 2", this.response); } else { - console.log("WasmWebService failed"); - WasmWebService_NewNotifyError(callableFailure, url_, payload); + WasmWebService_NotifyError(callableFailure, url_, payload); } } } @@ -64,7 +30,7 @@ xhr.send(); }, - WasmWebService_SchedulePostRequest: function(callback, url, headersInJsonString, body, bodySize, payload) { + WasmWebService_PostAsync: function(callableSuccess, callableFailure, url, headersInJsonString, body, bodySize, payload) { var xhr = new XMLHttpRequest(); var url_ = UTF8ToString(url); var headersInJsonString_ = UTF8ToString(headersInJsonString); @@ -80,10 +46,10 @@ xhr.onreadystatechange = function() { if (this.readyState == XMLHttpRequest.DONE) { if (xhr.status === 200) { - WasmWebService_NotifySuccess(callback, url_, new Uint8Array(this.response), + WasmWebService_NotifySuccess(callableSuccess, url_, new Uint8Array(this.response), this.response.byteLength, payload); } else { - WasmWebService_NotifyError(callback, url_, payload); + WasmWebService_NotifyError(callableFailure, url_, payload); } } } diff -r 4a79193ffb58 -r ed1a4302154f Platforms/Wasm/wasm-application-runner.ts --- a/Platforms/Wasm/wasm-application-runner.ts Tue Sep 18 18:04:53 2018 +0200 +++ b/Platforms/Wasm/wasm-application-runner.ts Tue Sep 18 18:17:26 2018 +0200 @@ -10,8 +10,6 @@ // global functions var WasmWebService_NotifyError: Function = null; var WasmWebService_NotifySuccess: Function = null; -var WasmWebService_NewNotifyError: Function = null; -var WasmWebService_NewNotifySuccess: Function = null; var WasmWebService_SetBaseUri: Function = null; var NotifyUpdateContent: Function = null; var SetStartupParameter: Function = null; @@ -97,8 +95,6 @@ WasmWebService_NotifySuccess = StoneFrameworkModule.cwrap('WasmWebService_NotifySuccess', null, ['number', 'string', 'array', 'number', 'number']); WasmWebService_NotifyError = StoneFrameworkModule.cwrap('WasmWebService_NotifyError', null, ['number', 'string', 'number']); - WasmWebService_NewNotifySuccess = StoneFrameworkModule.cwrap('WasmWebService_NewNotifySuccess', null, ['number', 'string', 'array', 'number', 'number']); - WasmWebService_NewNotifyError = StoneFrameworkModule.cwrap('WasmWebService_NewNotifyError', null, ['number', 'string', 'number']); WasmWebService_SetBaseUri = StoneFrameworkModule.cwrap('WasmWebService_SetBaseUri', null, ['string']); NotifyUpdateContent = StoneFrameworkModule.cwrap('NotifyUpdateContent', null, []);