changeset 29:bc0431cb6b8f

fix for compatibility with simplified OrthancPluginCppWrapper
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 04 Dec 2018 21:16:54 +0100
parents ae19947abf68
children 9be38fb4f78e
files Plugin/AuthorizationParserBase.cpp Plugin/AuthorizationParserBase.h Plugin/AuthorizationWebService.cpp Plugin/AuthorizationWebService.h Plugin/DefaultAuthorizationParser.cpp Plugin/DefaultAuthorizationParser.h Plugin/OrthancResource.cpp Plugin/OrthancResource.h Plugin/Plugin.cpp Plugin/ResourceHierarchyCache.cpp Plugin/ResourceHierarchyCache.h
diffstat 11 files changed, 56 insertions(+), 84 deletions(-) [+]
line wrap: on
line diff
--- a/Plugin/AuthorizationParserBase.cpp	Fri Nov 09 10:55:42 2018 +0100
+++ b/Plugin/AuthorizationParserBase.cpp	Tue Dec 04 21:16:54 2018 +0100
@@ -137,10 +137,9 @@
   }
 
   
-  AuthorizationParserBase::AuthorizationParserBase(OrthancPluginContext* context,
-                                                   ICacheFactory& factory)
+  AuthorizationParserBase::AuthorizationParserBase(ICacheFactory& factory)
   {
-    resourceHierarchy_.reset(new ResourceHierarchyCache(context, factory));
+    resourceHierarchy_.reset(new ResourceHierarchyCache(factory));
 
     if (resourceHierarchy_.get() == NULL)
     {
--- a/Plugin/AuthorizationParserBase.h	Fri Nov 09 10:55:42 2018 +0100
+++ b/Plugin/AuthorizationParserBase.h	Tue Dec 04 21:16:54 2018 +0100
@@ -58,8 +58,7 @@
                           const std::string& instanceDicomUid);
 
   public:
-    AuthorizationParserBase(OrthancPluginContext* context,
-                            ICacheFactory& factory);
+    AuthorizationParserBase(ICacheFactory& factory);
 
     virtual void Invalidate(Orthanc::ResourceType level,
                             const std::string& id)
--- a/Plugin/AuthorizationWebService.cpp	Fri Nov 09 10:55:42 2018 +0100
+++ b/Plugin/AuthorizationWebService.cpp	Tue Dec 04 21:16:54 2018 +0100
@@ -71,8 +71,8 @@
       body["token-value"] = tokenValue;
     }
 
-    MemoryBuffer answerBody(context_);
-    MemoryBuffer answerHeaders(context_);
+    MemoryBuffer answerBody;
+    MemoryBuffer answerHeaders;
     uint16_t httpStatus = 0;
 
     uint32_t headersCount = 0;
@@ -96,7 +96,7 @@
 
     std::string flatBody = body.toStyledString();
       
-    if (OrthancPluginHttpClient(context_, *answerBody, *answerHeaders,
+    if (OrthancPluginHttpClient(GetGlobalContext(), *answerBody, *answerHeaders,
                                 &httpStatus, OrthancPluginHttpMethod_Post,
                                 url_.c_str(), headersCount, headersKeys, headersValues,
                                 flatBody.c_str(), flatBody.size(),
@@ -120,8 +120,8 @@
         (answer.isMember(VALIDITY) &&
          answer[VALIDITY].type() != Json::intValue))
     {
-      LOG(ERROR) << "Syntax error in the result of the Web service";
-      throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol);
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol,
+                                      "Syntax error in the result of the Web service");
     }
 
     validity = 0;
@@ -130,8 +130,8 @@
       int tmp = answer[VALIDITY].asInt();
       if (tmp < 0)
       {
-        LOG(ERROR) << "A validity duration cannot be negative";
-        throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol);          
+        throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol,
+                                        "A validity duration cannot be negative");
       }
 
       validity = static_cast<unsigned int>(tmp);
@@ -141,18 +141,6 @@
   }
     
 
