# HG changeset patch # User Sebastien Jodogne # Date 1543500992 -3600 # Node ID e292798f99805da9983294a6b354f1c0ca3edc3b # Parent 4767d36679ed9cc7455f1136b1b6f9bce5094b13 OrthancConfiguration::SetServerIndex() diff -r 4767d36679ed -r e292798f9980 OrthancServer/OrthancConfiguration.cpp --- a/OrthancServer/OrthancConfiguration.cpp Thu Nov 29 11:47:00 2018 +0100 +++ b/OrthancServer/OrthancConfiguration.cpp Thu Nov 29 15:16:32 2018 +0100 @@ -40,6 +40,8 @@ #include "../Core/SystemToolbox.h" #include "../Core/Toolbox.h" +#include "ServerIndex.h" + namespace Orthanc { static void AddFileToConfiguration(Json::Value& target, @@ -717,4 +719,16 @@ return a != b; } + + + void OrthancConfiguration::SetServerIndex(ServerIndex& index) + { + serverIndex_ = &index; + } + + + void OrthancConfiguration::ResetServerIndex() + { + serverIndex_ = NULL; + } } diff -r 4767d36679ed -r e292798f9980 OrthancServer/OrthancConfiguration.h --- a/OrthancServer/OrthancConfiguration.h Thu Nov 29 11:47:00 2018 +0100 +++ b/OrthancServer/OrthancConfiguration.h Thu Nov 29 15:16:32 2018 +0100 @@ -46,6 +46,7 @@ namespace Orthanc { class MongooseServer; + class ServerIndex; class OrthancConfiguration : public boost::noncopyable { @@ -56,6 +57,7 @@ std::string configurationAbsolutePath_; FontRegistry fontRegistry_; const char* configurationFileArg_; + ServerIndex* serverIndex_; OrthancConfiguration() : configurationFileArg_(NULL) @@ -201,5 +203,9 @@ void SetDefaultEncoding(Encoding encoding); bool HasConfigurationChanged() const; + + void SetServerIndex(ServerIndex& index); + + void ResetServerIndex(); }; } diff -r 4767d36679ed -r e292798f9980 OrthancServer/main.cpp --- a/OrthancServer/main.cpp Thu Nov 29 11:47:00 2018 +0100 +++ b/OrthancServer/main.cpp Thu Nov 29 15:16:32 2018 +0100 @@ -1031,6 +1031,54 @@ } + +namespace +{ + class ServerContextConfigurator : public boost::noncopyable + { + private: + ServerContext& context_; + OrthancPlugins* plugins_; + + public: + ServerContextConfigurator(ServerContext& context, + OrthancPlugins* plugins) : + context_(context), + plugins_(plugins) + { + { + OrthancConfiguration::WriterLock lock; + lock.GetConfiguration().SetServerIndex(context.GetIndex()); + } + +#if ORTHANC_ENABLE_PLUGINS == 1 + if (plugins_ != NULL) + { + plugins_->SetServerContext(context_); + context_.SetPlugins(*plugins_); + } +#endif + } + + ~ServerContextConfigurator() + { + { + OrthancConfiguration::WriterLock lock; + lock.GetConfiguration().ResetServerIndex(); + } + +#if ORTHANC_ENABLE_PLUGINS == 1 + if (plugins_ != NULL) + { + plugins_->ResetServerContext(); + context_.ResetPlugins(); + } +#endif + } + }; +} + + static bool ConfigureServerContext(IDatabaseWrapper& database, IStorageArea& storageArea, OrthancPlugins *plugins, @@ -1081,41 +1129,10 @@ (lock.GetConfiguration().GetUnsignedIntegerParameter("JobsHistorySize", 10)); } - -#if ORTHANC_ENABLE_PLUGINS == 1 - if (plugins) { - plugins->SetServerContext(context); - context.SetPlugins(*plugins); - } -#endif - - bool restart = false; - ErrorCode error = ErrorCode_Success; - - try - { - restart = ConfigureHttpHandler(context, plugins, loadJobsFromDatabase); + ServerContextConfigurator configurator(context, plugins); + return ConfigureHttpHandler(context, plugins, loadJobsFromDatabase); } - catch (OrthancException& e) - { - error = e.GetErrorCode(); - } - -#if ORTHANC_ENABLE_PLUGINS == 1 - if (plugins) - { - plugins->ResetServerContext(); - context.ResetPlugins(); - } -#endif - - if (error != ErrorCode_Success) - { - throw OrthancException(error); - } - - return restart; }