changeset 4571:9224e107d613 db-changes

simplifying IDatabaseListener::SignalChange() as IDatabaseListener::SignalResourceDeleted()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 08 Mar 2021 16:49:34 +0100
parents 648defffc8cc
children c12d4e5f469b
files OrthancServer/Plugins/Engine/OrthancPluginDatabase.cpp OrthancServer/Sources/Database/IDatabaseListener.h OrthancServer/Sources/Database/IDatabaseWrapper.h OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp OrthancServer/Sources/ServerIndex.cpp OrthancServer/UnitTestsSources/ServerIndexTests.cpp
diffstat 6 files changed, 24 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Plugins/Engine/OrthancPluginDatabase.cpp	Mon Mar 08 16:04:56 2021 +0100
+++ b/OrthancServer/Plugins/Engine/OrthancPluginDatabase.cpp	Mon Mar 08 16:49:34 2021 +0100
@@ -908,7 +908,7 @@
       {
         const OrthancPluginAttachment& attachment = 
           *reinterpret_cast<const OrthancPluginAttachment*>(answer.valueGeneric);
-        listener.SignalFileDeleted(Convert(attachment));
+        listener.SignalAttachmentDeleted(Convert(attachment));
         break;
       }
         
@@ -922,8 +922,7 @@
       case _OrthancPluginDatabaseAnswerType_DeletedResource:
       {
         ResourceType type = Plugins::Convert(static_cast<OrthancPluginResourceType>(answer.valueInt32));
-        ServerIndexChange change(ChangeType_Deleted, type, answer.valueString);
-        listener.SignalChange(change);
+        listener.SignalResourceDeleted(type, answer.valueString);
         break;
       }
 
--- a/OrthancServer/Sources/Database/IDatabaseListener.h	Mon Mar 08 16:04:56 2021 +0100
+++ b/OrthancServer/Sources/Database/IDatabaseListener.h	Mon Mar 08 16:49:34 2021 +0100
@@ -33,8 +33,8 @@
 
 #pragma once
 
+#include "../../OrthancFramework/Sources/FileStorage/FileInfo.h"
 #include "../ServerEnumerations.h"
-#include "../ServerIndexChange.h"
 
 #include <string>
 
@@ -50,8 +50,9 @@
     virtual void SignalRemainingAncestor(ResourceType parentType,
                                          const std::string& publicId) = 0;
 
-    virtual void SignalFileDeleted(const FileInfo& info) = 0;
+    virtual void SignalAttachmentDeleted(const FileInfo& info) = 0;
 
-    virtual void SignalChange(const ServerIndexChange& change) = 0;
+    virtual void SignalResourceDeleted(ResourceType type,
+                                       const std::string& publicId) = 0;
   };
 }
--- a/OrthancServer/Sources/Database/IDatabaseWrapper.h	Mon Mar 08 16:04:56 2021 +0100
+++ b/OrthancServer/Sources/Database/IDatabaseWrapper.h	Mon Mar 08 16:49:34 2021 +0100
@@ -39,6 +39,7 @@
 #include "../../../OrthancFramework/Sources/SQLite/ITransaction.h"
 
 #include "../ExportedResource.h"
+#include "../ServerIndexChange.h"
 #include "IDatabaseListener.h"
 
 #include <list>
--- a/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp	Mon Mar 08 16:04:56 2021 +0100
+++ b/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp	Mon Mar 08 16:49:34 2021 +0100
@@ -92,7 +92,7 @@
                       static_cast<uint64_t>(context.GetInt64Value(4)),
                       compressedMD5);
         
-        listener_.SignalFileDeleted(info);
+        listener_.SignalAttachmentDeleted(info);
       }
     };
 
@@ -119,9 +119,8 @@
 
       virtual void Compute(SQLite::FunctionContext& context) ORTHANC_OVERRIDE
       {
-        ResourceType type = static_cast<ResourceType>(context.GetIntValue(1));
-        ServerIndexChange change(ChangeType_Deleted, type, context.GetStringValue(0));
-        listener_.SignalChange(change);
+        listener_.SignalResourceDeleted(static_cast<ResourceType>(context.GetIntValue(1)),
+                                        context.GetStringValue(0));
       }
     };
 
--- a/OrthancServer/Sources/ServerIndex.cpp	Mon Mar 08 16:04:56 2021 +0100
+++ b/OrthancServer/Sources/ServerIndex.cpp	Mon Mar 08 16:49:34 2021 +0100
@@ -177,7 +177,7 @@
     }
 
     virtual void SignalRemainingAncestor(ResourceType parentType,
-                                         const std::string& publicId)
+                                         const std::string& publicId) ORTHANC_OVERRIDE
     {
       LOG(TRACE) << "Remaining ancestor \"" << publicId << "\" (" << parentType << ")";
 
@@ -197,14 +197,20 @@
       }        
     }
 
-    virtual void SignalFileDeleted(const FileInfo& info)
+    virtual void SignalAttachmentDeleted(const FileInfo& info) ORTHANC_OVERRIDE
     {
       assert(Toolbox::IsUuid(info.GetUuid()));
       pendingFilesToRemove_.push_back(FileToRemove(info));
       sizeOfFilesToRemove_ += info.GetCompressedSize();
     }
 
-    virtual void SignalChange(const ServerIndexChange& change)
+    virtual void SignalResourceDeleted(ResourceType type,
+                                       const std::string& publicId) ORTHANC_OVERRIDE
+    {
+      SignalChange(ServerIndexChange(ChangeType_Deleted, type, publicId));
+    }
+
+    void SignalChange(const ServerIndexChange& change)
     {
       LOG(TRACE) << "Change related to resource " << change.GetPublicId() << " of type " 
                  << EnumerationToString(change.GetResourceType()) << ": " 
--- a/OrthancServer/UnitTestsSources/ServerIndexTests.cpp	Mon Mar 08 16:04:56 2021 +0100
+++ b/OrthancServer/UnitTestsSources/ServerIndexTests.cpp	Mon Mar 08 16:49:34 2021 +0100
@@ -75,23 +75,18 @@
       ancestorType_ = type;
     }
 
-    virtual void SignalFileDeleted(const FileInfo& info) ORTHANC_OVERRIDE
+    virtual void SignalAttachmentDeleted(const FileInfo& info) ORTHANC_OVERRIDE
     {
       const std::string fileUuid = info.GetUuid();
       deletedFiles_.push_back(fileUuid);
       LOG(INFO) << "A file must be removed: " << fileUuid;
     }       
 
-    virtual void SignalChange(const ServerIndexChange& change) ORTHANC_OVERRIDE
+    virtual void SignalResourceDeleted(ResourceType type,
+                                       const std::string& publicId)
     {
-      if (change.GetChangeType() == ChangeType_Deleted)
-      {
-        deletedResources_.push_back(change.GetPublicId());        
-      }
-
-      LOG(INFO) << "Change related to resource " << change.GetPublicId() << " of type " 
-                << EnumerationToString(change.GetResourceType()) << ": " 
-                << EnumerationToString(change.GetChangeType());
+      LOG(INFO) << "Deleted resource " << publicId << " of type " << EnumerationToString(type);
+      deletedResources_.push_back(publicId);
     }
   };