Mercurial > hg > orthanc
comparison OrthancServer/ServerJobs/StorageCommitmentScpJob.cpp @ 3659:08eb0f93c491 storage-commitment
setup step in StorageCommitmentScpJob
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 10 Feb 2020 16:56:28 +0100 |
parents | 2d90dd30858c |
children | f159b731c47d |
comparison
equal
deleted
inserted
replaced
3658:2d90dd30858c | 3659:08eb0f93c491 |
---|---|
44 | 44 |
45 static const char* ANSWER = "Answer"; | 45 static const char* ANSWER = "Answer"; |
46 static const char* CALLED_AET = "CalledAet"; | 46 static const char* CALLED_AET = "CalledAet"; |
47 static const char* LOOKUP = "Lookup"; | 47 static const char* LOOKUP = "Lookup"; |
48 static const char* REMOTE_MODALITY = "RemoteModality"; | 48 static const char* REMOTE_MODALITY = "RemoteModality"; |
49 static const char* SETUP = "Setup"; | |
49 static const char* SOP_CLASS_UID = "SopClassUid"; | 50 static const char* SOP_CLASS_UID = "SopClassUid"; |
50 static const char* SOP_INSTANCE_UID = "SopInstanceUid"; | 51 static const char* SOP_INSTANCE_UID = "SopInstanceUid"; |
51 static const char* TRANSACTION_UID = "TransactionUid"; | 52 static const char* TRANSACTION_UID = "TransactionUid"; |
52 static const char* TYPE = "Type"; | 53 static const char* TYPE = "Type"; |
53 | 54 |
56 namespace Orthanc | 57 namespace Orthanc |
57 { | 58 { |
58 class StorageCommitmentScpJob::StorageCommitmentCommand : public SetOfCommandsJob::ICommand | 59 class StorageCommitmentScpJob::StorageCommitmentCommand : public SetOfCommandsJob::ICommand |
59 { | 60 { |
60 public: | 61 public: |
61 virtual bool IsAnswer() const = 0; | 62 virtual CommandType GetType() const = 0; |
62 }; | 63 }; |
63 | 64 |
64 | 65 |
66 class StorageCommitmentScpJob::SetupCommand : public StorageCommitmentCommand | |
67 { | |
68 private: | |
69 ServerContext& context_; | |
70 | |
71 public: | |
72 SetupCommand(ServerContext& context) : | |
73 context_(context) | |
74 { | |
75 } | |
76 | |
77 virtual CommandType GetType() const | |
78 { | |
79 return CommandType_Setup; | |
80 } | |
81 | |
82 virtual bool Execute(const std::string& jobId) ORTHANC_OVERRIDE | |
83 { | |
84 return true; | |
85 } | |
86 | |
87 virtual void Serialize(Json::Value& target) const | |
88 { | |
89 target = Json::objectValue; | |
90 target[TYPE] = SETUP; | |
91 } | |
92 }; | |
93 | |
94 | |
65 class StorageCommitmentScpJob::LookupCommand : public StorageCommitmentCommand | 95 class StorageCommitmentScpJob::LookupCommand : public StorageCommitmentCommand |
66 { | 96 { |
67 private: | 97 private: |
68 ServerContext& context_; | 98 ServerContext& context_; |
69 bool hasFailureReason_; | 99 bool hasFailureReason_; |
80 sopClassUid_(sopClassUid), | 110 sopClassUid_(sopClassUid), |
81 sopInstanceUid_(sopInstanceUid) | 111 sopInstanceUid_(sopInstanceUid) |
82 { | 112 { |
83 } | 113 } |
84 | 114 |
85 virtual bool IsAnswer() const | 115 virtual CommandType GetType() const |
86 { | 116 { |
87 return false; | 117 return CommandType_Lookup; |
88 } | 118 } |
89 | 119 |
90 virtual bool Execute(const std::string& jobId) ORTHANC_OVERRIDE | 120 virtual bool Execute(const std::string& jobId) ORTHANC_OVERRIDE |
91 { | 121 { |
92 if (hasFailureReason_) | 122 if (hasFailureReason_) |
182 { | 212 { |
183 that_.ready_ = true; | 213 that_.ready_ = true; |
184 } | 214 } |
185 } | 215 } |
186 | 216 |
187 virtual bool IsAnswer() const | 217 virtual CommandType GetType() const |
188 { | 218 { |
189 return true; | 219 return CommandType_Answer; |
190 } | 220 } |
191 | 221 |
192 virtual bool Execute(const std::string& jobId) ORTHANC_OVERRIDE | 222 virtual bool Execute(const std::string& jobId) ORTHANC_OVERRIDE |
193 { | 223 { |
194 that_.Answer(); | 224 that_.Answer(); |
220 | 250 |
221 virtual ICommand* Unserialize(const Json::Value& source) const | 251 virtual ICommand* Unserialize(const Json::Value& source) const |
222 { | 252 { |
223 const std::string type = SerializationToolbox::ReadString(source, TYPE); | 253 const std::string type = SerializationToolbox::ReadString(source, TYPE); |
224 | 254 |
225 if (type == LOOKUP) | 255 if (type == SETUP) |
256 { | |
257 return new SetupCommand(context_); | |
258 } | |
259 else if (type == LOOKUP) | |
226 { | 260 { |
227 return new LookupCommand(context_, | 261 return new LookupCommand(context_, |
228 SerializationToolbox::ReadString(source, SOP_CLASS_UID), | 262 SerializationToolbox::ReadString(source, SOP_CLASS_UID), |
229 SerializationToolbox::ReadString(source, SOP_INSTANCE_UID)); | 263 SerializationToolbox::ReadString(source, SOP_INSTANCE_UID)); |
230 } | 264 } |
244 { | 278 { |
245 LOG(INFO) << " Storage commitment SCP job: Sending answer"; | 279 LOG(INFO) << " Storage commitment SCP job: Sending answer"; |
246 | 280 |
247 const size_t n = GetCommandsCount(); | 281 const size_t n = GetCommandsCount(); |
248 | 282 |
249 if (n == 0) | 283 if (n <= 1) |
250 { | 284 { |
251 throw OrthancException(ErrorCode_InternalError); | 285 throw OrthancException(ErrorCode_InternalError); |
252 } | 286 } |
253 | 287 |
254 std::vector<std::string> sopClassUids, sopInstanceUids; | 288 std::vector<std::string> sopClassUids, sopInstanceUids; |
258 sopInstanceUids.reserve(n); | 292 sopInstanceUids.reserve(n); |
259 failureReasons.reserve(n); | 293 failureReasons.reserve(n); |
260 | 294 |
261 for (size_t i = 0; i < n; i++) | 295 for (size_t i = 0; i < n; i++) |
262 { | 296 { |
263 const StorageCommitmentCommand& command = dynamic_cast<const StorageCommitmentCommand&>(GetCommand(i)); | 297 const CommandType type = dynamic_cast<const StorageCommitmentCommand&>(GetCommand(i)).GetType(); |
264 | 298 |
265 if (i == n - 1) | 299 if ((i == 0 && type != CommandType_Setup) || |
266 { | 300 (i >= 1 && i < n - 1 && type != CommandType_Lookup) || |
267 if (!command.IsAnswer()) | 301 (i == n - 1 && type != CommandType_Answer)) |
268 { | 302 { |
269 throw OrthancException(ErrorCode_InternalError); | 303 throw OrthancException(ErrorCode_InternalError); |
270 } | 304 } |
271 } | 305 |
272 else | 306 if (type == CommandType_Lookup) |
273 { | 307 { |
274 if (command.IsAnswer()) | 308 const LookupCommand& lookup = dynamic_cast<const LookupCommand&>(GetCommand(i)); |
275 { | |
276 throw OrthancException(ErrorCode_InternalError); | |
277 } | |
278 | |
279 const LookupCommand& lookup = dynamic_cast<const LookupCommand&>(command); | |
280 | |
281 sopClassUids.push_back(lookup.GetSopClassUid()); | 309 sopClassUids.push_back(lookup.GetSopClassUid()); |
282 sopInstanceUids.push_back(lookup.GetSopInstanceUid()); | 310 sopInstanceUids.push_back(lookup.GetSopInstanceUid()); |
283 failureReasons.push_back(lookup.GetFailureReason()); | 311 failureReasons.push_back(lookup.GetFailureReason()); |
284 } | 312 } |
285 } | 313 } |
304 { | 332 { |
305 throw OrthancException(ErrorCode_InexistentItem, | 333 throw OrthancException(ErrorCode_InexistentItem, |
306 "Unknown remote modality for storage commitment SCP: " + remoteAet); | 334 "Unknown remote modality for storage commitment SCP: " + remoteAet); |
307 } | 335 } |
308 } | 336 } |
337 | |
338 AddCommand(new SetupCommand(context)); | |
309 } | 339 } |
310 | 340 |
311 | 341 |
312 void StorageCommitmentScpJob::AddInstance(const std::string& sopClassUid, | 342 void StorageCommitmentScpJob::AddInstance(const std::string& sopClassUid, |
313 const std::string& sopInstanceUid) | 343 const std::string& sopInstanceUid) |