changeset 6850:30879dc76b68 streaming

added user data to StorageAreaDataSource
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 22 May 2026 14:29:15 +0200
parents f1066df74009
children 8e4223cc729d
files OrthancFramework/Sources/DataSource/StorageAreaDataSource.cpp OrthancFramework/Sources/DataSource/StorageAreaDataSource.h OrthancServer/Sources/ServerContext.cpp OrthancServer/Sources/ServerContext.h
diffstat 4 files changed, 93 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/DataSource/StorageAreaDataSource.cpp	Fri May 22 14:00:29 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/StorageAreaDataSource.cpp	Fri May 22 14:29:15 2026 +0200
@@ -145,16 +145,27 @@
 
     void SetPostProcessing(IPostProcessing* postProcessing)
     {
+      std::unique_ptr<IPostProcessing> protection(postProcessing);
+
       if (postProcessing == NULL)
       {
         throw OrthancException(ErrorCode_NullPointer);
       }
+      else if (postProcessing_.get() != NULL)
+      {
+        throw OrthancException(ErrorCode_BadSequenceOfCalls);
+      }
       else
       {
-        postProcessing_.reset(postProcessing);
+        postProcessing_.reset(protection.release());
       }
     }
 
+    bool HasPostProcessing() const
+    {
+      return postProcessing_.get() != NULL;
+    }
+
     const IPostProcessing& GetPostProcessing() const
     {
       if (postProcessing_.get() == NULL)
@@ -166,22 +177,6 @@
         return *postProcessing_;
       }
     }
-
-    boost::shared_ptr<IDynamicObject> ApplyPostProcessing(const boost::shared_ptr<IDynamicObject>& value) const
-    {
-      if (value.get() == NULL)
-      {
-        throw OrthancException(ErrorCode_NullPointer);
-      }
-      else if (postProcessing_.get() == NULL)
-      {
-        return value;
-      }
-      else
-      {
-        return postProcessing_->Apply(value);
-      }
-    }
   };
 
 
@@ -316,6 +311,34 @@
   }
 
 
+  void StorageAreaDataSource::Range::SetUserData(IDynamicObject* data)
+  {
+    std::unique_ptr<IDynamicObject> protection(data);
+
+    if (userData_.get() == NULL)
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+    else
+    {
+      userData_.reset(data);
+    }
+  }
+
+
+  const IDynamicObject& StorageAreaDataSource::Range::GetUserData()
+  {
+    if (userData_.get() == NULL)
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+    else
+    {
+      return *userData_;
+    }
+  }
+
+
   const void* StorageAreaDataSource::Range::GetData() const
   {
     return GetValue().GetBuffer().GetData();
@@ -335,12 +358,6 @@
   }
 
 
-  StorageAreaDataSource::Range* StorageAreaDataSource::Range::ApplyPostProcessing(const IDataIdentifier& identifier) const
-  {
-    return new Range(dynamic_cast<const Identifier&>(identifier).ApplyPostProcessing(value_));
-  }
-
-
   StorageAreaDataSource::Range* StorageAreaDataSource::Range::CreateFromSwap(std::string& content)
   {
     boost::shared_ptr<Value> value(new Value(StringMemoryBuffer::CreateFromSwap(content), false));
@@ -371,11 +388,7 @@
                                                   attachment.GetCustomData()));
     id->SetPostProcessing(new AttachmentPostProcessing(attachment, uncompress));
 
-    std::unique_ptr<DataSourceAnswer::Item> item(reader.ReadSingleWithIdentifier(id.release()));
-
-    std::unique_ptr<StorageAreaDataSource::Range> range(new Range(item->GetValue()));
-
-    return range->ApplyPostProcessing(item->GetId());
+    return Execute(reader, id.release());
   }
 
 
@@ -444,6 +457,42 @@
   }
 
 