-  AuthorizationWebService::AuthorizationWebService(OrthancPluginContext* context,
-                                                   const std::string& url) :
-    context_(context),
-    url_(url)
-  {
-    if (context_ == NULL)
-    {
-      throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
-    }
-  }
-
-    
   void AuthorizationWebService::SetCredentials(const std::string& username,
                                                const std::string& password)
   {
--- a/Plugin/AuthorizationWebService.h	Fri Nov 09 10:55:42 2018 +0100
+++ b/Plugin/AuthorizationWebService.h	Tue Dec 04 21:16:54 2018 +0100
@@ -25,7 +25,6 @@
   class AuthorizationWebService : public IAuthorizationService
   {
   private:
-    OrthancPluginContext* context_;
     std::string url_;
     std::string username_;
     std::string password_;
@@ -37,8 +36,10 @@
                            const std::string& tokenValue);
     
   public:
-    AuthorizationWebService(OrthancPluginContext* context,
-                            const std::string& url);
+    AuthorizationWebService(const std::string& url) :
+      url_(url)
+    {
+    }
 
     void SetCredentials(const std::string& username,
                         const std::string& password);
--- a/Plugin/DefaultAuthorizationParser.cpp	Fri Nov 09 10:55:42 2018 +0100
+++ b/Plugin/DefaultAuthorizationParser.cpp	Tue Dec 04 21:16:54 2018 +0100
@@ -22,10 +22,9 @@
 
 namespace OrthancPlugins
 {
-  DefaultAuthorizationParser::DefaultAuthorizationParser(OrthancPluginContext* context,
-                                                         ICacheFactory& factory,
+  DefaultAuthorizationParser::DefaultAuthorizationParser(ICacheFactory& factory,
                                                          const std::string& dicomWebRoot) :
-    AuthorizationParserBase(context, factory),
+    AuthorizationParserBase(factory),
     resourcesPattern_("^/(patients|studies|series|instances)/([a-f0-9-]+)(|/.*)$"),
     seriesPattern_("^/(web-viewer/series|web-viewer/is-stable-series|wsi/pyramids|wsi/tiles)/([a-f0-9-]+)(|/.*)$"),
     instancesPattern_("^/web-viewer/instances/[a-z0-9]+-([a-f0-9-]+)_[0-9]+$"),
--- a/Plugin/DefaultAuthorizationParser.h	Fri Nov 09 10:55:42 2018 +0100
+++ b/Plugin/DefaultAuthorizationParser.h	Tue Dec 04 21:16:54 2018 +0100
@@ -41,8 +41,7 @@
     boost::regex osimisViewerStudies_;
 
   public:
-    DefaultAuthorizationParser(OrthancPluginContext* context,
-                               ICacheFactory& factory,
+    DefaultAuthorizationParser(ICacheFactory& factory,
                                const std::string& dicomWebRoot);
 
     virtual bool Parse(AccessedResources& target,
--- a/Plugin/OrthancResource.cpp	Fri Nov 09 10:55:42 2018 +0100
+++ b/Plugin/OrthancResource.cpp	Tue Dec 04 21:16:54 2018 +0100
@@ -103,8 +103,7 @@
   }
 
   
-  bool OrthancResource::GetContent(Json::Value& content,
-                                   OrthancPluginContext* context) const
+  bool OrthancResource::GetContent(Json::Value& content) const
   {
     if (!IsValid())
     {
@@ -136,16 +135,15 @@
 
     uri = "/" + uri + "/" + id_;
         
-    return RestApiGet(content, context, uri, false /* ignore plugins */);
+    return RestApiGet(content, uri, false /* ignore plugins */);
   }
   
 
-  bool OrthancResource::GetDicomUid(std::string& dicomUid /* out */,
-                                    OrthancPluginContext* context) const
+  bool OrthancResource::GetDicomUid(std::string& dicomUid /* out */) const
   {
     Json::Value content;
         
-    if (!GetContent(content, context))
+    if (!GetContent(content))
     {
       return false;
     }
@@ -159,12 +157,11 @@
     
   bool OrthancResource::GetHierarchy(std::string& dicomUid /* out */,
                                      OrthancResource& parent /* out */,
-                                     std::list<OrthancResource>& children /* out */,
-                                     OrthancPluginContext* context) const
+                                     std::list<OrthancResource>& children /* out */) const
   {
     Json::Value content;
         
-    if (!GetContent(content, context))
+    if (!GetContent(content))
     {
       return false;
     }
@@ -244,28 +241,27 @@
 
 
   bool OrthancResource::LookupOrthancId(std::string& result,
-                                        OrthancPluginContext* context,
                                         Orthanc::ResourceType level,
                                         const std::string& dicomUid)
   {
-    OrthancString s(context);
+    OrthancString s;
 
     switch (level)
     {
       case Orthanc::ResourceType_Patient:
-        s.Assign(OrthancPluginLookupPatient(context, dicomUid.c_str()));
+        s.Assign(OrthancPluginLookupPatient(GetGlobalContext(), dicomUid.c_str()));
         break;
 
       case Orthanc::ResourceType_Study:
-        s.Assign(OrthancPluginLookupStudy(context, dicomUid.c_str()));
+        s.Assign(OrthancPluginLookupStudy(GetGlobalContext(), dicomUid.c_str()));
         break;
 
       case Orthanc::ResourceType_Series:
-        s.Assign(OrthancPluginLookupSeries(context, dicomUid.c_str()));
+        s.Assign(OrthancPluginLookupSeries(GetGlobalContext(), dicomUid.c_str()));
         break;
 
       case Orthanc::ResourceType_Instance:
-        s.Assign(OrthancPluginLookupInstance(context, dicomUid.c_str()));
+        s.Assign(OrthancPluginLookupInstance(GetGlobalContext(), dicomUid.c_str()));
         break;
 
       default:
--- a/Plugin/OrthancResource.h	Fri Nov 09 10:55:42 2018 +0100
+++ b/Plugin/OrthancResource.h	Tue Dec 04 21:16:54 2018 +0100
@@ -60,19 +60,15 @@
 
     const std::string& GetIdentifier() const;
 
-    bool GetContent(Json::Value& content,
-                    OrthancPluginContext* context) const;
+    bool GetContent(Json::Value& content) const;
 
-    bool GetDicomUid(std::string& dicomUid /* out */,
-                     OrthancPluginContext* context) const;
+    bool GetDicomUid(std::string& dicomUid /* out */) const;
     
     bool GetHierarchy(std::string& dicomUid /* out */,
                       OrthancResource& parent /* out */,
-                      std::list<OrthancResource>& children /* out */,
-                      OrthancPluginContext* context) const;
+                      std::list<OrthancResource>& children /* out */) const;
 
     static bool LookupOrthancId(std::string& result,
-                                OrthancPluginContext* context,
                                 Orthanc::ResourceType level,
                                 const std::string& dicomUid);
   };
--- a/Plugin/Plugin.cpp	Fri Nov 09 10:55:42 2018 +0100
+++ b/Plugin/Plugin.cpp	Tue Dec 04 21:16:54 2018 +0100
@@ -26,8 +26,6 @@
 #include <Core/Logging.h>
 #include <Core/Toolbox.h>
 
-static OrthancPluginContext* context_ = NULL;
-
 
 // Configuration of the authorization plugin
 static std::auto_ptr<OrthancPlugins::IAuthorizationParser> authorizationParser_;
@@ -246,25 +244,24 @@
 {
   ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context)
   {
-    context_ = context;
-    OrthancPluginLogWarning(context_, "Initializing the authorization plugin");
+    OrthancPlugins::SetGlobalContext(context);
+    OrthancPluginLogWarning(context, "Initializing the authorization plugin");
 
     /* Check the version of the Orthanc core */
-    if (OrthancPluginCheckVersion(context_) == 0)
+    if (OrthancPluginCheckVersion(context) == 0)
     {
-      OrthancPlugins::ReportMinimalOrthancVersion(context_, 
-                                                  ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
+      OrthancPlugins::ReportMinimalOrthancVersion(ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
                                                   ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
                                                   ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
       return -1;
     }
 
-    Orthanc::Logging::Initialize(context_);
-    OrthancPluginSetDescription(context_, "Advanced authorization plugin for Orthanc.");
+    Orthanc::Logging::Initialize(context);
+    OrthancPluginSetDescription(context, "Advanced authorization plugin for Orthanc.");
 
     try
     {
-      OrthancPlugins::OrthancConfiguration general(context_);
+      OrthancPlugins::OrthancConfiguration general;
 
       static const char* SECTION = "Authorization";
       if (general.IsSection(SECTION))
@@ -291,7 +288,7 @@
           } 
 
           authorizationParser_.reset
-            (new OrthancPlugins::DefaultAuthorizationParser(context_, factory, root));
+            (new OrthancPlugins::DefaultAuthorizationParser(factory, root));
         }
 
         std::list<std::string> tmp;
@@ -314,9 +311,10 @@
 #else
         if (!tmp.empty())
         {
-          LOG(ERROR) << "The option \"TokenGetArguments\" of the authorization plugin "
-                     << "is only valid if compiled against Orthanc >= 1.3.0";
-          throw Orthanc::OrthancException(Orthanc::ErrorCode_Plugin);
+          throw Orthanc::OrthancException(
+            Orthanc::ErrorCode_Plugin,
+            "The option \"TokenGetArguments\" of the authorization plugin "
+            "is only valid if compiled against Orthanc >= 1.3.0"
         }
 #endif
 
@@ -328,9 +326,10 @@
         static const char* WEB_SERVICE = "WebService";
         if (!configuration.LookupStringValue(url, WEB_SERVICE))
         {
-          LOG(ERROR) << "Missing mandatory option \"" << WEB_SERVICE
-                     << "\" for the authorization plugin";
-          throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);          
+          throw Orthanc::OrthancException(
+            Orthanc::ErrorCode_BadFileFormat,
+            "Missing mandatory option \"" + std::string(WEB_SERVICE) +
+            "\" for the authorization plugin");
         }
 
         if (configuration.LookupListOfStrings(tmp, "UncheckedLevels", false))
@@ -344,14 +343,14 @@
 
         authorizationService_.reset
           (new OrthancPlugins::CachedAuthorizationService
-           (new OrthancPlugins::AuthorizationWebService(context_, url), factory));
+           (new OrthancPlugins::AuthorizationWebService(url), factory));
 
-        OrthancPluginRegisterOnChangeCallback(context_, OnChangeCallback);
+        OrthancPluginRegisterOnChangeCallback(context, OnChangeCallback);
         
 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 2, 1)
-        OrthancPluginRegisterIncomingHttpRequestFilter2(context_, FilterHttpRequests);
+        OrthancPluginRegisterIncomingHttpRequestFilter2(context, FilterHttpRequests);
 #else
-        OrthancPluginRegisterIncomingHttpRequestFilter(context_, FilterHttpRequestsFallback);
+        OrthancPluginRegisterIncomingHttpRequestFilter(context, FilterHttpRequestsFallback);
 #endif
       }
       else
--- a/Plugin/ResourceHierarchyCache.cpp	Fri Nov 09 10:55:42 2018 +0100
+++ b/Plugin/ResourceHierarchyCache.cpp	Tue Dec 04 21:16:54 2018 +0100
@@ -60,7 +60,7 @@
     OrthancResource parent;
     std::list<OrthancResource> children;
 
-    if (!resource.GetHierarchy(dicomUid, parent, children, context_))
+    if (!resource.GetHierarchy(dicomUid, parent, children))
     {
       // The resource is non-existing (*)
       return false;
@@ -92,9 +92,7 @@
   }
 
 
-  ResourceHierarchyCache::ResourceHierarchyCache(OrthancPluginContext* context,
-                                                 ICacheFactory& factory) :
-    context_(context),
+  ResourceHierarchyCache::ResourceHierarchyCache(ICacheFactory& factory) :
     cache_(factory.Create()),
     orthancToDicom_(factory.Create()),
     dicomToOrthanc_(factory.Create())
@@ -162,7 +160,7 @@
 
     OrthancResource resource(level, orthancId);
 
-    if (resource.GetDicomUid(target, context_))
+    if (resource.GetDicomUid(target))
     {
       orthancToDicom_->Store(key, target, 0 /* no expiration */);
       return true;
@@ -187,7 +185,7 @@
 
     OrthancResource resource(level, dicomUid);
 
-    if (OrthancResource::LookupOrthancId(target, context_, level, dicomUid))
+    if (OrthancResource::LookupOrthancId(target, level, dicomUid))
     {
       dicomToOrthanc_->Store(key, target, 0 /* no expiration */);
       return true;
--- a/Plugin/ResourceHierarchyCache.h	Fri Nov 09 10:55:42 2018 +0100
+++ b/Plugin/ResourceHierarchyCache.h	Tue Dec 04 21:16:54 2018 +0100
@@ -30,7 +30,6 @@
   class ResourceHierarchyCache : public boost::noncopyable
   {
   private:
-    OrthancPluginContext   *context_;
     std::auto_ptr<ICache>   cache_;   // Maps resources to their parents
     std::auto_ptr<ICache>   orthancToDicom_;
     std::auto_ptr<ICache>   dicomToOrthanc_;
@@ -57,8 +56,7 @@
     }
 
   public:
-    ResourceHierarchyCache(OrthancPluginContext* context,
-                           ICacheFactory& factory);
+    ResourceHierarchyCache(ICacheFactory& factory);
 
     void Invalidate(Orthanc::ResourceType level,
                     const std::string& identifier);