changeset 8:4c3437217518

fix for compatibility with simplified OrthancPluginCppWrapper
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 05 Dec 2018 09:16:51 +0100
parents 151e29acbb13
children 7e207ade2f1a
files Framework/DownloadArea.cpp Framework/DownloadArea.h Framework/HttpQueries/DetectTransferPlugin.cpp Framework/HttpQueries/DetectTransferPlugin.h Framework/HttpQueries/HttpQueriesQueue.cpp Framework/HttpQueries/HttpQueriesQueue.h Framework/OrthancInstancesCache.cpp Framework/OrthancInstancesCache.h Framework/PullMode/PullJob.cpp Framework/PullMode/PullJob.h Framework/PushMode/ActivePushTransactions.cpp Framework/PushMode/ActivePushTransactions.h Framework/PushMode/PushJob.cpp Framework/PushMode/PushJob.h Framework/SourceDicomInstance.cpp Framework/SourceDicomInstance.h Framework/TransferScheduler.cpp Plugin/Plugin.cpp Plugin/PluginContext.cpp Plugin/PluginContext.h
diffstat 20 files changed, 96 insertions(+), 162 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/DownloadArea.cpp	Fri Sep 21 12:52:23 2018 +0200
+++ b/Framework/DownloadArea.cpp	Wed Dec 05 09:16:51 2018 +0100
@@ -97,8 +97,7 @@
   }
 
   
-  void DownloadArea::Instance::Commit(OrthancPluginContext* context,
-                                      bool simulate) const
+  void DownloadArea::Instance::Commit(bool simulate) const
   {
     std::string content;
     Orthanc::SystemToolbox::ReadFile(content, file_.GetPath());
@@ -110,13 +109,8 @@
     {
       if (!simulate)
       {
-        if (context == NULL)
-        {
-          throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
-        }
-
         Json::Value result;
-        if (!RestApiPost(result, context, "/instances", 
+        if (!RestApiPost(result, "/instances", 
                          content.empty() ? NULL : content.c_str(), content.size(),
                          false))
         {
@@ -225,8 +219,7 @@
   }
     
 
-  void DownloadArea::CommitInternal(OrthancPluginContext* context,
-                                    bool simulate)
+  void DownloadArea::CommitInternal(bool simulate)
   {
     boost::mutex::scoped_lock lock(mutex_);
       
@@ -235,7 +228,7 @@
     {
       if (it->second != NULL)
       {
-        it->second->Commit(context, simulate);
+        it->second->Commit(simulate);
         delete it->second;
         it->second = NULL;
       }
@@ -313,13 +306,13 @@
   void DownloadArea::CheckMD5()
   {
     LOG(INFO) << "Checking MD5 sum without committing (testing)";
-    CommitInternal(NULL, true);
+    CommitInternal(true);
   }
 
 
-  void DownloadArea::Commit(OrthancPluginContext* context)
+  void DownloadArea::Commit()
   {
     LOG(INFO) << "Importing transfered DICOM files from the temporary download area into Orthanc";
-    CommitInternal(context, false);
+    CommitInternal(false);
   }
 }
--- a/Framework/DownloadArea.h	Fri Sep 21 12:52:23 2018 +0200
+++ b/Framework/DownloadArea.h	Wed Dec 05 09:16:51 2018 +0100
@@ -48,8 +48,7 @@
                       const void* data,
                       size_t size);
 
-      void Commit(OrthancPluginContext* context,
-                  bool simulate) const;
+      void Commit(bool simulate) const;
     };
 
 
@@ -70,8 +69,7 @@
 
     void Setup(const std::vector<DicomInstanceInfo>& instances);
     
-    void CommitInternal(OrthancPluginContext* context,
-                        bool simulate);
+    void CommitInternal(bool simulate);
 
   public:
     DownloadArea(const TransferScheduler& scheduler);
@@ -102,6 +100,6 @@
 
     void CheckMD5();
 
-    void Commit(OrthancPluginContext* context);
+    void Commit();
   };
 }
--- a/Framework/HttpQueries/DetectTransferPlugin.cpp	Fri Sep 21 12:52:23 2018 +0200
+++ b/Framework/HttpQueries/DetectTransferPlugin.cpp	Wed Dec 05 09:16:51 2018 +0100
@@ -68,11 +68,10 @@
 
 
   void DetectTransferPlugin::Apply(Result& result,
-                                   OrthancPluginContext* context,
                                    size_t threadsCount,
                                    unsigned int timeout)
   {
-    OrthancPlugins::HttpQueriesQueue queue(context);
+    OrthancPlugins::HttpQueriesQueue queue;
 
     queue.GetOrthancPeers().SetTimeout(timeout);
     queue.Reserve(queue.GetOrthancPeers().GetPeersCount());
--- a/Framework/HttpQueries/DetectTransferPlugin.h	Fri Sep 21 12:52:23 2018 +0200
+++ b/Framework/HttpQueries/DetectTransferPlugin.h	Wed Dec 05 09:16:51 2018 +0100
@@ -22,7 +22,6 @@
 #include "IHttpQuery.h"
 #include "../TransferToolbox.h"
 
-#include <orthanc/OrthancCPlugin.h>
 #include <map>
 
 
@@ -63,7 +62,6 @@
                               size_t size);
 
     static void Apply(Result& result,
-                      OrthancPluginContext* context,
                       size_t threadsCount,
                       unsigned int timeout);
   };
--- a/Framework/HttpQueries/HttpQueriesQueue.cpp	Fri Sep 21 12:52:23 2018 +0200
+++ b/Framework/HttpQueries/HttpQueriesQueue.cpp	Wed Dec 05 09:16:51 2018 +0100
@@ -41,9 +41,7 @@
   }
 
 
