changeset 4509:98b7b9d21d83

removed ServerContext::ReadAttachment()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 11 Feb 2021 17:11:37 +0100
parents 8f9090b137f1
children a3635a01a945
files OrthancServer/Sources/ServerContext.cpp OrthancServer/Sources/ServerContext.h OrthancServer/Sources/ServerJobs/ArchiveJob.cpp
diffstat 3 files changed, 38 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Sources/ServerContext.cpp	Thu Feb 11 11:00:05 2021 +0100
+++ b/OrthancServer/Sources/ServerContext.cpp	Thu Feb 11 17:11:37 2021 +0100
@@ -813,7 +813,8 @@
     FileInfo attachment;
     if (index_.LookupAttachment(attachment, instancePublicId, FileContentType_DicomAsJson))
     {
-      ReadAttachment(result, attachment);
+      StorageAccessor accessor(area_, GetMetricsRegistry());
+      accessor.Read(result, attachment);
     }
     else
     {
@@ -886,6 +887,13 @@
   }
 
 
+  void ServerContext::ReadDicom(std::string& dicom,
+                                const std::string& instancePublicId)
+  {
+    ReadAttachment(dicom, instancePublicId, FileContentType_Dicom, true /* uncompress */);
+  }
+    
+
   void ServerContext::ReadAttachment(std::string& result,
                                      const std::string& instancePublicId,
                                      FileContentType content,
@@ -901,29 +909,23 @@
 
     assert(attachment.GetContentType() == content);
 
-    if (uncompressIfNeeded)
     {
-      ReadAttachment(result, attachment);
-    }
-    else
-    {
-      // Do not uncompress the content of the storage area, return the
-      // raw data
       StorageAccessor accessor(area_, GetMetricsRegistry());
-      accessor.ReadRaw(result, attachment);
+
+      if (uncompressIfNeeded)
+      {
+        accessor.Read(result, attachment);
+      }
+      else
+      {
+        // Do not uncompress the content of the storage area, return the
+        // raw data
+        accessor.ReadRaw(result, attachment);
+      }
     }
   }
 
 
-  void ServerContext::ReadAttachment(std::string& result,
-                                     const FileInfo& attachment)
-  {
-    // This will decompress the attachment
-    StorageAccessor accessor(area_, GetMetricsRegistry());
-    accessor.Read(result, attachment);
-  }
-
-
   ServerContext::DicomCacheLocker::DicomCacheLocker(ServerContext& context,
                                                     const std::string& instancePublicId) :
     context_(context),
--- a/OrthancServer/Sources/ServerContext.h	Thu Feb 11 11:00:05 2021 +0100
+++ b/OrthancServer/Sources/ServerContext.h	Thu Feb 11 17:11:37 2021 +0100
@@ -338,10 +338,7 @@
     }
 
     void ReadDicom(std::string& dicom,
-                   const std::string& instancePublicId)
-    {
-      ReadAttachment(dicom, instancePublicId, FileContentType_Dicom, true);
-    }
+                   const std::string& instancePublicId);
     
     // TODO CACHING MECHANISM AT THIS POINT
     void ReadAttachment(std::string& result,
@@ -349,9 +346,6 @@
                         FileContentType content,
                         bool uncompressIfNeeded);
     
-    void ReadAttachment(std::string& result,
-                        const FileInfo& attachment);
-
     void SetStoreMD5ForAttachments(bool storeMD5);
 
     bool IsStoreMD5ForAttachments() const
--- a/OrthancServer/Sources/ServerJobs/ArchiveJob.cpp	Thu Feb 11 11:00:05 2021 +0100
+++ b/OrthancServer/Sources/ServerJobs/ArchiveJob.cpp	Thu Feb 11 17:11:37 2021 +0100
@@ -195,7 +195,7 @@
     virtual void Close() = 0;
 
     virtual void AddInstance(const std::string& instanceId,
-                             const FileInfo& dicom) = 0;
+                             size_t uncompressedSize) = 0;
   };
 
 
@@ -205,11 +205,12 @@
     struct Instance
     {
       std::string  id_;
-      FileInfo     dicom_;
+      uint64_t     uncompressedSize_;
 
       Instance(const std::string& id,
-               const FileInfo& dicom) : 
-        id_(id), dicom_(dicom)
+               uint64_t uncompressedSize) : 
+        id_(id),
+        uncompressedSize_(uncompressedSize)
       {
       }
     };
@@ -230,7 +231,7 @@
         FileInfo tmp;
         if (index.LookupAttachment(tmp, id, FileContentType_Dicom))
         {
-          instances_.push_back(Instance(id, tmp));
+          instances_.push_back(Instance(id, tmp.GetUncompressedSize()));
         }
       }
       else
@@ -335,7 +336,7 @@
         for (std::list<Instance>::const_iterator 
                it = instances_.begin(); it != instances_.end(); ++it)
         {
-          visitor.AddInstance(it->id_, it->dicom_);
+          visitor.AddInstance(it->id_, it->uncompressedSize_);
         }          
       }
       else
@@ -370,7 +371,6 @@
       Type          type_;
       std::string   filename_;
       std::string   instanceId_;
-      FileInfo      info_;
 
     public:
       explicit Command(Type type) :
@@ -389,12 +389,10 @@
         
       Command(Type type,
               const std::string& filename,
-              const std::string& instanceId,
-              const FileInfo& info) :
+              const std::string& instanceId) :
         type_(type),
         filename_(filename),
-        instanceId_(instanceId),
-        info_(info)
+        instanceId_(instanceId)
       {
         assert(type_ == Type_WriteInstance);
       }
@@ -422,7 +420,7 @@
 
             try
             {
-              context.ReadAttachment(content, info_);
+              context.ReadDicom(content, instanceId_);
             }
             catch (OrthancException& e)
             {
@@ -577,11 +575,11 @@
 
     void AddWriteInstance(const std::string& filename,
                           const std::string& instanceId,
-                          const FileInfo& info)
+                          uint64_t uncompressedSize)
     {
-      commands_.push_back(new Command(Type_WriteInstance, filename, instanceId, info));
+      commands_.push_back(new Command(Type_WriteInstance, filename, instanceId));
       instancesCount_ ++;
-      uncompressedSize_ += info.GetUncompressedSize();
+      uncompressedSize_ += uncompressedSize;
     }
 
     bool IsZip64() const
@@ -695,13 +693,13 @@
     }
 
     virtual void AddInstance(const std::string& instanceId,
-                             const FileInfo& dicom) ORTHANC_OVERRIDE
+                             uint64_t uncompressedSize) ORTHANC_OVERRIDE
     {
       char filename[24];
       snprintf(filename, sizeof(filename) - 1, instanceFormat_, counter_);
       counter_ ++;
 
-      commands_.AddWriteInstance(filename, instanceId, dicom);
+      commands_.AddWriteInstance(filename, instanceId, uncompressedSize);
     }
   };
 
@@ -732,13 +730,13 @@
     }
 
     virtual void AddInstance(const std::string& instanceId,
-                             const FileInfo& dicom) ORTHANC_OVERRIDE
+                             uint64_t uncompressedSize) ORTHANC_OVERRIDE
     {
       // "DICOM restricts the filenames on DICOM media to 8
       // characters (some systems wrongly use 8.3, but this does not
       // conform to the standard)."
       std::string filename = "IM" + boost::lexical_cast<std::string>(counter_);
-      commands_.AddWriteInstance(filename, instanceId, dicom);
+      commands_.AddWriteInstance(filename, instanceId, uncompressedSize);
 
       counter_ ++;
     }