changeset 5184:dd085f7e7e71

cleaning new constructors of StorageAccessor
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 25 Mar 2023 12:20:34 +0100
parents 5ec3dcdf78b9
children 0ea402b4d901
files OrthancFramework/Sources/FileStorage/StorageAccessor.cpp OrthancFramework/Sources/FileStorage/StorageAccessor.h OrthancFramework/UnitTestsSources/FileStorageTests.cpp OrthancServer/Sources/ServerContext.cpp OrthancServer/Sources/ServerToolbox.cpp
diffstat 5 files changed, 55 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/FileStorage/StorageAccessor.cpp	Sat Mar 25 12:07:39 2023 +0100
+++ b/OrthancFramework/Sources/FileStorage/StorageAccessor.cpp	Sat Mar 25 12:20:34 2023 +0100
@@ -62,18 +62,36 @@
   };
 
 
-  StorageAccessor::StorageAccessor(IStorageArea &area, StorageCache* cache) :
+  StorageAccessor::StorageAccessor(IStorageArea& area) :
     area_(area),
-    cache_(cache),
+    cache_(NULL),
+    metrics_(NULL)
+  {
+  }
+  
+
+  StorageAccessor::StorageAccessor(IStorageArea& area, 
+                                   StorageCache& cache) :
+    area_(area),
+    cache_(&cache),
     metrics_(NULL)
   {
   }
 
-  StorageAccessor::StorageAccessor(IStorageArea &area, 
-                                   StorageCache* cache,
-                                   MetricsRegistry &metrics) :
+
+  StorageAccessor::StorageAccessor(IStorageArea& area,
+                                   MetricsRegistry& metrics) :
     area_(area),
-    cache_(cache),
+    cache_(NULL),
+    metrics_(&metrics)
+  {
+  }
+
+  StorageAccessor::StorageAccessor(IStorageArea& area, 
+                                   StorageCache& cache,
+                                   MetricsRegistry& metrics) :
+    area_(area),
+    cache_(&cache),
     metrics_(&metrics)
   {
   }
--- a/OrthancFramework/Sources/FileStorage/StorageAccessor.h	Sat Mar 25 12:07:39 2023 +0100
+++ b/OrthancFramework/Sources/FileStorage/StorageAccessor.h	Sat Mar 25 12:20:34 2023 +0100
@@ -78,11 +78,16 @@
 #endif
 
   public:
-    explicit StorageAccessor(IStorageArea& area,
-                             StorageCache* cache);
+    explicit StorageAccessor(IStorageArea& area);
 
     StorageAccessor(IStorageArea& area,
-                    StorageCache* cache,
+                    StorageCache& cache);
+
+    StorageAccessor(IStorageArea& area,
+                    MetricsRegistry& metrics);
+
+    StorageAccessor(IStorageArea& area,
+                    StorageCache& cache,
                     MetricsRegistry& metrics);
 
     FileInfo Write(const void* data,
--- a/OrthancFramework/UnitTestsSources/FileStorageTests.cpp	Sat Mar 25 12:07:39 2023 +0100
+++ b/OrthancFramework/UnitTestsSources/FileStorageTests.cpp	Sat Mar 25 12:20:34 2023 +0100
@@ -127,7 +127,7 @@
 {
   FilesystemStorage s("UnitTestsStorage");
   StorageCache cache;
-  StorageAccessor accessor(s, &cache);
+  StorageAccessor accessor(s, cache);
 
   std::string data = "Hello world";
   FileInfo info = accessor.Write(data, FileContentType_Dicom, CompressionType_None, true);
@@ -149,7 +149,7 @@
 {
   FilesystemStorage s("UnitTestsStorage");
   StorageCache cache;
-  StorageAccessor accessor(s, &cache);
+  StorageAccessor accessor(s, cache);
 
   std::string data = "Hello world";
   FileInfo info = accessor.Write(data, FileContentType_Dicom, CompressionType_ZlibWithSize, true);
@@ -170,7 +170,7 @@
 {
   FilesystemStorage s("UnitTestsStorage");
   StorageCache cache;
-  StorageAccessor accessor(s, &cache);
+  StorageAccessor accessor(s, cache);
 
   std::string r;
   std::string compressedData = "Hello";
--- a/OrthancServer/Sources/ServerContext.cpp	Sat Mar 25 12:07:39 2023 +0100
+++ b/OrthancServer/Sources/ServerContext.cpp	Sat Mar 25 12:20:34 2023 +0100
@@ -520,7 +520,7 @@
   void ServerContext::RemoveFile(const std::string& fileUuid,
                                  FileContentType type)
   {
-    StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry());
+    StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
     accessor.Remove(fileUuid, type);
   }
 
@@ -566,7 +566,7 @@
     try
     {
       MetricsRegistry::Timer timer(GetMetricsRegistry(), "orthanc_store_dicom_duration_ms");
-      StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry());
+      StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
 
       DicomInstanceHasher hasher(summary);
       resultPublicId = hasher.HashInstance();
@@ -880,7 +880,7 @@
     }
     else
     {
-      StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry());
+      StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
       accessor.AnswerFile(output, attachment, GetFileContentMime(content));
     }
   }
