Mercurial > hg > orthanc-stone
changeset 418:c23df8b3433b
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 15 Nov 2018 18:32:48 +0100 |
parents | aee3d7941c9b |
children | d638d5721f1c |
files | Applications/Generic/NativeStoneApplicationContext.cpp Applications/Generic/NativeStoneApplicationContext.h Applications/Generic/NativeStoneApplicationRunner.cpp Applications/Samples/SingleFrameEditorApplication.h Applications/StoneApplicationContext.cpp Applications/StoneApplicationContext.h Framework/Radiography/RadiographyScene.cpp Framework/Toolbox/OrthancApiClient.cpp Platforms/Wasm/Defaults.cpp Platforms/Wasm/WasmWebService.cpp Platforms/Wasm/WasmWebService.h Platforms/Wasm/wasm-application-runner.ts |
diffstat | 12 files changed, 93 insertions(+), 61 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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);
--- 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);
--- 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 <Core/HttpClient.h> #include <Core/Images/FontRegistry.h> #include <Core/Logging.h> #include <Core/OrthancException.h> @@ -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()); {
--- 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(); + } } }
--- 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<OrthancApiClient> 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); }; }
--- 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()); + } } }
--- 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<IWebService::HttpRequestErrorMessage>* 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<OrthancApiClient, IWebService::HttpRequestSuccessMessage>
--- 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();
--- 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<IWebService::HttpRequestErrorMessage>* 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<IWebService::HttpRequestErrorMessage>* 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<IWebService::HttpRequestErrorMessage>* 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); } }
--- 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,
--- 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']);