# HG changeset patch # User Sebastien Jodogne # Date 1542303168 -3600 # Node ID c23df8b3433b046ce5433765ab410db4cfe1c101 # Parent aee3d7941c9b80c01e8d68100f544199838670e6 refactoring diff -r aee3d7941c9b -r c23df8b3433b Applications/Generic/NativeStoneApplicationContext.cpp --- a/Applications/Generic/NativeStoneApplicationContext.cpp Thu Nov 15 17:28:15 2018 +0100 +++ b/Applications/Generic/NativeStoneApplicationContext.cpp Thu Nov 15 18:32:48 2018 +0100 @@ -46,7 +46,7 @@ NativeStoneApplicationContext::NativeStoneApplicationContext(MessageBroker& broker) : - broker_(broker), + StoneApplicationContext(broker), centralViewport_(broker), stopped_(true), updateDelayInMs_(100) // By default, 100ms between each refresh of the content diff -r aee3d7941c9b -r c23df8b3433b Applications/Generic/NativeStoneApplicationContext.h --- a/Applications/Generic/NativeStoneApplicationContext.h Thu Nov 15 17:28:15 2018 +0100 +++ b/Applications/Generic/NativeStoneApplicationContext.h Thu Nov 15 18:32:48 2018 +0100 @@ -37,7 +37,6 @@ static void UpdateThread(NativeStoneApplicationContext* that); boost::mutex globalMutex_; - MessageBroker& broker_; WidgetViewport centralViewport_; boost::thread updateThread_; bool stopped_; @@ -59,11 +58,6 @@ IWidget& SetCentralWidget(IWidget* widget); // Takes ownership - MessageBroker& GetMessageBroker() const - { - return that_.broker_; - } - IViewport& GetCentralViewport() { return that_.centralViewport_; @@ -73,6 +67,11 @@ { that_.updateDelayInMs_ = delayInMs; } + + MessageBroker& GetMessageBroker() + { + return that_.GetMessageBroker(); + } }; NativeStoneApplicationContext(MessageBroker& broker); diff -r aee3d7941c9b -r c23df8b3433b Applications/Generic/NativeStoneApplicationRunner.cpp --- a/Applications/Generic/NativeStoneApplicationRunner.cpp Thu Nov 15 17:28:15 2018 +0100 +++ b/Applications/Generic/NativeStoneApplicationRunner.cpp Thu Nov 15 18:32:48 2018 +0100 @@ -193,7 +193,8 @@ { OracleWebService webService(broker_, oracle, webServiceParameters, context); - context.Initialize(broker_, webService, webServiceParameters.GetUrl()); + context.SetWebService(webService); + context.SetOrthancBaseUrl(webServiceParameters.GetUrl()); application_.Initialize(&context, statusBar, parameters); diff -r aee3d7941c9b -r c23df8b3433b Applications/Samples/SingleFrameEditorApplication.h --- a/Applications/Samples/SingleFrameEditorApplication.h Thu Nov 15 17:28:15 2018 +0100 +++ b/Applications/Samples/SingleFrameEditorApplication.h Thu Nov 15 18:32:48 2018 +0100 @@ -32,6 +32,7 @@ #include "../../Framework/Radiography/RadiographyWidget.h" #include "../../Framework/Radiography/RadiographyWindowingTracker.h" +#include #include #include #include @@ -445,6 +446,11 @@ scene_.reset(new RadiographyScene(GetBroker())); //scene_->LoadDicomFrame(instance, frame, false); //.SetPan(200, 0); scene_->LoadDicomFrame(context->GetOrthancApiClient(), "61f3143e-96f34791-ad6bbb8d-62559e75-45943e1b", 0, false); + +#if !defined(ORTHANC_ENABLE_WASM) || ORTHANC_ENABLE_WASM != 1 + Orthanc::HttpClient::ConfigureSsl(true, "/etc/ssl/certs/ca-certificates.crt"); +#endif + //scene_->LoadDicomWebFrame(context->GetWebService()); { diff -r aee3d7941c9b -r c23df8b3433b Applications/StoneApplicationContext.cpp --- a/Applications/StoneApplicationContext.cpp Thu Nov 15 17:28:15 2018 +0100 +++ b/Applications/StoneApplicationContext.cpp Thu Nov 15 18:32:48 2018 +0100 @@ -25,31 +25,62 @@ namespace OrthancStone { + void StoneApplicationContext::InitializeOrthanc() + { + if (webService_ == NULL) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); + } + + orthanc_.reset(new OrthancApiClient(broker_, *webService_, orthancBaseUrl_)); + } + + IWebService& StoneApplicationContext::GetWebService() { if (webService_ == NULL) { - throw Orthanc::ErrorCode_BadSequenceOfCalls; + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); } return *webService_; } + OrthancApiClient& StoneApplicationContext::GetOrthancApiClient() { if (orthanc_.get() == NULL) { - throw Orthanc::ErrorCode_BadSequenceOfCalls; + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); } return *orthanc_; } - void StoneApplicationContext::Initialize(MessageBroker& broker, - IWebService& webService, - const std::string& orthancBaseUrl) + + void StoneApplicationContext::SetWebService(IWebService& webService) { webService_ = &webService; - orthanc_.reset(new OrthancApiClient(broker, webService, orthancBaseUrl)); + InitializeOrthanc(); + } + + + void StoneApplicationContext::SetOrthancBaseUrl(const std::string& baseUrl) + { + // Make sure the base url ends with "/" + if (baseUrl.empty() || + baseUrl[baseUrl.size() - 1] != '/') + { + orthancBaseUrl_ = baseUrl + "/"; + } + else + { + orthancBaseUrl_ = baseUrl; + } + + if (webService_ != NULL) + { + InitializeOrthanc(); + } } } diff -r aee3d7941c9b -r c23df8b3433b Applications/StoneApplicationContext.h --- a/Applications/StoneApplicationContext.h Thu Nov 15 17:28:15 2018 +0100 +++ b/Applications/StoneApplicationContext.h Thu Nov 15 18:32:48 2018 +0100 @@ -38,14 +38,17 @@ class StoneApplicationContext : public boost::noncopyable { - protected: - // TODO ADD THE MessageBroker HERE - + private: + MessageBroker& broker_; IWebService* webService_; std::auto_ptr orthanc_; + std::string orthancBaseUrl_; + + void InitializeOrthanc(); public: - StoneApplicationContext() : + StoneApplicationContext(MessageBroker& broker) : + broker_(broker), webService_(NULL) { } @@ -54,12 +57,22 @@ { } + MessageBroker& GetMessageBroker() + { + return broker_; + } + + bool HasWebService() const + { + return webService_ != NULL; + } + IWebService& GetWebService(); OrthancApiClient& GetOrthancApiClient(); - void Initialize(MessageBroker& broker, - IWebService& webService, - const std::string& orthancBaseUrl); + void SetWebService(IWebService& webService); + + void SetOrthancBaseUrl(const std::string& baseUrl); }; } diff -r aee3d7941c9b -r c23df8b3433b Framework/Radiography/RadiographyScene.cpp --- a/Framework/Radiography/RadiographyScene.cpp Thu Nov 15 17:28:15 2018 +0100 +++ b/Framework/Radiography/RadiographyScene.cpp Thu Nov 15 18:32:48 2018 +0100 @@ -858,6 +858,13 @@ void RadiographyScene::OnDicomWebReceived(const IWebService::HttpRequestSuccessMessage& message) { LOG(INFO) << "DICOMweb WADO-RS received: " << message.GetAnswerSize() << " bytes"; + + const IWebService::HttpHeaders& h = message.GetAnswerHttpHeaders(); + for (IWebService::HttpHeaders::const_iterator + it = h.begin(); it != h.end(); ++it) + { + printf("[%s] = [%s]\n", it->first.c_str(), it->second.c_str()); + } } } diff -r aee3d7941c9b -r c23df8b3433b Framework/Toolbox/OrthancApiClient.cpp --- a/Framework/Toolbox/OrthancApiClient.cpp Thu Nov 15 17:28:15 2018 +0100 +++ b/Framework/Toolbox/OrthancApiClient.cpp Thu Nov 15 18:32:48 2018 +0100 @@ -214,6 +214,8 @@ MessageHandler* failureCallback, Orthanc::IDynamicObject* payload) { + printf("GET [%s] [%s]\n", baseUrl_.c_str(), uri.c_str()); + web_.GetAsync(baseUrl_ + uri, headers, new WebServicePayload(successCallback, failureCallback, payload), new Callable diff -r aee3d7941c9b -r c23df8b3433b Platforms/Wasm/Defaults.cpp --- a/Platforms/Wasm/Defaults.cpp Thu Nov 15 17:28:15 2018 +0100 +++ b/Platforms/Wasm/Defaults.cpp Thu Nov 15 18:32:48 2018 +0100 @@ -82,7 +82,7 @@ startupParametersBuilder.SetStartupParameter(keyc, value); } - void EMSCRIPTEN_KEEPALIVE StartWasmApplication() { + void EMSCRIPTEN_KEEPALIVE StartWasmApplication(const char* baseUri) { printf("StartWasmApplication\n"); @@ -92,8 +92,10 @@ application->DeclareStartupOptions(options); startupParametersBuilder.GetStartupParameters(parameters, options); - context.reset(new OrthancStone::StoneApplicationContext()); - context->Initialize(broker, OrthancStone::WasmWebService::GetInstance(), ""); + context.reset(new OrthancStone::StoneApplicationContext(broker)); + context->SetOrthancBaseUrl(baseUri); + printf("Base URL to Orthanc API: [%s]\n", baseUri); + context->SetWebService(OrthancStone::WasmWebService::GetInstance()); application->Initialize(context.get(), statusBar_, parameters); application->InitializeWasm(); diff -r aee3d7941c9b -r c23df8b3433b Platforms/Wasm/WasmWebService.cpp --- a/Platforms/Wasm/WasmWebService.cpp Thu Nov 15 17:28:15 2018 +0100 +++ b/Platforms/Wasm/WasmWebService.cpp Thu Nov 15 18:32:48 2018 +0100 @@ -69,11 +69,6 @@ } } - void EMSCRIPTEN_KEEPALIVE WasmWebService_SetBaseUri(const char* baseUri) - { - OrthancStone::WasmWebService::GetInstance().SetBaseUri(baseUri); - } - #ifdef __cplusplus } #endif @@ -84,20 +79,6 @@ { MessageBroker* WasmWebService::broker_ = NULL; - void WasmWebService::SetBaseUri(const std::string baseUri) - { - // Make sure the base url ends with "/" - if (baseUri.empty() || - baseUri[baseUri.size() - 1] != '/') - { - baseUri_ = baseUri + "/"; - } - else - { - baseUri_ = baseUri; - } - } - void ToJsonString(std::string& output, const IWebService::HttpHeaders& headers) { Json::Value jsonHeaders; @@ -122,10 +103,9 @@ MessageHandler* failureCallable, unsigned int timeoutInSeconds) { - std::string uri = baseUri_ + relativeUri; std::string headersInJsonString; ToJsonString(headersInJsonString, headers); - WasmWebService_PostAsync(successCallable, failureCallable, uri.c_str(), headersInJsonString.c_str(), + WasmWebService_PostAsync(successCallable, failureCallable, relativeUri.c_str(), headersInJsonString.c_str(), body.c_str(), body.size(), payload, timeoutInSeconds); } @@ -136,10 +116,9 @@ MessageHandler* failureCallable, unsigned int timeoutInSeconds) { - std::string uri = baseUri_ + relativeUri; std::string headersInJsonString; ToJsonString(headersInJsonString, headers); - WasmWebService_DeleteAsync(successCallable, failureCallable, uri.c_str(), headersInJsonString.c_str(), + WasmWebService_DeleteAsync(successCallable, failureCallable, relativeUri.c_str(), headersInJsonString.c_str(), payload, timeoutInSeconds); } @@ -150,9 +129,9 @@ MessageHandler* failureCallable, unsigned int timeoutInSeconds) { - std::string uri = baseUri_ + relativeUri; std::string headersInJsonString; ToJsonString(headersInJsonString, headers); - WasmWebService_GetAsync(successCallable, failureCallable, uri.c_str(), headersInJsonString.c_str(), payload, timeoutInSeconds); + WasmWebService_GetAsync(successCallable, failureCallable, relativeUri.c_str(), + headersInJsonString.c_str(), payload, timeoutInSeconds); } } diff -r aee3d7941c9b -r c23df8b3433b Platforms/Wasm/WasmWebService.h --- a/Platforms/Wasm/WasmWebService.h Thu Nov 15 17:28:15 2018 +0100 +++ b/Platforms/Wasm/WasmWebService.h Thu Nov 15 18:32:48 2018 +0100 @@ -8,13 +8,11 @@ class WasmWebService : public IWebService { private: - std::string baseUri_; static MessageBroker* broker_; // Private constructor => Singleton design pattern WasmWebService(MessageBroker& broker) : - IWebService(broker), - baseUri_("../../") // note: this is configurable from the JS code by calling WasmWebService_SetBaseUri + IWebService(broker) { } @@ -35,8 +33,6 @@ broker_ = &broker; } - void SetBaseUri(const std::string baseUri); - virtual void GetAsync(const std::string& uri, const HttpHeaders& headers, Orthanc::IDynamicObject* payload, diff -r aee3d7941c9b -r c23df8b3433b Platforms/Wasm/wasm-application-runner.ts --- a/Platforms/Wasm/wasm-application-runner.ts Thu Nov 15 17:28:15 2018 +0100 +++ b/Platforms/Wasm/wasm-application-runner.ts Thu Nov 15 18:32:48 2018 +0100 @@ -10,7 +10,6 @@ // global functions var WasmWebService_NotifyError: Function = null; var WasmWebService_NotifySuccess: Function = null; -var WasmWebService_SetBaseUri: Function = null; var WasmDoAnimation: Function = null; var SetStartupParameter: Function = null; var CreateWasmApplication: Function = null; @@ -58,8 +57,6 @@ function _InitializeWasmApplication(orthancBaseUrl: string): void { CreateWasmApplication(); - WasmWebService_SetBaseUri(orthancBaseUrl); - // parse uri and transmit the parameters to the app before initializing it let parameters = GetUriParameters(); @@ -70,9 +67,9 @@ } } - StartWasmApplication(); + StartWasmApplication(orthancBaseUrl); - // trigger a first resize of the canvas that have just been initialized + // trigger a first resize of the canvas that has just been initialized Stone.WasmViewport.ResizeAll(); DoAnimationThread(); @@ -92,11 +89,10 @@ CreateWasmApplication = StoneFrameworkModule.cwrap('CreateWasmApplication', null, ['number']); CreateCppViewport = StoneFrameworkModule.cwrap('CreateCppViewport', 'number', []); ReleaseCppViewport = StoneFrameworkModule.cwrap('ReleaseCppViewport', null, ['number']); - StartWasmApplication = StoneFrameworkModule.cwrap('StartWasmApplication', null, ['number']); + StartWasmApplication = StoneFrameworkModule.cwrap('StartWasmApplication', null, ['string']); WasmWebService_NotifySuccess = StoneFrameworkModule.cwrap('WasmWebService_NotifySuccess', null, ['number', 'string', 'array', 'number', 'number']); WasmWebService_NotifyError = StoneFrameworkModule.cwrap('WasmWebService_NotifyError', null, ['number', 'string', 'number']); - WasmWebService_SetBaseUri = StoneFrameworkModule.cwrap('WasmWebService_SetBaseUri', null, ['string']); WasmDoAnimation = StoneFrameworkModule.cwrap('WasmDoAnimation', null, []); SendMessageToStoneApplication = StoneFrameworkModule.cwrap('SendMessageToStoneApplication', 'string', ['string']);