-  HttpQueriesQueue::HttpQueriesQueue(OrthancPluginContext* context) :
-    context_(context),
-    peers_(context),
+  HttpQueriesQueue::HttpQueriesQueue() :
     maxRetries_(0)
   {
     Reset();
@@ -142,7 +140,7 @@
 
     for (;;)
     {
-      MemoryBuffer answer(context_);
+      MemoryBuffer answer;
 
       bool success;
 
--- a/Framework/HttpQueries/HttpQueriesQueue.h	Fri Sep 21 12:52:23 2018 +0200
+++ b/Framework/HttpQueries/HttpQueriesQueue.h	Wed Dec 05 09:16:51 2018 +0100
@@ -40,7 +40,6 @@
     };
 
   private:
-    OrthancPluginContext         *context_;
     OrthancPeers                  peers_;
     boost::mutex                  mutex_;
     boost::condition_variable     completed_;
@@ -57,7 +56,7 @@
     Status GetStatusInternal() const;
 
   public:
-    HttpQueriesQueue(OrthancPluginContext* context);
+    HttpQueriesQueue();
 
     ~HttpQueriesQueue();
 
--- a/Framework/OrthancInstancesCache.cpp	Fri Sep 21 12:52:23 2018 +0200
+++ b/Framework/OrthancInstancesCache.cpp	Wed Dec 05 09:16:51 2018 +0100
@@ -153,15 +153,10 @@
   }
     
 
-  OrthancInstancesCache::OrthancInstancesCache(OrthancPluginContext* context) :
-    context_(context),
+  OrthancInstancesCache::OrthancInstancesCache() :
     memorySize_(0),
     maxMemorySize_(512 * MB)  // 512 MB by default
   {
-    if (context == NULL)
-    {
-      throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
-    }
   }
     
 
@@ -227,7 +222,7 @@
     }
       
     // The instance was not in the cache, load it
-    std::auto_ptr<SourceDicomInstance> instance(new SourceDicomInstance(context_, instanceId));
+    std::auto_ptr<SourceDicomInstance> instance(new SourceDicomInstance(instanceId));
     size = instance->GetInfo().GetSize();
     md5 = instance->GetInfo().GetMD5();
 
@@ -256,7 +251,7 @@
     }
       
     // The instance was not in the cache, load it
-    std::auto_ptr<SourceDicomInstance> instance(new SourceDicomInstance(context_, instanceId));
+    std::auto_ptr<SourceDicomInstance> instance(new SourceDicomInstance(instanceId));
     instance->GetChunk(chunk, md5, 0, instance->GetInfo().GetSize());
 
     // Store the just-loaded DICOM instance into the cache
--- a/Framework/OrthancInstancesCache.h	Fri Sep 21 12:52:23 2018 +0200
+++ b/Framework/OrthancInstancesCache.h	Wed Dec 05 09:16:51 2018 +0100
@@ -60,12 +60,11 @@
     typedef Orthanc::LeastRecentlyUsedIndex<std::string>  Index;
     typedef std::map<std::string, SourceDicomInstance*>   Content;
 
