changeset 395:a7a029043670 db-protobuf

integration mainline->db-protobuf
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 05 Apr 2023 14:53:57 +0200
parents d941568543a0 (diff) 2fd272ea8f00 (current diff)
children 7b3acfa95bd8
files
diffstat 13 files changed, 130 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Plugins/DatabaseBackendAdapterV2.cpp	Wed Apr 05 14:53:36 2023 +0200
+++ b/Framework/Plugins/DatabaseBackendAdapterV2.cpp	Wed Apr 05 14:53:57 2023 +0200
@@ -1419,7 +1419,10 @@
         lookup.push_back(Orthanc::DatabaseConstraint(constraints[i]));
       }
         
-      adapter->GetBackend().LookupResources(*output, accessor.GetManager(), lookup, queryLevel, limit, (requestSomeInstance != 0));
+      std::set<std::string> noLabels;
+      adapter->GetBackend().LookupResources(*output, accessor.GetManager(), lookup, queryLevel,
+                                            noLabels, noLabels, limit, (requestSomeInstance != 0));
+      
       return OrthancPluginErrorCode_Success;
     }
     ORTHANC_PLUGINS_DATABASE_CATCH;
--- a/Framework/Plugins/DatabaseBackendAdapterV3.cpp	Wed Apr 05 14:53:36 2023 +0200
+++ b/Framework/Plugins/DatabaseBackendAdapterV3.cpp	Wed Apr 05 14:53:57 2023 +0200
@@ -1646,7 +1646,9 @@
         lookup.push_back(Orthanc::DatabaseConstraint(constraints[i]));
       }
         
-      t->GetBackend().LookupResources(t->GetOutput(), t->GetManager(), lookup, queryLevel, limit, (requestSomeInstanceId != 0));
+      std::set<std::string> noLabels;
+      t->GetBackend().LookupResources(t->GetOutput(), t->GetManager(), lookup, queryLevel,
+                                      noLabels, noLabels, limit, (requestSomeInstanceId != 0));
       return OrthancPluginErrorCode_Success;
     }
     ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext());
--- a/Framework/Plugins/DatabaseBackendAdapterV4.cpp	Wed Apr 05 14:53:36 2023 +0200
+++ b/Framework/Plugins/DatabaseBackendAdapterV4.cpp	Wed Apr 05 14:53:57 2023 +0200
@@ -567,9 +567,21 @@
 
     assert(values.size() == countValues);
 
+    std::set<std::string> withLabels, withoutLabels;
+
+    for (int i = 0; i < request.with_labels().size(); i++)
+    {
+      withLabels.insert(request.with_labels(i));
+    }
+
+    for (int i = 0; i < request.without_labels().size(); i++)
+    {
+      withoutLabels.insert(request.without_labels(i));
+    }
+    
     Output output(response);
     backend.LookupResources(output, manager, lookup, Convert(request.query_level()),
-                            request.limit(), request.retrieve_instances_ids());
+                            withLabels, withoutLabels, request.limit(), request.retrieve_instances_ids());
   }
 
   
--- a/Framework/Plugins/IDatabaseBackend.h	Wed Apr 05 14:53:36 2023 +0200
+++ b/Framework/Plugins/IDatabaseBackend.h	Wed Apr 05 14:53:57 2023 +0200
@@ -271,6 +271,8 @@
                                  DatabaseManager& manager,
                                  const std::vector<Orthanc::DatabaseConstraint>& lookup,
                                  OrthancPluginResourceType queryLevel,
+                                 const std::set<std::string>& withLabels,     // New in Orthanc 1.12.0
+                                 const std::set<std::string>& withoutLabels,  // New in Orthanc 1.12.0
                                  uint32_t limit,
                                  bool requestSomeInstance) = 0;
 #endif
@@ -307,23 +309,30 @@
     virtual void TagMostRecentPatient(DatabaseManager& manager,
                                       int64_t patientId) = 0;
 
-#if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE)      // Macro introduced in 1.3.1
-#  if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 4)
     // NB: "parentPublicId" must be cleared if the resource has no parent
     virtual bool LookupResourceAndParent(int64_t& id,
                                          OrthancPluginResourceType& type,
                                          std::string& parentPublicId,
                                          DatabaseManager& manager,
                                          const char* publicId) = 0;
-#  endif
-#endif
 
-#if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE)      // Macro introduced in 1.3.1
-#  if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 4)
     virtual void GetAllMetadata(std::map<int32_t, std::string>& result,
                                 DatabaseManager& manager,
                                 int64_t id) = 0;
-#  endif
-#endif
+
+    // New in Orthanc 1.12.0
+    virtual bool HasLabelsSupport() const = 0;
+
+    // New in Orthanc 1.12.0
+    virtual void AddLabel(int64_t resource,
+                          const std::string& label) = 0;
+
+    // New in Orthanc 1.12.0
+    virtual void RemoveLabel(int64_t resource,
+                             const std::string& label) = 0;
+
+    // New in Orthanc 1.12.0
+    virtual void ListLabels(std::set<std::string>& target,
+                            int64_t resource) = 0;
   };
 }