+  StorageAreaDataSource::Range* StorageAreaDataSource::Execute(DataSourceReader& reader,
+                                                               IDataIdentifier* request /* takes ownership */)
+  {
+    if (request == NULL)
+    {
+      throw OrthancException(ErrorCode_NullPointer);
+    }
+    else
+    {
+      std::unique_ptr<DataSourceAnswer::Item> item(reader.ReadSingleWithIdentifier(request));
+
+      const Identifier& id = dynamic_cast<const Identifier&>(item->GetId());
+
+      std::unique_ptr<Range> range;
+
+      if (id.HasPostProcessing())
+      {
+        range.reset(new Range(id.GetPostProcessing().Apply(item->GetValue())));
+      }
+      else
+      {
+        range.reset(new Range(item->GetValue()));
+      }
+
+      if (item->HasUserData())
+      {
+        range->SetUserData(item->ReleaseUserData());
+      }
+
+      return range.release();
+    }
+  }
+
+
+  // TODO-Streaming : REMOVE
+#if 0
   class StorageAreaDataSource::MultipleReader::PImpl : public boost::noncopyable
   {
   private:
@@ -530,4 +579,5 @@
   {
     return pimpl_->Dequeue();
   }
+#endif
 }
--- a/OrthancFramework/Sources/DataSource/StorageAreaDataSource.h	Fri May 22 14:00:29 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/StorageAreaDataSource.h	Fri May 22 14:29:15 2026 +0200
@@ -69,21 +69,28 @@
     {
     private:
       boost::shared_ptr<IDynamicObject>  value_;
+      std::unique_ptr<IDynamicObject>    userData_;
 
       const Value& GetValue() const;
 
     public:
       explicit Range(const boost::shared_ptr<IDynamicObject>& value);
 
+      void SetUserData(IDynamicObject* data);
+
+      bool HasUserData() const
+      {
+        return userData_.get() != NULL;
+      }
+
+      const IDynamicObject& GetUserData();
+
       const void* GetData() const;
 
       size_t GetSize() const;
 
       void Copy(std::string& to) const;
 
-      // TODO-Streaming : Post-processing is probably an overkill
-      Range* ApplyPostProcessing(const IDataIdentifier& identifier) const;
-
       static Range* CreateFromSwap(std::string& content);
     };
 
@@ -107,8 +114,12 @@
                             const StorageRange& range,
                             bool uncompress);
 
+    static Range* Execute(DataSourceReader& reader,
+                          IDataIdentifier* request /* takes ownership */);
+
 
     // TODO-Streaming: Probably to be removed
+#if 0
     class MultipleReader : public boost::noncopyable
     {
     private:
@@ -151,5 +162,6 @@
 
       Item* Dequeue();
     };
+#endif
   };
 }
--- a/OrthancServer/Sources/ServerContext.cpp	Fri May 22 14:00:29 2026 +0200
+++ b/OrthancServer/Sources/ServerContext.cpp	Fri May 22 14:29:15 2026 +0200
@@ -2139,12 +2139,6 @@
   }
 
 
-  StorageAreaDataSource::MultipleReader* ServerContext::CreateMultipleStorageAreaReader() const
-  {
-    return new StorageAreaDataSource::MultipleReader(storageAreaReader_);
-  }
-
-
   MultipleDicomReader* ServerContext::CreateMultipleDicomReader() const
   {
     return new MultipleDicomReader(dicomReader_);
--- a/OrthancServer/Sources/ServerContext.h	Fri May 22 14:00:29 2026 +0200
+++ b/OrthancServer/Sources/ServerContext.h	Fri May 22 14:29:15 2026 +0200
@@ -591,8 +591,6 @@
 
     Future* SubmitTranscodingRequest(TranscodingCallable* callable);
 
-    StorageAreaDataSource::MultipleReader* CreateMultipleStorageAreaReader() const;
-
     MultipleDicomReader* CreateMultipleDicomReader() const;
   };
 }