-    OrthancPluginContext*  context_;
-    boost::mutex           mutex_;
-    Index                  index_;
-    Content                content_;
-    size_t                 memorySize_;
-    size_t                 maxMemorySize_;
+    boost::mutex   mutex_;
+    Index          index_;
+    Content        content_;
+    size_t         memorySize_;
+    size_t         maxMemorySize_;
 
 
     // The mutex must be locked!
@@ -80,15 +79,10 @@
     
 
   public:
-    OrthancInstancesCache(OrthancPluginContext* context);
+    OrthancInstancesCache();
 
     ~OrthancInstancesCache();
 
-    OrthancPluginContext* GetContext() const
-    {
-      return context_;
-    }    
-
     size_t GetMemorySize();
 
     size_t GetMaxMemorySize();
--- a/Framework/PullMode/PullJob.cpp	Fri Sep 21 12:52:23 2018 +0200
+++ b/Framework/PullMode/PullJob.cpp	Wed Dec 05 09:16:51 2018 +0100
@@ -46,7 +46,7 @@
 
     virtual StateUpdate* Step()
     {
-      area_->Commit(job_.context_);
+      area_->Commit();
       return StateUpdate::Success();
     }
 
@@ -93,7 +93,6 @@
                      const TransferScheduler& scheduler) :
       job_(job),
       info_(info),
-      queue_(job.context_),
       area_(new DownloadArea(scheduler))
     {
       const std::string baseUrl = job.peers_.GetPeerUrl(job.query_.GetPeer());
@@ -229,16 +228,13 @@
   }
     
     
