diff OrthancServer/Plugins/Engine/OrthancPluginDatabase.cpp @ 4589:bec74e29f86b db-changes

attaching the listener to transactions in IDatabaseWrapper
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 12 Mar 2021 15:33:47 +0100
parents 9224e107d613
children ff8170d17d90
line wrap: on
line diff
--- a/OrthancServer/Plugins/Engine/OrthancPluginDatabase.cpp	Wed Mar 10 17:15:01 2021 +0100
+++ b/OrthancServer/Plugins/Engine/OrthancPluginDatabase.cpp	Fri Mar 12 15:33:47 2021 +0100
@@ -62,9 +62,18 @@
     }
 
   public:
-    explicit Transaction(OrthancPluginDatabase& that) :
+    explicit Transaction(OrthancPluginDatabase& that,
+                         IDatabaseListener& listener) :
       that_(that)
     {
+      assert(that_.listener_ == NULL);
+      that_.listener_ = &listener;   // TODO - STORE IN TRANSACTION
+    }
+
+    virtual ~Transaction()
+    {
+      assert(that_.listener_ != NULL);
+      that_.listener_ = NULL;   // TODO - STORE IN TRANSACTION
     }
 
     void Begin()
@@ -310,12 +319,39 @@
   }
 
 
+  namespace
+  {
+    class VoidListener : public IDatabaseListener
+    {
+    public:
+      virtual void SignalRemainingAncestor(ResourceType parentType,
+                                           const std::string& publicId)
+      {
+        throw OrthancException(ErrorCode_InternalError);  // Should be read-only transaction
+      }
+      
+      virtual void SignalAttachmentDeleted(const FileInfo& info)
+      {
+        throw OrthancException(ErrorCode_InternalError);  // Should be read-only transaction
+      }
+
+      virtual void SignalResourceDeleted(ResourceType type,
+                                         const std::string& publicId)
+      {
+        throw OrthancException(ErrorCode_InternalError);  // Should be read-only transaction
+      }      
+    };
+  }
+
+
   void OrthancPluginDatabase::Open()
   {
     CheckSuccess(backend_.open(payload_));
 
+    VoidListener listener;
+    
     {
-      Transaction transaction(*this);
+      Transaction transaction(*this, listener);
       transaction.Begin();
 
       std::string tmp;
@@ -889,11 +925,12 @@
   }
 
 
-  IDatabaseWrapper::ITransaction* OrthancPluginDatabase::StartTransaction(TransactionType type)
+  IDatabaseWrapper::ITransaction* OrthancPluginDatabase::StartTransaction(TransactionType type,
+                                                                          IDatabaseListener& listener)
   {
     // TODO - Take advantage of "type"
-    
-    std::unique_ptr<Transaction> transaction(new Transaction(*this));
+
+    std::unique_ptr<Transaction> transaction(new Transaction(*this, listener));
     transaction->Begin();
     return transaction.release();
   }
@@ -953,9 +990,11 @@
   void OrthancPluginDatabase::Upgrade(unsigned int targetVersion,
                                       IStorageArea& storageArea)
   {
+    VoidListener listener;
+    
     if (extensions_.upgradeDatabase != NULL)
     {
-      Transaction transaction(*this);
+      Transaction transaction(*this, listener);
       transaction.Begin();
 
       OrthancPluginErrorCode code = extensions_.upgradeDatabase(