--- a/Framework/Plugins/IndexBackend.cpp	Wed Apr 05 14:53:36 2023 +0200
+++ b/Framework/Plugins/IndexBackend.cpp	Wed Apr 05 14:53:57 2023 +0200
@@ -2065,9 +2065,17 @@
                                      DatabaseManager& manager,
                                      const std::vector<Orthanc::DatabaseConstraint>& lookup,
                                      OrthancPluginResourceType queryLevel,
+                                     const std::set<std::string>& withLabels,
+                                     const std::set<std::string>& withoutLabels,
                                      uint32_t limit,
                                      bool requestSomeInstance)
   {
+    if (!withLabels.empty() ||
+        !withoutLabels.empty())
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
+    }
+
     LookupFormatter formatter(manager.GetDialect());
 
     std::string sql;
@@ -2609,6 +2617,27 @@
 #endif
 
 
+  void IndexBackend::AddLabel(int64_t resource,
+                              const std::string& label)
+  {
+    throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
+  }
+
+
+  void IndexBackend::RemoveLabel(int64_t resource,
+                                 const std::string& label)
+  {
+    throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
+  }
+
+
+  void IndexBackend::ListLabels(std::set<std::string>& target,
+                                int64_t resource)
+  {
+    throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
+  }
+  
+
   void IndexBackend::Register(IndexBackend* backend,
                               size_t countConnections,
                               unsigned int maxDatabaseRetries)
--- a/Framework/Plugins/IndexBackend.h	Wed Apr 05 14:53:36 2023 +0200
+++ b/Framework/Plugins/IndexBackend.h	Wed Apr 05 14:53:57 2023 +0200
@@ -302,6 +302,8 @@
                                  DatabaseManager& manager,
                                  const std::vector<Orthanc::DatabaseConstraint>& lookup,
                                  OrthancPluginResourceType queryLevel,
+                                 const std::set<std::string>& withLabels,
+                                 const std::set<std::string>& withoutLabels,
                                  uint32_t limit,
                                  bool requestSomeInstance) ORTHANC_OVERRIDE;
 #endif
@@ -327,25 +329,17 @@
     virtual void TagMostRecentPatient(DatabaseManager& manager,
                                       int64_t patient) ORTHANC_OVERRIDE;
 
-#if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE)      // Macro introduced in 1.3.1
-#  if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 4)
     // New primitive since Orthanc 1.5.4
     virtual bool LookupResourceAndParent(int64_t& id,
                                          OrthancPluginResourceType& type,
                                          std::string& parentPublicId,
                                          DatabaseManager& manager,
                                          const char* publicId) ORTHANC_OVERRIDE;
-#  endif
-#endif
 
-#if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE)      // Macro introduced in 1.3.1
-#  if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 4)
     // New primitive since Orthanc 1.5.4
     virtual void GetAllMetadata(std::map<int32_t, std::string>& result,
                                 DatabaseManager& manager,
                                 int64_t id) ORTHANC_OVERRIDE;
-#  endif
-#endif
 
     virtual bool HasCreateInstance() const ORTHANC_OVERRIDE
     {
@@ -387,6 +381,15 @@
                                   int32_t property,
                                   int value);
 
