changeset 568:77c8544bbd7d find-refactoring

merge
author Alain Mazy <am@orthanc.team>
date Mon, 23 Sep 2024 16:06:53 +0200
parents 22bbce1f88ff (current diff) a7f841fc4a9f (diff)
children f18e46d7dbf8 6667bd31beaf
files Framework/Plugins/DatabaseBackendAdapterV4.cpp Framework/Plugins/IndexBackend.cpp Framework/Plugins/IndexBackend.h
diffstat 4 files changed, 44 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Plugins/DatabaseBackendAdapterV4.cpp	Mon Sep 23 16:03:24 2024 +0200
+++ b/Framework/Plugins/DatabaseBackendAdapterV4.cpp	Mon Sep 23 16:06:53 2024 +0200
@@ -27,6 +27,7 @@
 #  if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 0)
 
 #include "IndexConnectionsPool.h"
+#include "MessagesToolbox.h"
 
 #include <OrthancDatabasePlugin.pb.h>  // Include protobuf messages
 
@@ -97,7 +98,6 @@
     Orthanc::DatabasePluginMessages::DeleteAttachment::Response*         deleteAttachment_;
     Orthanc::DatabasePluginMessages::DeleteResource::Response*           deleteResource_;
     Orthanc::DatabasePluginMessages::GetChanges::Response*               getChanges_;
-    Orthanc::DatabasePluginMessages::GetChangesExtended::Response*       getChangesExtended_;
     Orthanc::DatabasePluginMessages::GetExportedResources::Response*     getExportedResources_;
     Orthanc::DatabasePluginMessages::GetLastChange::Response*            getLastChange_;
     Orthanc::DatabasePluginMessages::GetLastExportedResource::Response*  getLastExportedResource_;
@@ -105,18 +105,25 @@
     Orthanc::DatabasePluginMessages::LookupAttachment::Response*         lookupAttachment_;
     Orthanc::DatabasePluginMessages::LookupResources::Response*          lookupResources_;
 
+#if ORTHANC_PLUGINS_HAS_CHANGES_EXTENDED == 1
+    Orthanc::DatabasePluginMessages::GetChangesExtended::Response*       getChangesExtended_;
+#endif
+
     void Clear()
     {
       deleteAttachment_ = NULL;
       deleteResource_ = NULL;
       getChanges_ = NULL;
-      getChangesExtended_ = NULL;
       getExportedResources_ = NULL;
       getLastChange_ = NULL;
       getLastExportedResource_ = NULL;
       getMainDicomTags_ = NULL;
       lookupAttachment_ = NULL;
       lookupResources_ = NULL;
+
+#if ORTHANC_PLUGINS_HAS_CHANGES_EXTENDED == 1
+      getChangesExtended_ = NULL;
+#endif
     }
     
   public:
@@ -138,11 +145,13 @@
       getChanges_ = &getChanges;
     }
 
+#if ORTHANC_PLUGINS_HAS_CHANGES_EXTENDED == 1
     Output(Orthanc::DatabasePluginMessages::GetChangesExtended::Response& getChangesExtended)
     {
       Clear();
       getChangesExtended_ = &getChangesExtended;
     }
+#endif
 
     Output(Orthanc::DatabasePluginMessages::GetExportedResources::Response& getExportedResources)
     {
@@ -296,10 +305,12 @@
       {
         change = getChanges_->add_changes();
       }
+#if ORTHANC_PLUGINS_HAS_CHANGES_EXTENDED == 1
       else if (getChangesExtended_ != NULL)
       {
         change = getChangesExtended_->add_changes();
       }
+#endif
       else if (getLastChange_ != NULL)
       {
         if (getLastChange_->found())
@@ -429,7 +440,7 @@
         response.mutable_get_system_information()->set_has_measure_latency(accessor.GetBackend().HasMeasureLatency());
 #endif
 
-#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
+#if ORTHANC_PLUGINS_HAS_INTEGRATED_FIND == 1
         response.mutable_get_system_information()->set_supports_find(accessor.GetBackend().HasFindSupport());
         response.mutable_get_system_information()->set_has_extended_changes(accessor.GetBackend().HasExtendedChanges());
 #endif
@@ -777,7 +788,7 @@
         response.mutable_get_changes()->set_done(done);
         break;
       }
-#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
+#if ORTHANC_PLUGINS_HAS_CHANGES_EXTENDED == 1
       case Orthanc::DatabasePluginMessages::OPERATION_GET_CHANGES_EXTENDED:
       {
         Output output(*response.mutable_get_changes_extended());
@@ -1310,11 +1321,13 @@
         break;
       }
       
+#if ORTHANC_PLUGINS_HAS_INTEGRATED_FIND == 1
       case Orthanc::DatabasePluginMessages::OPERATION_FIND:
       {
         backend.ExecuteFind(response, manager, request.find());
         break;
       }
+#endif
 
       default:
         LOG(ERROR) << "Not implemented transaction operation from protobuf: " << request.operation();
--- a/Framework/Plugins/IndexBackend.cpp	Mon Sep 23 16:03:24 2024 +0200
+++ b/Framework/Plugins/IndexBackend.cpp	Mon Sep 23 16:06:53 2024 +0200
@@ -125,13 +125,7 @@
   }
 
 
