# HG changeset patch # User Sebastien Jodogne # Date 1589906676 -7200 # Node ID ef696db8426f9228a6f60a9c7dd6620ac46bb782 # Parent 3d2fc1b5cc8c91d7ebc6228df7284e9c09ed5c43 preparing transcoding in OrthancPeerStoreJob diff -r 3d2fc1b5cc8c -r ef696db8426f OrthancServer/ServerJobs/OrthancPeerStoreJob.cpp --- a/OrthancServer/ServerJobs/OrthancPeerStoreJob.cpp Tue May 19 17:23:30 2020 +0200 +++ b/OrthancServer/ServerJobs/OrthancPeerStoreJob.cpp Tue May 19 18:44:36 2020 +0200 @@ -35,6 +35,7 @@ #include "OrthancPeerStoreJob.h" #include "../../Core/Logging.h" +#include "../../Core/SerializationToolbox.h" #include "../ServerContext.h" @@ -94,6 +95,61 @@ } + DicomTransferSyntax OrthancPeerStoreJob::GetTransferSyntax() const + { + if (transcode_) + { + return transferSyntax_; + } + else + { + throw OrthancException(ErrorCode_BadSequenceOfCalls); + } + } + + + void OrthancPeerStoreJob::SetTranscode(DicomTransferSyntax syntax) + { + if (IsStarted()) + { + throw OrthancException(ErrorCode_BadSequenceOfCalls); + } + else + { + transcode_ = true; + transferSyntax_ = syntax; + } + } + + + void OrthancPeerStoreJob::SetTranscode(const std::string& transferSyntaxUid) + { + DicomTransferSyntax s; + if (LookupTransferSyntax(s, transferSyntaxUid)) + { + SetTranscode(s); + } + else + { + throw OrthancException(ErrorCode_BadFileFormat, + "Unknown transfer syntax UID: " + transferSyntaxUid); + } + } + + + void OrthancPeerStoreJob::ClearTranscode() + { + if (IsStarted()) + { + throw OrthancException(ErrorCode_BadSequenceOfCalls); + } + else + { + transcode_ = false; + } + } + + void OrthancPeerStoreJob::Stop(JobStopReason reason) // For pausing jobs { client_.reset(NULL); @@ -109,17 +165,33 @@ false /* allow simple format if possible */, false /* don't include passwords */); value["Peer"] = v; + + if (transcode_) + { + value["Transcode"] = GetTransferSyntaxUid(transferSyntax_); + } } static const char* PEER = "Peer"; + static const char* TRANSCODE = "Transcode"; OrthancPeerStoreJob::OrthancPeerStoreJob(ServerContext& context, const Json::Value& serialized) : SetOfInstancesJob(serialized), context_(context) { + assert(serialized.type() == Json::objectValue); peer_ = WebServiceParameters(serialized[PEER]); + + if (serialized.isMember(TRANSCODE)) + { + SetTranscode(SerializationToolbox::ReadString(serialized, TRANSCODE)); + } + else + { + transcode_ = false; + } } @@ -131,9 +203,16 @@ } else { + assert(target.type() == Json::objectValue); peer_.Serialize(target[PEER], true /* force advanced format */, true /* include passwords */); + + if (transcode_) + { + target[TRANSCODE] = GetTransferSyntaxUid(transferSyntax_); + } + return true; } } diff -r 3d2fc1b5cc8c -r ef696db8426f OrthancServer/ServerJobs/OrthancPeerStoreJob.h --- a/OrthancServer/ServerJobs/OrthancPeerStoreJob.h Tue May 19 17:23:30 2020 +0200 +++ b/OrthancServer/ServerJobs/OrthancPeerStoreJob.h Tue May 19 18:44:36 2020 +0200 @@ -48,6 +48,8 @@ ServerContext& context_; WebServiceParameters peer_; std::unique_ptr client_; + bool transcode_; + DicomTransferSyntax transferSyntax_; protected: virtual bool HandleInstance(const std::string& instance); @@ -56,7 +58,8 @@ public: OrthancPeerStoreJob(ServerContext& context) : - context_(context) + context_(context), + transcode_(false) { } @@ -70,6 +73,19 @@ return peer_; } + bool IsTranscode() const + { + return transcode_; + } + + DicomTransferSyntax GetTransferSyntax() const; + + void SetTranscode(DicomTransferSyntax syntax); + + void SetTranscode(const std::string& transferSyntaxUid); + + void ClearTranscode(); + virtual void Stop(JobStopReason reason); // For pausing jobs virtual void GetJobType(std::string& target) diff -r 3d2fc1b5cc8c -r ef696db8426f UnitTestsSources/FromDcmtkTests.cpp --- a/UnitTestsSources/FromDcmtkTests.cpp Tue May 19 17:23:30 2020 +0200 +++ b/UnitTestsSources/FromDcmtkTests.cpp Tue May 19 18:44:36 2020 +0200 @@ -513,7 +513,8 @@ f.ReplacePlainString(DICOM_TAG_SOP_CLASS_UID, "Tata"); // (**) std::string s; - ASSERT_FALSE(f.LookupTransferSyntax(s)); + ASSERT_TRUE(f.LookupTransferSyntax(s)); + ASSERT_EQ(s, GetTransferSyntaxUid(DicomTransferSyntax_LittleEndianExplicit)); ASSERT_THROW(f.Replace(DICOM_TAG_ACCESSION_NUMBER, std::string("Accession"), false, DicomReplaceMode_ThrowIfAbsent, ""), OrthancException); diff -r 3d2fc1b5cc8c -r ef696db8426f UnitTestsSources/MultiThreadingTests.cpp --- a/UnitTestsSources/MultiThreadingTests.cpp Tue May 19 17:23:30 2020 +0200 +++ b/UnitTestsSources/MultiThreadingTests.cpp Tue May 19 18:44:36 2020 +0200 @@ -1549,6 +1549,30 @@ ASSERT_EQ("username", tmp.GetPeer().GetUsername()); ASSERT_EQ("password", tmp.GetPeer().GetPassword()); ASSERT_TRUE(tmp.GetPeer().IsPkcs11Enabled()); + ASSERT_FALSE(tmp.IsTranscode()); + ASSERT_THROW(tmp.GetTransferSyntax(), OrthancException); + } + + { + OrthancPeerStoreJob job(GetContext()); + ASSERT_THROW(job.SetTranscode("nope"), OrthancException); + job.SetTranscode("1.2.840.10008.1.2.4.50"); + + ASSERT_TRUE(CheckIdempotentSetOfInstances(unserializer, job)); + ASSERT_TRUE(job.Serialize(s)); + } + + { + std::unique_ptr job; + job.reset(unserializer.UnserializeJob(s)); + + OrthancPeerStoreJob& tmp = dynamic_cast(*job); + ASSERT_EQ("http://127.0.0.1:8042/", tmp.GetPeer().GetUrl()); + ASSERT_EQ("", tmp.GetPeer().GetUsername()); + ASSERT_EQ("", tmp.GetPeer().GetPassword()); + ASSERT_FALSE(tmp.GetPeer().IsPkcs11Enabled()); + ASSERT_TRUE(tmp.IsTranscode()); + ASSERT_EQ(DicomTransferSyntax_JPEGProcess1, tmp.GetTransferSyntax()); } // ResourceModificationJob @@ -1580,6 +1604,7 @@ { ResourceModificationJob job(GetContext()); + ASSERT_THROW(job.SetTranscode("nope"), OrthancException); job.SetTranscode(DicomTransferSyntax_JPEGProcess1); job.AddTrailingStep(); // Necessary since 1.7.0