# HG changeset patch # User Sebastien Jodogne # Date 1578330485 -3600 # Node ID b9b5d4378874a1c3501440ca5b97262345833072 # Parent a4bb8c2dd21192c52c9aec06eed4fdafe0abb404 working of WebAssemblyOracle diff -r a4bb8c2dd211 -r b9b5d4378874 Framework/Fonts/GlyphTextureAlphabet.cpp --- 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 #include -#ifdef __EMSCRIPTEN__ +#if defined(__EMSCRIPTEN__) /* Avoid this error: .../boost/math/special_functions/round.hpp:86:12: warning: implicit conversion from 'std::__2::numeric_limits::type' (aka 'int') to 'float' changes value from 2147483647 to 2147483648 [-Wimplicit-int-float-conversion] diff -r a4bb8c2dd211 -r b9b5d4378874 Framework/Loaders/GenericLoadersContext.cpp --- 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); } } } diff -r a4bb8c2dd211 -r b9b5d4378874 Framework/Loaders/GenericLoadersContext.h --- 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(); diff -r a4bb8c2dd211 -r b9b5d4378874 Framework/Loaders/ILoadersContext.h --- 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 loader) = 0; }; + virtual ~ILoadersContext() + { + } + /** * Locks the Stone loaders context, to give access to its * underlying features. This is important for Stone applications diff -r a4bb8c2dd211 -r b9b5d4378874 Framework/Loaders/SeriesFramesLoader.h --- 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 dicomDir_; diff -r a4bb8c2dd211 -r b9b5d4378874 Framework/Oracle/WebAssemblyOracle.cpp --- 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 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 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(); diff -r a4bb8c2dd211 -r b9b5d4378874 Framework/Oracle/WebAssemblyOracle.h --- 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 + 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 receiver, HttpCommand* command); @@ -63,10 +67,17 @@ void Execute(boost::weak_ptr 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 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; } }; } diff -r a4bb8c2dd211 -r b9b5d4378874 Framework/Toolbox/ParsedDicomCache.cpp --- 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 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 { diff -r a4bb8c2dd211 -r b9b5d4378874 Framework/Viewport/WebGLViewportsRegistry.cpp --- 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 +#include + 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 viewport; + boost::shared_ptr viewport; { std::auto_ptr lock(it->second->Lock()); - viewport.reset(new WebGLViewport(it->first, lock->GetController().GetScene())); + viewport = boost::make_shared(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 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 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(); } diff -r a4bb8c2dd211 -r b9b5d4378874 Framework/Viewport/WebGLViewportsRegistry.h --- 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 Viewports; + typedef std::map > Viewports; double timeoutMS_; Viewports viewports_; @@ -55,7 +55,7 @@ Clear(); } - void Add(const std::string& canvasId); + boost::shared_ptr Add(const std::string& canvasId); void Remove(const std::string& canvasId);