-  PullJob::PullJob(OrthancPluginContext* context,
-                   const TransferQuery& query,
+  PullJob::PullJob(const TransferQuery& query,
                    size_t threadsCount,
                    size_t targetBucketSize) :
     StatefulOrthancJob(JOB_TYPE_PULL),
-    context_(context),
     query_(query),
     threadsCount_(threadsCount),
-    targetBucketSize_(targetBucketSize),
-    peers_(context)
+    targetBucketSize_(targetBucketSize)
   {
     if (!peers_.LookupName(peerIndex_, query_.GetPeer()))
     {
--- a/Framework/PullMode/PullJob.h	Fri Sep 21 12:52:23 2018 +0200
+++ b/Framework/PullMode/PullJob.h	Wed Dec 05 09:16:51 2018 +0100
@@ -32,18 +32,16 @@
     class PullBucketsState;
     class CommitState;
 
-    OrthancPluginContext  *context_;
-    TransferQuery          query_;
-    size_t                 threadsCount_;
-    size_t                 targetBucketSize_;
-    OrthancPeers           peers_;
-    size_t                 peerIndex_;
+    TransferQuery  query_;
+    size_t         threadsCount_;
+    size_t         targetBucketSize_;
+    OrthancPeers   peers_;
+    size_t         peerIndex_;
 
     virtual StateUpdate* CreateInitialState(JobInfo& info);    
     
   public:
-    PullJob(OrthancPluginContext* context,
-            const TransferQuery& query,
+    PullJob(const TransferQuery& query,
             size_t threadsCount,
             size_t targetBucketSize);
   };
--- a/Framework/PushMode/ActivePushTransactions.cpp	Fri Sep 21 12:52:23 2018 +0200
+++ b/Framework/PushMode/ActivePushTransactions.cpp	Wed Dec 05 09:16:51 2018 +0100
@@ -74,8 +74,7 @@
   };
     
 
-  void ActivePushTransactions::FinalizeTransaction(OrthancPluginContext* context,
-                                                   const std::string& transactionUuid,
+  void ActivePushTransactions::FinalizeTransaction(const std::string& transactionUuid,
                                                    bool commit)
   {
     boost::mutex::scoped_lock  lock(mutex_);
@@ -89,7 +88,7 @@
     assert(found->second != NULL);
     if (commit)
     {
-      found->second->GetDownloadArea().Commit(context);
+      found->second->GetDownloadArea().Commit();
     }
 
     delete found->second;
@@ -163,8 +162,7 @@
   }
     
 
-  void ActivePushTransactions::Store(OrthancPluginContext* context,
-                                     const std::string& transactionUuid,
+  void ActivePushTransactions::Store(const std::string& transactionUuid,
                                      size_t bucketIndex,
                                      const void* data,
                                      size_t size)
--- a/Framework/PushMode/ActivePushTransactions.h	Fri Sep 21 12:52:23 2018 +0200
+++ b/Framework/PushMode/ActivePushTransactions.h	Wed Dec 05 09:16:51 2018 +0100
@@ -21,7 +21,6 @@
 
 #include "../TransferBucket.h"
 
-#include <orthanc/OrthancCPlugin.h>
 #include <Core/Cache/LeastRecentlyUsedIndex.h>
 
 #include <boost/thread/mutex.hpp>
@@ -41,8 +40,7 @@
     Index         index_;
     size_t        maxSize_;
 
-    void FinalizeTransaction(OrthancPluginContext* context,
-                             const std::string& transactionUuid,
+    void FinalizeTransaction(const std::string& transactionUuid,
                              bool commit);
 
   public:
@@ -59,21 +57,19 @@
                                   const std::vector<TransferBucket>& buckets,
                                   BucketCompression compression);
 
-    void Store(OrthancPluginContext* context,
-               const std::string& transactionUuid,
+    void Store(const std::string& transactionUuid,
                size_t bucketIndex,
                const void* data,
                size_t size);
 
-    void Commit(OrthancPluginContext* context,
-                const std::string& transactionUuid)
+    void Commit(const std::string& transactionUuid)
     {
-      FinalizeTransaction(context, transactionUuid, true);
+      FinalizeTransaction(transactionUuid, true);
     }
 
     void Discard(const std::string& transactionUuid)
     {
-      FinalizeTransaction(NULL, transactionUuid, false);
+      FinalizeTransaction(transactionUuid, false);
     }
   };
 }
--- a/Framework/PushMode/PushJob.cpp	Fri Sep 21 12:52:23 2018 +0200
+++ b/Framework/PushMode/PushJob.cpp	Wed Dec 05 09:16:51 2018 +0100
@@ -128,8 +128,7 @@
                      const std::vector<TransferBucket>& buckets) :
       job_(job),
       info_(info),
-      transactionUri_(transactionUri),
-      queue_(job.context_)
+      transactionUri_(transactionUri)
     {
       queue_.Reserve(buckets.size());
         
@@ -246,18 +245,15 @@
   }
     
     
-  PushJob::PushJob(OrthancPluginContext* context,
-                   const TransferQuery& query,
+  PushJob::PushJob(const TransferQuery& query,
                    OrthancInstancesCache& cache,
                    size_t threadsCount,
                    size_t targetBucketSize) :
     StatefulOrthancJob(JOB_TYPE_PUSH),
-    context_(context),
     cache_(cache),
     query_(query),
     threadsCount_(threadsCount),
-    targetBucketSize_(targetBucketSize),
-    peers_(context)
+    targetBucketSize_(targetBucketSize)
   {
     if (!peers_.LookupName(peerIndex_, query_.GetPeer()))
     {
--- a/Framework/PushMode/PushJob.h	Fri Sep 21 12:52:23 2018 +0200
+++ b/Framework/PushMode/PushJob.h	Wed Dec 05 09:16:51 2018 +0100
@@ -32,7 +32,6 @@
     class PushBucketsState;
     class FinalState;
 
-    OrthancPluginContext    *context_;
     OrthancInstancesCache&   cache_;
     TransferQuery            query_;
     size_t                   threadsCount_;
@@ -43,8 +42,7 @@
     virtual StateUpdate* CreateInitialState(JobInfo& info);
     
   public:
-    PushJob(OrthancPluginContext* context,
-            const TransferQuery& query,
+    PushJob(const TransferQuery& query,
             OrthancInstancesCache& cache,
             size_t threadsCount,
             size_t targetBucketSize);
--- a/Framework/SourceDicomInstance.cpp	Fri Sep 21 12:52:23 2018 +0200
+++ b/Framework/SourceDicomInstance.cpp	Wed Dec 05 09:16:51 2018 +0100
@@ -26,13 +26,11 @@
 
 namespace OrthancPlugins
 {
-  SourceDicomInstance::SourceDicomInstance(OrthancPluginContext* context,
-                                           const std::string& instanceId) :
-    context_(context)
+  SourceDicomInstance::SourceDicomInstance(const std::string& instanceId)
   {
     LOG(INFO) << "Transfers accelerator reading DICOM instance: " << instanceId;
       
-    MemoryBuffer buffer(context);
+    MemoryBuffer buffer;
     buffer.GetDicomInstance(instanceId);
 
     info_.reset(new DicomInstanceInfo(instanceId, buffer));
@@ -43,7 +41,7 @@
   
   SourceDicomInstance::~SourceDicomInstance()
   {
-    OrthancPluginFreeMemoryBuffer(context_, &buffer_);
+    OrthancPluginFreeMemoryBuffer(OrthancPlugins::GetGlobalContext(), &buffer_);
   }
 
 
--- a/Framework/SourceDicomInstance.h	Fri Sep 21 12:52:23 2018 +0200
+++ b/Framework/SourceDicomInstance.h	Wed Dec 05 09:16:51 2018 +0100
@@ -31,13 +31,11 @@
   class SourceDicomInstance : public boost::noncopyable
   {
   private:
-    OrthancPluginContext*             context_;
     OrthancPluginMemoryBuffer         buffer_;
     std::auto_ptr<DicomInstanceInfo>  info_;
 
   public:
-    SourceDicomInstance(OrthancPluginContext* context,
-                        const std::string& instanceId);
+    SourceDicomInstance(const std::string& instanceId);
 
     ~SourceDicomInstance();
 
--- a/Framework/TransferScheduler.cpp	Fri Sep 21 12:52:23 2018 +0200
+++ b/Framework/TransferScheduler.cpp	Wed Dec 05 09:16:51 2018 +0100
@@ -51,7 +51,7 @@
         throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
     }
 
-    if (RestApiGet(resource, cache.GetContext(), "/" + base + "/" + id + "/instances", false))
+    if (RestApiGet(resource, "/" + base + "/" + id + "/instances", false))
     {
       if (resource.type() != Json::arrayValue)
       {
--- a/Plugin/Plugin.cpp	Fri Sep 21 12:52:23 2018 +0200
+++ b/Plugin/Plugin.cpp	Wed Dec 05 09:16:51 2018 +0100
@@ -69,7 +69,7 @@
   
   if (request->method != OrthancPluginHttpMethod_Get)
   {
-    OrthancPluginSendMethodNotAllowed(context.GetOrthanc(), output, "GET");
+    OrthancPluginSendMethodNotAllowed(OrthancPlugins::GetGlobalContext(), output, "GET");
     return;
   }
   
@@ -159,7 +159,7 @@
   {
     case OrthancPlugins::BucketCompression_None:
     {
-      OrthancPluginAnswerBuffer(context.GetOrthanc(), output, chunk.c_str(),
+      OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, chunk.c_str(),
                                 chunk.size(), "application/octet-stream");
       break;
     }
@@ -170,7 +170,7 @@
       Orthanc::GzipCompressor gzip;
       //gzip.SetCompressionLevel(9);
       Orthanc::IBufferCompressor::Compress(compressed, gzip, chunk);
-      OrthancPluginAnswerBuffer(context.GetOrthanc(), output, compressed.c_str(),
+      OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, compressed.c_str(),
                                 compressed.size(), "application/gzip");
       break;
     }
@@ -186,13 +186,11 @@
                           OrthancPluginRestOutput* output,
                           const OrthancPluginHttpRequest* request)
 {
-  OrthancPlugins::PluginContext& context = OrthancPlugins::PluginContext::GetInstance();
-  
   Json::Reader reader;
 
   if (request->method != OrthancPluginHttpMethod_Post)
   {
-    OrthancPluginSendMethodNotAllowed(context.GetOrthanc(), output, "POST");
+    OrthancPluginSendMethodNotAllowed(OrthancPlugins::GetGlobalContext(), output, "POST");
     return false;
   }
   else if (reader.parse(request->body, request->body + request->bodySize, body))
@@ -241,7 +239,7 @@
   Json::FastWriter writer;
   std::string s = writer.write(answer);
   
-  OrthancPluginAnswerBuffer(context.GetOrthanc(), output, s.c_str(), s.size(), "application/json");
+  OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(), s.size(), "application/json");
 }
 
 
@@ -250,16 +248,14 @@
                       OrthancPlugins::OrthancJob* job,
                       int priority)
 {
-  OrthancPlugins::PluginContext& context = OrthancPlugins::PluginContext::GetInstance();
-  
-  std::string id = OrthancPlugins::OrthancJob::Submit(context.GetOrthanc(), job, priority);
+  std::string id = OrthancPlugins::OrthancJob::Submit(job, priority);
 
   Json::Value result = Json::objectValue;
   result[KEY_ID] = id;
   result[KEY_PATH] = std::string(URI_JOBS) + "/" + id;
 
   std::string s = result.toStyledString();
-  OrthancPluginAnswerBuffer(context.GetOrthanc(), output, s.c_str(), s.size(), "application/json");
+  OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(), s.size(), "application/json");
 }
 
 
@@ -278,9 +274,8 @@
 
   OrthancPlugins::TransferQuery query(body);
 
-  SubmitJob(output, new OrthancPlugins::PullJob(context.GetOrthanc(), query,
-                                                context.GetThreadsCount(),
-                                                context.GetTargetBucketSize()),
+  SubmitJob(output, new OrthancPlugins::PullJob(
+              query, context.GetThreadsCount(), context.GetTargetBucketSize()),
             query.GetPriority());
 }
 
@@ -338,7 +333,7 @@
   result[KEY_PATH] = std::string(URI_PUSH) + "/" + id;
 
   std::string s = result.toStyledString();  
-  OrthancPluginAnswerBuffer(context.GetOrthanc(), output, s.c_str(), s.size(), "application/json");
+  OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(), s.size(), "application/json");
 }
 
 
@@ -350,7 +345,7 @@
   
   if (request->method != OrthancPluginHttpMethod_Put)
   {
-    OrthancPluginSendMethodNotAllowed(context.GetOrthanc(), output, "PUT");
+    OrthancPluginSendMethodNotAllowed(OrthancPlugins::GetGlobalContext(), output, "PUT");
     return;
   }
 
@@ -370,10 +365,10 @@
   }
 
   context.GetActivePushTransactions().Store
-    (context.GetOrthanc(), transaction, chunkIndex, request->body, request->bodySize);
+    (transaction, chunkIndex, request->body, request->bodySize);
 
   std::string s = "{}";
-  OrthancPluginAnswerBuffer(context.GetOrthanc(), output, s.c_str(), s.size(), "application/json");
+  OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(), s.size(), "application/json");
 }
 
 
@@ -385,18 +380,17 @@
   
   if (request->method != OrthancPluginHttpMethod_Post)
   {
-    OrthancPluginSendMethodNotAllowed(context.GetOrthanc(), output, "POST");
+    OrthancPluginSendMethodNotAllowed(OrthancPlugins::GetGlobalContext(), output, "POST");
     return;
   }
 
   assert(request->groupsCount == 1);
   std::string transaction(request->groups[0]);
 
-  context.
-    GetActivePushTransactions().Commit(context.GetOrthanc(), transaction);
+  context.GetActivePushTransactions().Commit(transaction);
 
   std::string s = "{}";
-  OrthancPluginAnswerBuffer(context.GetOrthanc(), output, s.c_str(), s.size(), "application/json");
+  OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(), s.size(), "application/json");
 }
 
 
