comparison OrthancServer/ServerJobs/OrthancPeerStoreJob.cpp @ 3949:ef696db8426f transcoding

preparing transcoding in OrthancPeerStoreJob
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 19 May 2020 18:44:36 +0200
parents 94f4a18a79cc
children 5797ca4f3b8d
comparison
equal deleted inserted replaced
3948:3d2fc1b5cc8c 3949:ef696db8426f
33 33
34 #include "../PrecompiledHeadersServer.h" 34 #include "../PrecompiledHeadersServer.h"
35 #include "OrthancPeerStoreJob.h" 35 #include "OrthancPeerStoreJob.h"
36 36
37 #include "../../Core/Logging.h" 37 #include "../../Core/Logging.h"
38 #include "../../Core/SerializationToolbox.h"
38 #include "../ServerContext.h" 39 #include "../ServerContext.h"
39 40
40 41
41 namespace Orthanc 42 namespace Orthanc
42 { 43 {
88 throw OrthancException(ErrorCode_BadSequenceOfCalls); 89 throw OrthancException(ErrorCode_BadSequenceOfCalls);
89 } 90 }
90 else 91 else
91 { 92 {
92 peer_ = peer; 93 peer_ = peer;
94 }
95 }
96
97
98 DicomTransferSyntax OrthancPeerStoreJob::GetTransferSyntax() const
99 {
100 if (transcode_)
101 {
102 return transferSyntax_;
103 }
104 else
105 {
106 throw OrthancException(ErrorCode_BadSequenceOfCalls);
107 }
108 }
109
110
111 void OrthancPeerStoreJob::SetTranscode(DicomTransferSyntax syntax)
112 {
113 if (IsStarted())
114 {
115 throw OrthancException(ErrorCode_BadSequenceOfCalls);
116 }
117 else
118 {
119 transcode_ = true;
120 transferSyntax_ = syntax;
121 }
122 }
123
124
125 void OrthancPeerStoreJob::SetTranscode(const std::string& transferSyntaxUid)
126 {
127 DicomTransferSyntax s;
128 if (LookupTransferSyntax(s, transferSyntaxUid))
129 {
130 SetTranscode(s);
131 }
132 else
133 {
134 throw OrthancException(ErrorCode_BadFileFormat,
135 "Unknown transfer syntax UID: " + transferSyntaxUid);
136 }
137 }
138
139
140 void OrthancPeerStoreJob::ClearTranscode()
141 {
142 if (IsStarted())
143 {
144 throw OrthancException(ErrorCode_BadSequenceOfCalls);
145 }
146 else
147 {
148 transcode_ = false;
93 } 149 }
94 } 150 }
95 151
96 152
97 void OrthancPeerStoreJob::Stop(JobStopReason reason) // For pausing jobs 153 void OrthancPeerStoreJob::Stop(JobStopReason reason) // For pausing jobs
107 Json::Value v; 163 Json::Value v;
108 peer_.Serialize(v, 164 peer_.Serialize(v,
109 false /* allow simple format if possible */, 165 false /* allow simple format if possible */,
110 false /* don't include passwords */); 166 false /* don't include passwords */);
111 value["Peer"] = v; 167 value["Peer"] = v;
168
169 if (transcode_)
170 {
171 value["Transcode"] = GetTransferSyntaxUid(transferSyntax_);
172 }
112 } 173 }
113 174
114 175
115 static const char* PEER = "Peer"; 176 static const char* PEER = "Peer";
177 static const char* TRANSCODE = "Transcode";
116 178
117 OrthancPeerStoreJob::OrthancPeerStoreJob(ServerContext& context, 179 OrthancPeerStoreJob::OrthancPeerStoreJob(ServerContext& context,
118 const Json::Value& serialized) : 180 const Json::Value& serialized) :
119 SetOfInstancesJob(serialized), 181 SetOfInstancesJob(serialized),
120 context_(context) 182 context_(context)
121 { 183 {
184 assert(serialized.type() == Json::objectValue);
122 peer_ = WebServiceParameters(serialized[PEER]); 185 peer_ = WebServiceParameters(serialized[PEER]);
186
187 if (serialized.isMember(TRANSCODE))
188 {
189 SetTranscode(SerializationToolbox::ReadString(serialized, TRANSCODE));
190 }
191 else
192 {
193 transcode_ = false;
194 }
123 } 195 }
124 196
125 197
126 bool OrthancPeerStoreJob::Serialize(Json::Value& target) 198 bool OrthancPeerStoreJob::Serialize(Json::Value& target)
127 { 199 {
129 { 201 {
130 return false; 202 return false;
131 } 203 }
132 else 204 else
133 { 205 {
206 assert(target.type() == Json::objectValue);
134 peer_.Serialize(target[PEER], 207 peer_.Serialize(target[PEER],
135 true /* force advanced format */, 208 true /* force advanced format */,
136 true /* include passwords */); 209 true /* include passwords */);
210
211 if (transcode_)
212 {
213 target[TRANSCODE] = GetTransferSyntaxUid(transferSyntax_);
214 }
215
137 return true; 216 return true;
138 } 217 }
139 } 218 }
140 } 219 }