diff OrthancServer/Plugins/Engine/OrthancPlugins.cpp @ 4595:cc64385593ef db-changes

added OrthancPluginRegisterDatabaseBackendV3() to plugin sdk
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 16 Mar 2021 17:58:16 +0100
parents ff8170d17d90
children c125bfd31023
line wrap: on
line diff
--- a/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Tue Mar 16 12:43:43 2021 +0100
+++ b/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Tue Mar 16 17:58:16 2021 +0100
@@ -71,6 +71,8 @@
 #include "../../Sources/Search/HierarchicalMatcher.h"
 #include "../../Sources/ServerContext.h"
 #include "../../Sources/ServerToolbox.h"
+#include "OrthancPluginDatabase.h"
+#include "OrthancPluginDatabaseV3.h"
 #include "PluginsEnumerations.h"
 #include "PluginsJob.h"
 
@@ -1191,6 +1193,7 @@
     int argc_;
     char** argv_;
     std::unique_ptr<OrthancPluginDatabase>  database_;
+    std::unique_ptr<OrthancPluginDatabaseV3>  databaseV3_;  // New in Orthanc 1.10.0
     PluginsErrorDictionary  dictionary_;
 
     PImpl() : 
@@ -4886,12 +4889,15 @@
 
       case _OrthancPluginService_RegisterDatabaseBackend:
       {
+        // TODO - WARN ABOUT PERFORMANCE
+        
         CLOG(INFO, PLUGINS) << "Plugin has registered a custom database back-end";
 
         const _OrthancPluginRegisterDatabaseBackend& p =
           *reinterpret_cast<const _OrthancPluginRegisterDatabaseBackend*>(parameters);
 
-        if (pimpl_->database_.get() == NULL)
+        if (pimpl_->database_.get() == NULL &&
+            pimpl_->databaseV3_.get() == NULL)
         {
           pimpl_->database_.reset(new OrthancPluginDatabase(plugin, GetErrorDictionary(), 
                                                             *p.backend, NULL, 0, p.payload));
@@ -4908,12 +4914,15 @@
 
       case _OrthancPluginService_RegisterDatabaseBackendV2:
       {
+        // TODO - WARN ABOUT PERFORMANCE
+        
         CLOG(INFO, PLUGINS) << "Plugin has registered a custom database back-end";
 
         const _OrthancPluginRegisterDatabaseBackendV2& p =
           *reinterpret_cast<const _OrthancPluginRegisterDatabaseBackendV2*>(parameters);
 
-        if (pimpl_->database_.get() == NULL)
+        if (pimpl_->database_.get() == NULL &&
+            pimpl_->databaseV3_.get() == NULL)
         {
           pimpl_->database_.reset(new OrthancPluginDatabase(plugin, GetErrorDictionary(),
                                                             *p.backend, p.extensions,
@@ -4929,6 +4938,27 @@
         return true;
       }
 
+      case _OrthancPluginService_RegisterDatabaseBackendV3:
+      {
+        CLOG(INFO, PLUGINS) << "Plugin has registered a custom database back-end";
+
+        const _OrthancPluginRegisterDatabaseBackendV3& p =
+          *reinterpret_cast<const _OrthancPluginRegisterDatabaseBackendV3*>(parameters);
+
+        if (pimpl_->database_.get() == NULL &&
+            pimpl_->databaseV3_.get() == NULL)
+        {
+          pimpl_->databaseV3_.reset(new OrthancPluginDatabaseV3(plugin, GetErrorDictionary(),
+                                                                p.backend, p.backendSize, p.database));
+        }
+        else
+        {
+          throw OrthancException(ErrorCode_DatabaseBackendAlreadyRegistered);
+        }
+
+        return true;
+      }
+
       case _OrthancPluginService_DatabaseAnswer:
         throw OrthancException(ErrorCode_InternalError);   // Implemented before locking (*)
 
@@ -5048,7 +5078,8 @@
   bool OrthancPlugins::HasDatabaseBackend() const
   {
     boost::recursive_mutex::scoped_lock lock(pimpl_->invokeServiceMutex_);
-    return pimpl_->database_.get() != NULL;
+    return (pimpl_->database_.get() != NULL ||
+            pimpl_->databaseV3_.get() != NULL);
   }
 
 
@@ -5080,27 +5111,35 @@
 
   IDatabaseWrapper& OrthancPlugins::GetDatabaseBackend()
   {
-    if (!HasDatabaseBackend())
+    if (pimpl_->database_.get() != NULL)
+    {
+      return *pimpl_->database_;
+    }
+    else if (pimpl_->databaseV3_.get() != NULL)
+    {
+      return *pimpl_->databaseV3_;
+    }
+    else
     {
       throw OrthancException(ErrorCode_BadSequenceOfCalls);
     }
-    else
-    {
-      return *pimpl_->database_;
-    }
   }
 
 
   const SharedLibrary& OrthancPlugins::GetDatabaseBackendLibrary() const
   {
-    if (!HasDatabaseBackend())
+    if (pimpl_->database_.get() != NULL)
+    {
+      return pimpl_->database_->GetSharedLibrary();
+    }
+    else if (pimpl_->databaseV3_.get() != NULL)
+    {
+      return pimpl_->databaseV3_->GetSharedLibrary();
+    }
+    else
     {
       throw OrthancException(ErrorCode_BadSequenceOfCalls);
     }
-    else
-    {
-      return pimpl_->database_->GetSharedLibrary();
-    }
   }