@@ -408,7 +402,7 @@
   
   if (request->method != OrthancPluginHttpMethod_Delete)
   {
-    OrthancPluginSendMethodNotAllowed(context.GetOrthanc(), output, "DELETE");
+    OrthancPluginSendMethodNotAllowed(OrthancPlugins::GetGlobalContext(), output, "DELETE");
     return;
   }
 
@@ -419,7 +413,7 @@
     GetActivePushTransactions().Discard(transaction);
 
   std::string s = "{}";
-  OrthancPluginAnswerBuffer(context.GetOrthanc(), output, s.c_str(), s.size(), "application/json");
+  OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(), s.size(), "application/json");
 }
 
 
@@ -438,7 +432,7 @@
 
   OrthancPlugins::TransferQuery query(body);
 
-  OrthancPlugins::OrthancPeers peers(context.GetOrthanc());
+  OrthancPlugins::OrthancPeers peers;
   
   std::string remoteSelf;  // For pull mode
   bool pullMode = peers.LookupUserProperty(remoteSelf, query.GetPeer(), KEY_REMOTE_SELF);
@@ -473,7 +467,7 @@
       result[KEY_URL] = url + answer[KEY_PATH].asString();
 
       std::string s = result.toStyledString();  
-      OrthancPluginAnswerBuffer(context.GetOrthanc(), output, s.c_str(), s.size(), "application/json");
+      OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(), s.size(), "application/json");
     }
     else
     {
@@ -484,10 +478,8 @@
   }
   else
   {
-    SubmitJob(output, new OrthancPlugins::PushJob(context.GetOrthanc(), query,
-                                                  context.GetCache(),
-                                                  context.GetThreadsCount(),
-                                                  context.GetTargetBucketSize()),
+    SubmitJob(output, new OrthancPlugins::PushJob(query, context.GetCache(),
+                                                  context.GetThreadsCount(), context.GetTargetBucketSize()),
               query.GetPriority());
   }
 }
