Mercurial > hg > orthanc-stone
changeset 1242:b9b5d4378874 broker
working of WebAssemblyOracle
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 06 Jan 2020 18:08:05 +0100 |
parents | a4bb8c2dd211 |
children | 608983cc2512 |
files | Framework/Fonts/GlyphTextureAlphabet.cpp Framework/Loaders/GenericLoadersContext.cpp Framework/Loaders/GenericLoadersContext.h Framework/Loaders/ILoadersContext.h Framework/Loaders/SeriesFramesLoader.h Framework/Oracle/WebAssemblyOracle.cpp Framework/Oracle/WebAssemblyOracle.h Framework/Toolbox/ParsedDicomCache.cpp Framework/Viewport/WebGLViewportsRegistry.cpp Framework/Viewport/WebGLViewportsRegistry.h |
diffstat | 10 files changed, 96 insertions(+), 53 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Fonts/GlyphTextureAlphabet.cpp Mon Dec 30 10:54:26 2019 +0100 +++ b/Framework/Fonts/GlyphTextureAlphabet.cpp Mon Jan 06 18:08:05 2020 +0100 @@ -28,7 +28,7 @@ #include <Core/Images/ImageProcessing.h> #include <Core/OrthancException.h> -#ifdef __EMSCRIPTEN__ +#if defined(__EMSCRIPTEN__) /* Avoid this error: .../boost/math/special_functions/round.hpp:86:12: warning: implicit conversion from 'std::__2::numeric_limits<int>::type' (aka 'int') to 'float' changes value from 2147483647 to 2147483648 [-Wimplicit-int-float-conversion]
--- a/Framework/Loaders/GenericLoadersContext.cpp Mon Dec 30 10:54:26 2019 +0100 +++ b/Framework/Loaders/GenericLoadersContext.cpp Mon Jan 06 18:08:05 2020 +0100 @@ -171,6 +171,7 @@ uint64_t& processedCommands) { boost::recursive_mutex::scoped_lock lock(mutex_); + if (scheduler_) { scheduledCommands = scheduler_->GetTotalScheduled(); @@ -178,8 +179,7 @@ } else { - scheduledCommands = 0; - processedCommands = 0; + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); } } }
--- a/Framework/Loaders/GenericLoadersContext.h Mon Dec 30 10:54:26 2019 +0100 +++ b/Framework/Loaders/GenericLoadersContext.h Mon Jan 06 18:08:05 2020 +0100 @@ -60,7 +60,7 @@ public: GenericLoadersContext(unsigned int maxHighPriority, - unsigned int maxStandardPriority, + unsigned int maxStandardPriority, unsigned int maxLowPriority); virtual ~GenericLoadersContext();
--- a/Framework/Loaders/ILoadersContext.h Mon Dec 30 10:54:26 2019 +0100 +++ b/Framework/Loaders/ILoadersContext.h Mon Jan 06 18:08:05 2020 +0100 @@ -101,6 +101,10 @@ virtual void AddLoader(boost::shared_ptr<IObserver> loader) = 0; }; + virtual ~ILoadersContext() + { + } + /** * Locks the Stone loaders context, to give access to its * underlying features. This is important for Stone applications
--- a/Framework/Loaders/SeriesFramesLoader.h Mon Dec 30 10:54:26 2019 +0100 +++ b/Framework/Loaders/SeriesFramesLoader.h Mon Jan 06 18:08:05 2020 +0100 @@ -39,7 +39,7 @@ private: class Payload; - ILoadersContext& context_; + ILoadersContext& context_; SeriesOrderedFrames frames_; std::string dicomDirPath_; boost::shared_ptr<LoadedDicomResources> dicomDir_;
--- a/Framework/Oracle/WebAssemblyOracle.cpp Mon Dec 30 10:54:26 2019 +0100 +++ b/Framework/Oracle/WebAssemblyOracle.cpp Mon Jan 06 18:08:05 2020 +0100 @@ -338,6 +338,9 @@ HttpHeaders headers_; unsigned int timeout_; std::string expectedContentType_; + bool hasCredentials_; + std::string username_; + std::string password_; public: FetchCommand(WebAssemblyOracle& oracle, @@ -347,7 +350,8 @@ receiver_(receiver), command_(command), method_(Orthanc::HttpMethod_Get), - timeout_(0) + timeout_(0), + hasCredentials_(false) { if (command == NULL) { @@ -360,11 +364,6 @@ method_ = method; } - void SetOrthancUri(const std::string& uri) - { - url_ = oracle_.orthancRoot_ + uri; - } - void SetUrl(const std::string& url) { url_ = url; @@ -375,9 +374,12 @@ body_.swap(body); } - void SetHttpHeaders(const HttpHeaders& headers) + void AddHttpHeaders(const HttpHeaders& headers) { - headers_ = headers; + for (HttpHeaders::const_iterator it = headers.begin(); it != headers.end(); ++it) + { + headers_[it->first] = it->second; + } } void SetTimeout(unsigned int timeout) @@ -385,6 +387,14 @@ timeout_ = timeout; } + void SetCredentials(const std::string& username, + const std::string& password) + { + hasCredentials_ = true; + username_ = username; + password_ = password; + } + void Execute() { #if 0 @@ -435,6 +445,13 @@ attr.onerror = FetchContext::FailureCallback; attr.timeoutMSecs = timeout_ * 1000; + if (hasCredentials_) + { + attr.withCredentials = EM_TRUE; + attr.userName = username_.c_str(); + attr.password = password_.c_str(); + } + std::vector<const char*> headers; headers.reserve(2 * headers_.size() + 1); @@ -510,6 +527,26 @@ #endif + void WebAssemblyOracle::SetOrthancUrl(FetchCommand& command, + const std::string& uri) const + { + if (isLocalOrthanc_) + { + command.SetUrl(localOrthancRoot_ + uri); + } + else + { + command.SetUrl(remoteOrthanc_.GetUrl() + uri); + command.AddHttpHeaders(remoteOrthanc_.GetHttpHeaders()); + + if (!remoteOrthanc_.GetUsername().empty()) + { + command.SetCredentials(remoteOrthanc_.GetUsername(), remoteOrthanc_.GetPassword()); + } + } + } + + void WebAssemblyOracle::Execute(boost::weak_ptr<IObserver> receiver, HttpCommand* command) { @@ -517,7 +554,7 @@ fetch.SetMethod(command->GetMethod()); fetch.SetUrl(command->GetUrl()); - fetch.SetHttpHeaders(command->GetHttpHeaders()); + fetch.AddHttpHeaders(command->GetHttpHeaders()); fetch.SetTimeout(command->GetTimeout()); if (command->GetMethod() == Orthanc::HttpMethod_Post || @@ -552,8 +589,8 @@ FetchCommand fetch(*this, receiver, command); fetch.SetMethod(command->GetMethod()); - fetch.SetOrthancUri(command->GetUri()); - fetch.SetHttpHeaders(command->GetHttpHeaders()); + SetOrthancUrl(fetch, command->GetUri()); + fetch.AddHttpHeaders(command->GetHttpHeaders()); fetch.SetTimeout(command->GetTimeout()); if (command->GetMethod() == Orthanc::HttpMethod_Post || @@ -608,8 +645,8 @@ FetchCommand fetch(*this, receiver, command); - fetch.SetOrthancUri(command->GetUri()); - fetch.SetHttpHeaders(command->GetHttpHeaders()); + SetOrthancUrl(fetch, command->GetUri()); + fetch.AddHttpHeaders(command->GetHttpHeaders()); fetch.SetTimeout(command->GetTimeout()); fetch.Execute(); @@ -628,8 +665,8 @@ FetchCommand fetch(*this, receiver, command); - fetch.SetOrthancUri(command->GetUri()); - fetch.SetHttpHeaders(command->GetHttpHeaders()); + SetOrthancUrl(fetch, command->GetUri()); + fetch.AddHttpHeaders(command->GetHttpHeaders()); fetch.SetTimeout(command->GetTimeout()); fetch.Execute();
--- a/Framework/Oracle/WebAssemblyOracle.h Mon Dec 30 10:54:26 2019 +0100 +++ b/Framework/Oracle/WebAssemblyOracle.h Mon Jan 06 18:08:05 2020 +0100 @@ -36,12 +36,13 @@ #include "IOracle.h" #include "OrthancRestApiCommand.h" +#include <Core/WebServiceParameters.h> + namespace OrthancStone { class WebAssemblyOracle : public IOracle, - public IObservable, public IMessageEmitter { private: @@ -49,7 +50,10 @@ class TimeoutContext; class FetchContext; - class FetchCommand; + class FetchCommand; + + void SetOrthancUrl(FetchCommand& command, + const std::string& uri) const; void Execute(boost::weak_ptr<IObserver> receiver, HttpCommand* command); @@ -63,10 +67,17 @@ void Execute(boost::weak_ptr<IObserver> receiver, GetOrthancWebViewerJpegCommand* command); - IObservable oracleObservable_; - std::string orthancRoot_; + IObservable oracleObservable_; + bool isLocalOrthanc_; + std::string localOrthancRoot_; + Orthanc::WebServiceParameters remoteOrthanc_; public: + WebAssemblyOracle() : + isLocalOrthanc_(false) + { + } + virtual void EmitMessage(boost::weak_ptr<IObserver> observer, const IMessage& message) ORTHANC_OVERRIDE { @@ -81,9 +92,16 @@ return oracleObservable_; } - void SetOrthancRoot(const std::string& root) + void SetLocalOrthanc(const std::string& root) { - orthancRoot_ = root; + isLocalOrthanc_ = true; + localOrthancRoot_ = root; + } + + void SetRemoteOrthanc(const Orthanc::WebServiceParameters& orthanc) + { + isLocalOrthanc_ = false; + remoteOrthanc_ = orthanc; } }; }
--- a/Framework/Toolbox/ParsedDicomCache.cpp Mon Dec 30 10:54:26 2019 +0100 +++ b/Framework/Toolbox/ParsedDicomCache.cpp Mon Jan 06 18:08:05 2020 +0100 @@ -26,7 +26,6 @@ class ParsedDicomCache::Item : public Orthanc::ICacheable { private: - boost::mutex mutex_; std::auto_ptr<Orthanc::ParsedDicomFile> dicom_; size_t fileSize_; bool hasPixelData_; @@ -44,11 +43,6 @@ throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); } } - - boost::mutex& GetMutex() - { - return mutex_; - } virtual size_t GetMemoryUsage() const {
--- a/Framework/Viewport/WebGLViewportsRegistry.cpp Mon Dec 30 10:54:26 2019 +0100 +++ b/Framework/Viewport/WebGLViewportsRegistry.cpp Mon Jan 06 18:08:05 2020 +0100 @@ -23,6 +23,8 @@ #include <Core/OrthancException.h> +#include <boost/make_shared.hpp> + namespace OrthancStone { void WebGLViewportsRegistry::LaunchTimer() @@ -58,16 +60,15 @@ // At this point, the old canvas is removed from the DOM and // replaced by a fresh one with the same ID: Recreate the // WebGL context on the new canvas - std::auto_ptr<WebGLViewport> viewport; + boost::shared_ptr<WebGLViewport> viewport; { std::auto_ptr<IViewport::ILock> lock(it->second->Lock()); - viewport.reset(new WebGLViewport(it->first, lock->GetController().GetScene())); + viewport = boost::make_shared<WebGLViewport>(it->first, lock->GetController().GetScene()); } // Replace the old WebGL viewport by the new one - delete it->second; - it->second = viewport.release(); + it->second = viewport; // Tag the fresh canvas as needing a repaint { @@ -100,7 +101,7 @@ } - void WebGLViewportsRegistry::Add(const std::string& canvasId) + boost::shared_ptr<WebGLViewport> WebGLViewportsRegistry::Add(const std::string& canvasId) { if (viewports_.find(canvasId) != viewports_.end()) { @@ -109,7 +110,9 @@ } else { - viewports_[canvasId] = new WebGLViewport(canvasId); + boost::shared_ptr<WebGLViewport> viewport(new WebGLViewport(canvasId)); + viewports_[canvasId] = viewport; + return viewport; } } @@ -124,11 +127,6 @@ } else { - if (found->second != NULL) - { - delete found->second; - } - viewports_.erase(found); } } @@ -136,14 +134,6 @@ void WebGLViewportsRegistry::Clear() { - for (Viewports::iterator it = viewports_.begin(); it != viewports_.end(); ++it) - { - if (it->second != NULL) - { - delete it->second; - } - } - viewports_.clear(); }
--- a/Framework/Viewport/WebGLViewportsRegistry.h Mon Dec 30 10:54:26 2019 +0100 +++ b/Framework/Viewport/WebGLViewportsRegistry.h Mon Jan 06 18:08:05 2020 +0100 @@ -36,7 +36,7 @@ class WebGLViewportsRegistry : public boost::noncopyable { private: - typedef std::map<std::string, WebGLViewport*> Viewports; + typedef std::map<std::string, boost::shared_ptr<WebGLViewport> > Viewports; double timeoutMS_; Viewports viewports_; @@ -55,7 +55,7 @@ Clear(); } - void Add(const std::string& canvasId); + boost::shared_ptr<WebGLViewport> Add(const std::string& canvasId); void Remove(const std::string& canvasId);