+    virtual void AddLabel(int64_t resource,
+                          const std::string& label) ORTHANC_OVERRIDE;
+
+    virtual void RemoveLabel(int64_t resource,
+                             const std::string& label) ORTHANC_OVERRIDE;
+
+    virtual void ListLabels(std::set<std::string>& target,
+                            int64_t resource) ORTHANC_OVERRIDE;
+    
     /**
      * "maxDatabaseRetries" is to handle
      * "OrthancPluginErrorCode_DatabaseCannotSerialize" if there is a
--- a/MySQL/Plugins/MySQLIndex.h	Wed Apr 05 14:53:36 2023 +0200
+++ b/MySQL/Plugins/MySQLIndex.h	Wed Apr 05 14:53:57 2023 +0200
@@ -76,5 +76,11 @@
                                 const char* hashInstance)
       ORTHANC_OVERRIDE;
 #endif
+
+    // New primitive since Orthanc 1.12.0
+    virtual bool HasLabelsSupport() const ORTHANC_OVERRIDE
+    {
+      return false;
+    }
   };
 }
--- a/Odbc/CMakeLists.txt	Wed Apr 05 14:53:36 2023 +0200
+++ b/Odbc/CMakeLists.txt	Wed Apr 05 14:53:57 2023 +0200
@@ -24,14 +24,14 @@
 set(ORTHANC_PLUGIN_VERSION "mainline")
 
 set(ORTHANC_OPTIMAL_VERSION_MAJOR    1)
-set(ORTHANC_OPTIMAL_VERSION_MINOR    9)
-set(ORTHANC_OPTIMAL_VERSION_REVISION 2)
+set(ORTHANC_OPTIMAL_VERSION_MINOR    12)
+set(ORTHANC_OPTIMAL_VERSION_REVISION 0)
 
 if (ORTHANC_PLUGIN_VERSION STREQUAL "mainline")
   set(ORTHANC_FRAMEWORK_VERSION "mainline")
   set(ORTHANC_FRAMEWORK_DEFAULT_SOURCE "hg")
 else()
-  set(ORTHANC_FRAMEWORK_VERSION "1.9.6")
+  set(ORTHANC_FRAMEWORK_VERSION "1.12.0")
   set(ORTHANC_FRAMEWORK_DEFAULT_SOURCE "web")
 endif()
 
@@ -79,6 +79,23 @@
   ODBC_PREPARE_STORAGE  ${CMAKE_SOURCE_DIR}/Plugins/PrepareStorage.sql
   )
 
+if (EXISTS ${ORTHANC_SDK_ROOT}/orthanc/OrthancDatabasePlugin.proto)
+  add_custom_command(
+    COMMAND
+    ${PROTOC_EXECUTABLE} ${ORTHANC_SDK_ROOT}/orthanc/OrthancDatabasePlugin.proto --cpp_out=${AUTOGENERATED_DIR} -I${ORTHANC_SDK_ROOT}/orthanc/
+    DEPENDS
+    ProtobufCompiler
+    ${ORTHANC_SDK_ROOT}/orthanc/OrthancDatabasePlugin.proto
+    OUTPUT
+    ${AUTOGENERATED_DIR}/OrthancDatabasePlugin.pb.cc
+    ${AUTOGENERATED_DIR}/OrthancDatabasePlugin.pb.h
+    )
+
+  list(APPEND AUTOGENERATED_SOURCES
+    ${AUTOGENERATED_DIR}/OrthancDatabasePlugin.pb.cc
+    )
+endif()
+
 add_custom_target(
   AutogeneratedTarget
   DEPENDS 
--- a/Odbc/NEWS	Wed Apr 05 14:53:36 2023 +0200
+++ b/Odbc/NEWS	Wed Apr 05 14:53:57 2023 +0200
@@ -1,6 +1,9 @@
 Pending changes in the mainline
 ===============================
 
+* Compatibility with Orthanc SDK 1.12.0 (communications between the
+  Orthanc core and the database plugin using Google Protocol Buffers)
+
 
 Release 1.1 (2021-12-06)
 ========================
--- a/Odbc/Plugins/IndexPlugin.cpp	Wed Apr 05 14:53:36 2023 +0200
+++ b/Odbc/Plugins/IndexPlugin.cpp	Wed Apr 05 14:53:57 2023 +0200
@@ -42,6 +42,9 @@
 #endif
 
 
+#include <google/protobuf/any.h>
+
+
 static const char* const KEY_ODBC = "Odbc";
 
 
@@ -54,6 +57,8 @@
   
   ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context)
   {
+    GOOGLE_PROTOBUF_VERIFY_VERSION;
+
     if (!OrthancDatabases::InitializePlugin(context, "ODBC", true))
     {
       return -1;
@@ -130,6 +135,7 @@
   {
     LOG(WARNING) << "ODBC index is finalizing";
     OrthancDatabases::IndexBackend::Finalize();
+    google::protobuf::ShutdownProtobufLibrary();
   }
 
 
--- a/Odbc/Plugins/OdbcIndex.h	Wed Apr 05 14:53:36 2023 +0200
+++ b/Odbc/Plugins/OdbcIndex.h	Wed Apr 05 14:53:57 2023 +0200
@@ -83,5 +83,11 @@
                                   DatabaseManager& manager,
                                   int64_t id,
                                   int32_t attachment) ORTHANC_OVERRIDE;
+    
+    // New primitive since Orthanc 1.12.0
+    virtual bool HasLabelsSupport() const ORTHANC_OVERRIDE
+    {
+      return false;
+    }
   };
 }
--- a/PostgreSQL/Plugins/PostgreSQLIndex.h	Wed Apr 05 14:53:36 2023 +0200
+++ b/PostgreSQL/Plugins/PostgreSQLIndex.h	Wed Apr 05 14:53:57 2023 +0200
@@ -82,5 +82,11 @@
 
     virtual void TagMostRecentPatient(DatabaseManager& manager,
                                       int64_t patient) ORTHANC_OVERRIDE;
+
+    // New primitive since Orthanc 1.12.0
+    virtual bool HasLabelsSupport() const ORTHANC_OVERRIDE
+    {
+      return false;
+    }
   };
 }
--- a/SQLite/Plugins/SQLiteIndex.h	Wed Apr 05 14:53:36 2023 +0200
+++ b/SQLite/Plugins/SQLiteIndex.h	Wed Apr 05 14:53:57 2023 +0200
@@ -58,5 +58,11 @@
 
     // New primitive since Orthanc 1.5.2
     virtual int64_t GetLastChangeIndex(DatabaseManager& manager) ORTHANC_OVERRIDE;
+
+    // New primitive since Orthanc 1.12.0
+    virtual bool HasLabelsSupport() const ORTHANC_OVERRIDE
+    {
+      return false;
+    }
   };
 }