@@ -526,13 +518,13 @@
 
       if (type == JOB_TYPE_PULL)
       {
-        job.reset(new OrthancPlugins::PullJob(context.GetOrthanc(), query,
+        job.reset(new OrthancPlugins::PullJob(query,
                                               context.GetThreadsCount(),
                                               context.GetTargetBucketSize()));
       }
       else if (type == JOB_TYPE_PUSH)
       {
-        job.reset(new OrthancPlugins::PushJob(context.GetOrthanc(), query,
+        job.reset(new OrthancPlugins::PushJob(query,
                                               context.GetCache(),
                                               context.GetThreadsCount(),
                                               context.GetTargetBucketSize()));
@@ -544,7 +536,7 @@
       }
       else
       {
-        return OrthancPlugins::OrthancJob::Create(context.GetOrthanc(), job.release());
+        return OrthancPlugins::OrthancJob::Create(job.release());
       }
     }
     else
@@ -575,17 +567,17 @@
   
   if (request->method != OrthancPluginHttpMethod_Get)
   {
-    OrthancPluginSendMethodNotAllowed(context.GetOrthanc(), output, "GET");
+    OrthancPluginSendMethodNotAllowed(OrthancPlugins::GetGlobalContext(), output, "GET");
     return;
   }
 
   OrthancPlugins::DetectTransferPlugin::Result detection;
   OrthancPlugins::DetectTransferPlugin::Apply
-    (detection, context.GetOrthanc(), context.GetThreadsCount(), 2 /* timeout */);
+    (detection, context.GetThreadsCount(), 2 /* timeout */);
 
   Json::Value result = Json::objectValue;
 
-  OrthancPlugins::OrthancPeers peers(context.GetOrthanc());
+  OrthancPlugins::OrthancPeers peers;
 
   for (OrthancPlugins::DetectTransferPlugin::Result::const_iterator
          it = detection.begin(); it != detection.end(); ++it)
@@ -610,7 +602,7 @@
   }
 
   std::string s = result.toStyledString();
-  OrthancPluginAnswerBuffer(context.GetOrthanc(), output, s.c_str(), s.size(), "application/json");
+  OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(), s.size(), "application/json");
 }
 
 
