diff OrthancServer/Plugins/Engine/OrthancPlugins.cpp @ 5207:e7529e6241d2 db-protobuf

first successful protobuf communication
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 30 Mar 2023 21:31:56 +0200
parents 0ea402b4d901
children 9504de20d43d f2e1ad71e49c
line wrap: on
line diff
--- a/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Thu Mar 30 17:08:13 2023 +0200
+++ b/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Thu Mar 30 21:31:56 2023 +0200
@@ -63,6 +63,7 @@
 #include "../../Sources/ServerToolbox.h"
 #include "OrthancPluginDatabase.h"
 #include "OrthancPluginDatabaseV3.h"
+#include "OrthancPluginDatabaseV4.h"
 #include "PluginsEnumerations.h"
 #include "PluginsJob.h"
 
@@ -1544,8 +1545,9 @@
     Properties properties_;
     int argc_;
     char** argv_;
-    std::unique_ptr<OrthancPluginDatabase>  database_;
+    std::unique_ptr<OrthancPluginDatabase>    database_;
     std::unique_ptr<OrthancPluginDatabaseV3>  databaseV3_;  // New in Orthanc 1.9.2
+    std::unique_ptr<OrthancPluginDatabaseV4>  databaseV4_;  // New in Orthanc 1.12.0
     PluginsErrorDictionary  dictionary_;
     std::string databaseServerIdentifier_;   // New in Orthanc 1.9.2
     unsigned int maxDatabaseRetries_;   // New in Orthanc 1.9.2
@@ -5487,14 +5489,15 @@
 
       case _OrthancPluginService_RegisterDatabaseBackend:
       {
-        LOG(WARNING) << "Performance warning: Plugin has registered a custom database back-end with an old API";
+        LOG(WARNING) << "Performance warning: Plugin has registered a custom database back-end with an old API (version 1)";
         LOG(WARNING) << "The database backend has *no* support for revisions of metadata and attachments";
 
         const _OrthancPluginRegisterDatabaseBackend& p =
           *reinterpret_cast<const _OrthancPluginRegisterDatabaseBackend*>(parameters);
 
         if (pimpl_->database_.get() == NULL &&
-            pimpl_->databaseV3_.get() == NULL)
+            pimpl_->databaseV3_.get() == NULL &&
+            pimpl_->databaseV4_.get() == NULL)
         {
           pimpl_->database_.reset(new OrthancPluginDatabase(plugin, GetErrorDictionary(), 
                                                             *p.backend, NULL, 0, p.payload));
@@ -5511,14 +5514,15 @@
 
       case _OrthancPluginService_RegisterDatabaseBackendV2:
       {
-        LOG(WARNING) << "Performance warning: Plugin has registered a custom database back-end with an old API";
+        LOG(WARNING) << "Performance warning: Plugin has registered a custom database back-end with an old API (version 2)";
         LOG(WARNING) << "The database backend has *no* support for revisions of metadata and attachments";
 
         const _OrthancPluginRegisterDatabaseBackendV2& p =
           *reinterpret_cast<const _OrthancPluginRegisterDatabaseBackendV2*>(parameters);
 
         if (pimpl_->database_.get() == NULL &&
-            pimpl_->databaseV3_.get() == NULL)
+            pimpl_->databaseV3_.get() == NULL &&
+            pimpl_->databaseV4_.get() == NULL)
         {
           pimpl_->database_.reset(new OrthancPluginDatabase(plugin, GetErrorDictionary(),
                                                             *p.backend, p.extensions,
@@ -5536,13 +5540,14 @@
 
       case _OrthancPluginService_RegisterDatabaseBackendV3:
       {
-        CLOG(INFO, PLUGINS) << "Plugin has registered a custom database back-end";
+        LOG(WARNING) << "Performance warning: Plugin has registered a custom database back-end with an old API (version 3)";
 
         const _OrthancPluginRegisterDatabaseBackendV3& p =
           *reinterpret_cast<const _OrthancPluginRegisterDatabaseBackendV3*>(parameters);
 
         if (pimpl_->database_.get() == NULL &&
-            pimpl_->databaseV3_.get() == NULL)
+            pimpl_->databaseV3_.get() == NULL &&
+            pimpl_->databaseV4_.get() == NULL)
         {
           pimpl_->databaseV3_.reset(new OrthancPluginDatabaseV3(plugin, GetErrorDictionary(), p.backend,
                                                                 p.backendSize, p.database, pimpl_->databaseServerIdentifier_));
@@ -5556,6 +5561,28 @@
         return true;
       }
 
+      case _OrthancPluginService_RegisterDatabaseBackendV4:
+      {
+        CLOG(INFO, PLUGINS) << "Plugin has registered a custom database back-end";
+
+        const _OrthancPluginRegisterDatabaseBackendV4& p =
+          *reinterpret_cast<const _OrthancPluginRegisterDatabaseBackendV4*>(parameters);
+
+        if (pimpl_->database_.get() == NULL &&
+            pimpl_->databaseV3_.get() == NULL &&
+            pimpl_->databaseV4_.get() == NULL)
+        {
+          pimpl_->databaseV4_.reset(new OrthancPluginDatabaseV4(plugin, GetErrorDictionary(), p, pimpl_->databaseServerIdentifier_));
+          pimpl_->maxDatabaseRetries_ = p.maxDatabaseRetries;
+        }
+        else
+        {
+          throw OrthancException(ErrorCode_DatabaseBackendAlreadyRegistered);
+        }
+
+        return true;
+      }
+
       case _OrthancPluginService_DatabaseAnswer:
         throw OrthancException(ErrorCode_InternalError);   // Implemented before locking (*)
 
@@ -5695,7 +5722,8 @@
   {
     boost::recursive_mutex::scoped_lock lock(pimpl_->invokeServiceMutex_);
     return (pimpl_->database_.get() != NULL ||
-            pimpl_->databaseV3_.get() != NULL);
+            pimpl_->databaseV3_.get() != NULL ||
+            pimpl_->databaseV4_.get() != NULL);
   }
 
 
@@ -5735,6 +5763,10 @@
     {
       return *pimpl_->databaseV3_;
     }
+    else if (pimpl_->databaseV4_.get() != NULL)
+    {
+      return *pimpl_->databaseV4_;
+    }
     else
     {
       throw OrthancException(ErrorCode_BadSequenceOfCalls);
@@ -5752,6 +5784,10 @@
     {
       return pimpl_->databaseV3_->GetSharedLibrary();
     }
+    else if (pimpl_->databaseV4_.get() != NULL)
+    {
+      return pimpl_->databaseV4_->GetSharedLibrary();
+    }
     else
     {
       throw OrthancException(ErrorCode_BadSequenceOfCalls);