-  void IndexBackend::ReadChangesInternal(IDatabaseBackendOutput& output,
-                                         bool& done,
-                                         DatabaseManager& manager,
-                                         DatabaseManager::CachedStatement& statement,
-                                         const Dictionary& args,
-                                         uint32_t limit,
-                                         bool returnFirstResults)
+  namespace  // Anonymous namespace to avoid clashes between compilation modules
   {
     struct Change
     {
@@ -146,7 +140,17 @@
       {
       }
     };
-
+  }
+
+
+  void IndexBackend::ReadChangesInternal(IDatabaseBackendOutput& output,
+                                         bool& done,
+                                         DatabaseManager& manager,
+                                         DatabaseManager::CachedStatement& statement,
+                                         const Dictionary& args,
+                                         uint32_t limit,
+                                         bool returnFirstResults)
+  {
     statement.Execute(args);
 
     std::list<Change> changes;
@@ -647,10 +651,12 @@
       hasTo = true;
       filters.push_back("seq<=${to}");
     }
+#if ORTHANC_PLUGINS_HAS_CHANGES_EXTENDED == 1
     if (changeTypes.size() > 0)
     {
       filters.push_back("changeType IN (" + JoinChanges(changeTypes) + ") ");
     }
+#endif
 
     std::string filtersString;
     if (filters.size() > 0)
--- a/Framework/Plugins/IndexBackend.h	Mon Sep 23 16:03:24 2024 +0200
+++ b/Framework/Plugins/IndexBackend.h	Mon Sep 23 16:06:53 2024 +0200
@@ -429,11 +429,13 @@
 
     virtual uint64_t MeasureLatency(DatabaseManager& manager) ORTHANC_OVERRIDE;
 
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
     // New primitive since Orthanc 1.12.5
     virtual bool HasExtendedChanges() const ORTHANC_OVERRIDE
     {
       return true;
     }
+#endif
 
 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
     virtual bool HasFindSupport() const ORTHANC_OVERRIDE;
--- a/Framework/Plugins/MessagesToolbox.h	Mon Sep 23 16:03:24 2024 +0200
+++ b/Framework/Plugins/MessagesToolbox.h	Mon Sep 23 16:06:53 2024 +0200
@@ -24,17 +24,11 @@
 #pragma once
 
 #include <orthanc/OrthancCDatabasePlugin.h>
+#include <OrthancDatabasePlugin.pb.h>
 
 // Ensure that "ORTHANC_PLUGINS_VERSION_IS_ABOVE" is defined
 #include "../../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h"
 
-#if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE)         // Macro introduced in Orthanc 1.3.1
-#  if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
-#    include <OrthancDatabasePlugin.pb.h>
-#  endif
-#endif
-
-
 #define ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT 0
 
 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE)
@@ -55,6 +49,16 @@
 #endif
 
 
+#define ORTHANC_PLUGINS_HAS_CHANGES_EXTENDED 0
+
+#if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE)
+#  if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
+#    undef  ORTHANC_PLUGINS_HAS_CHANGES_EXTENDED
+#    define ORTHANC_PLUGINS_HAS_CHANGES_EXTENDED 1
+#  endif
+#endif
+
+
 #include <Enumerations.h>