@@ -622,6 +614,8 @@
     Orthanc::Logging::Initialize(context);
     assert(DisplayPerformanceWarning());
 
+    OrthancPlugins::SetGlobalContext(context);
+    
     /* Check the version of the Orthanc core */
     if (OrthancPluginCheckVersion(context) == 0)
     {
@@ -646,7 +640,7 @@
       std::map<std::string, std::string> bidirectionalPeers;
     
       {
-        OrthancPlugins::OrthancConfiguration config(context);
+        OrthancPlugins::OrthancConfiguration config;
 
         if (config.IsSection(KEY_PLUGIN_CONFIGURATION))
         {
@@ -662,37 +656,37 @@
       }
 
       OrthancPlugins::PluginContext::Initialize
-        (context, threadsCount, targetBucketSize * KB, maxPushTransactions, memoryCacheSize * MB);
+        (threadsCount, targetBucketSize * KB, maxPushTransactions, memoryCacheSize * MB);
     
       OrthancPlugins::RegisterRestCallback<ServeChunks>
-        (context, std::string(URI_CHUNKS) + "/([.0-9a-f-]+)", true);
+        (std::string(URI_CHUNKS) + "/([.0-9a-f-]+)", true);
 
       OrthancPlugins::RegisterRestCallback<LookupInstances>
-        (context, URI_LOOKUP, true);
+        (URI_LOOKUP, true);
 
       OrthancPlugins::RegisterRestCallback<SchedulePull>
-        (context, URI_PULL, true);
+        (URI_PULL, true);
 
       OrthancPlugins::RegisterRestCallback<ScheduleSend>
-        (context, URI_SEND, true);
+        (URI_SEND, true);
 
       OrthancPlugins::RegisterRestCallback<ServePeers>
-        (context, URI_PEERS, true);
+        (URI_PEERS, true);
 
       if (maxPushTransactions != 0)
       {
         // If no push transaction is allowed, their URIs are disabled
         OrthancPlugins::RegisterRestCallback<CreatePush>
-          (context, URI_PUSH, true);
+          (URI_PUSH, true);
 
         OrthancPlugins::RegisterRestCallback<StorePush>
-          (context, std::string(URI_PUSH) + "/([.0-9a-f-]+)/([0-9]+)", true);
+          (std::string(URI_PUSH) + "/([.0-9a-f-]+)/([0-9]+)", true);
 
         OrthancPlugins::RegisterRestCallback<CommitPush>
-          (context, std::string(URI_PUSH) + "/([.0-9a-f-]+)/commit", true);
+          (std::string(URI_PUSH) + "/([.0-9a-f-]+)/commit", true);
     
         OrthancPlugins::RegisterRestCallback<DiscardPush>
-          (context, std::string(URI_PUSH) + "/([.0-9a-f-]+)", true);
+          (std::string(URI_PUSH) + "/([.0-9a-f-]+)", true);
       }
 
       OrthancPluginRegisterJobsUnserializer(context, Unserializer);
--- a/Plugin/PluginContext.cpp	Fri Sep 21 12:52:23 2018 +0200
+++ b/Plugin/PluginContext.cpp	Wed Dec 05 09:16:51 2018 +0100
@@ -24,13 +24,10 @@
 
 namespace OrthancPlugins
 {
-  PluginContext::PluginContext(OrthancPluginContext* context,
-                               size_t threadsCount,
+  PluginContext::PluginContext(size_t threadsCount,
                                size_t targetBucketSize,
                                size_t maxPushTransactions,
                                size_t memoryCacheSize) :
-    context_(context),
-    cache_(context),
     pushTransactions_(maxPushTransactions),
     semaphore_(threadsCount),
     threadsCount_(threadsCount),
@@ -58,13 +55,12 @@
   }
 
   
-  void PluginContext::Initialize(OrthancPluginContext* context,
-                                 size_t threadsCount,
+  void PluginContext::Initialize(size_t threadsCount,
                                  size_t targetBucketSize,
                                  size_t maxPushTransactions,
                                  size_t memoryCacheSize)
   {
-    GetSingleton().reset(new PluginContext(context, threadsCount, targetBucketSize,
+    GetSingleton().reset(new PluginContext(threadsCount, targetBucketSize,
                                            maxPushTransactions, memoryCacheSize));
   }
 
--- a/Plugin/PluginContext.h	Fri Sep 21 12:52:23 2018 +0200
+++ b/Plugin/PluginContext.h	Wed Dec 05 09:16:51 2018 +0100
@@ -32,7 +32,6 @@
   {
   private:
     // Runtime structures
-    OrthancPluginContext*    context_;
     OrthancInstancesCache    cache_;
     ActivePushTransactions   pushTransactions_;
     Orthanc::Semaphore       semaphore_;
@@ -43,8 +42,7 @@
     size_t                   targetBucketSize_;
 
   
-    PluginContext(OrthancPluginContext* context,
-                  size_t threadsCount,
+    PluginContext(size_t threadsCount,
                   size_t targetBucketSize,
                   size_t maxPushTransactions,
                   size_t memoryCacheSize);
@@ -52,11 +50,6 @@
     static std::auto_ptr<PluginContext>& GetSingleton();
   
   public:
-    OrthancPluginContext* GetOrthanc()
-    {
-      return context_;
-    }
-    
     OrthancInstancesCache& GetCache()
     {
       return cache_;
@@ -87,8 +80,7 @@
       return targetBucketSize_;
     }
 
-    static void Initialize(OrthancPluginContext* context,
-                           size_t threadsCount,
+    static void Initialize(size_t threadsCount,
                            size_t targetBucketSize,
                            size_t maxPushTransactions,
                            size_t memoryCacheSize);