@@ -910,7 +910,7 @@
 
     std::string content;
 
-    StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry());
+    StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
     accessor.Read(content, attachment);
 
     FileInfo modified = accessor.Write(content.empty() ? NULL : content.c_str(),
@@ -966,7 +966,7 @@
       std::string dicom;
 
       {
-        StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry());
+        StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
         accessor.Read(dicom, attachment);
       }
 
@@ -1032,7 +1032,7 @@
         std::string dicom;
         
         {
-          StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry());
+          StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
           accessor.ReadStartRange(dicom, attachment.GetUuid(), FileContentType_Dicom, pixelDataOffset);
         }
         
@@ -1055,7 +1055,7 @@
         std::string dicomAsJson;
 
         {
-          StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry());
+          StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
           accessor.Read(dicomAsJson, attachment);
         }
 
@@ -1161,7 +1161,7 @@
       {
         uint64_t pixelDataOffset = boost::lexical_cast<uint64_t>(s);
 
-        StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry());
+        StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
 
         accessor.ReadStartRange(dicom, attachment.GetUuid(), attachment.GetContentType(), pixelDataOffset);
         assert(dicom.size() == pixelDataOffset);
@@ -1196,24 +1196,26 @@
     assert(attachment.GetContentType() == content);
 
     {
-      StorageCache* cache = NULL;
-
-      if (!skipCache)
+      std::unique_ptr<StorageAccessor> accessor;
+      
+      if (skipCache)
       {
-        cache = &storageCache_;
+        accessor.reset(new StorageAccessor(area_, GetMetricsRegistry()));
       }
-
-      StorageAccessor accessor(area_, cache, GetMetricsRegistry());
+      else
+      {
+        accessor.reset(new StorageAccessor(area_, storageCache_, GetMetricsRegistry()));
+      }
 
       if (uncompressIfNeeded)
       {
-        accessor.Read(result, attachment);
+        accessor->Read(result, attachment);
       }
       else
       {
         // Do not uncompress the content of the storage area, return the
         // raw data
-        accessor.ReadRaw(result, attachment);
+        accessor->ReadRaw(result, attachment);
       }
     }
   }
@@ -1303,7 +1305,7 @@
     // TODO Should we use "gzip" instead?
     CompressionType compression = (compressionEnabled_ ? CompressionType_ZlibWithSize : CompressionType_None);
 
-    StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry());
+    StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
     FileInfo attachment = accessor.Write(data, size, attachmentType, compression, storeMD5_);
 
     try
--- a/OrthancServer/Sources/ServerToolbox.cpp	Sat Mar 25 12:07:39 2023 +0100
+++ b/OrthancServer/Sources/ServerToolbox.cpp	Sat Mar 25 12:20:34 2023 +0100
@@ -144,7 +144,7 @@
         try
         {
           // Read and parse the content of the DICOM file
-          StorageAccessor accessor(storageArea, NULL);  // no cache
+          StorageAccessor accessor(storageArea);  // no cache
 
           std::string content;
           accessor.Read(content, attachment);