Mercurial > hg > orthanc
annotate Core/JobsEngine/Operations/SequenceOfOperationsJob.cpp @ 3813:aaaa442bfe39 transcoding
moving SetOverwriteInstances from ServerIndex to ServerContext
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Apr 2020 14:03:33 +0200 |
parents | 56f2397f027a |
children | d729d6e8b484 |
rev | line source |
---|---|
2603 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
2603 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #include "../../PrecompiledHeaders.h" | |
35 #include "SequenceOfOperationsJob.h" | |
36 | |
37 #include "../../Logging.h" | |
38 #include "../../OrthancException.h" | |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
39 #include "../../SerializationToolbox.h" |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
40 #include "../IJobUnserializer.h" |
2603 | 41 |
42 namespace Orthanc | |
43 { | |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
44 static const char* CURRENT = "Current"; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
45 static const char* DESCRIPTION = "Description"; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
46 static const char* DICOM_TIMEOUT = "DicomTimeout"; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
47 static const char* NEXT_OPERATIONS = "Next"; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
48 static const char* OPERATION = "Operation"; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
49 static const char* OPERATIONS = "Operations"; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
50 static const char* ORIGINAL_INPUTS = "OriginalInputs"; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
51 static const char* TRAILING_TIMEOUT = "TrailingTimeout"; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
52 static const char* TYPE = "Type"; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
53 static const char* WORK_INPUTS = "WorkInputs"; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
54 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
55 |
2603 | 56 class SequenceOfOperationsJob::Operation : public boost::noncopyable |
57 { | |
58 private: | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
59 size_t index_; |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
60 std::unique_ptr<IJobOperation> operation_; |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
61 std::unique_ptr<JobOperationValues> originalInputs_; |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
62 std::unique_ptr<JobOperationValues> workInputs_; |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
63 std::list<Operation*> nextOperations_; |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
64 size_t currentInput_; |
2603 | 65 |
66 public: | |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
67 Operation(size_t index, |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
68 IJobOperation* operation) : |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
69 index_(index), |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
70 operation_(operation), |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
71 originalInputs_(new JobOperationValues), |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
72 workInputs_(new JobOperationValues), |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
73 currentInput_(0) |
2603 | 74 { |
75 if (operation == NULL) | |
76 { | |
77 throw OrthancException(ErrorCode_NullPointer); | |
78 } | |
79 } | |
80 | |
81 void AddOriginalInput(const JobOperationValue& value) | |
82 { | |
83 if (currentInput_ != 0) | |
84 { | |
85 // Cannot add input after processing has started | |
86 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
87 } | |
88 else | |
89 { | |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
90 originalInputs_->Append(value.Clone()); |
2603 | 91 } |
92 } | |
93 | |
94 const JobOperationValues& GetOriginalInputs() const | |
95 { | |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
96 return *originalInputs_; |
2603 | 97 } |
98 | |
99 void Reset() | |
100 { | |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
101 workInputs_->Clear(); |
2603 | 102 currentInput_ = 0; |
103 } | |
104 | |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
105 void AddNextOperation(Operation& other, |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
106 bool unserializing) |
2603 | 107 { |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
108 if (other.index_ <= index_) |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
109 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
110 throw OrthancException(ErrorCode_InternalError); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
111 } |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
112 |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
113 if (!unserializing && |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
114 currentInput_ != 0) |
2603 | 115 { |
116 // Cannot add input after processing has started | |
117 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
118 } | |
119 else | |
120 { | |
121 nextOperations_.push_back(&other); | |
122 } | |
123 } | |
124 | |
125 bool IsDone() const | |
126 { | |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
127 return currentInput_ >= originalInputs_->GetSize() + workInputs_->GetSize(); |
2603 | 128 } |
129 | |
2608
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
130 void Step(IDicomConnectionManager& connectionManager) |
2603 | 131 { |
132 if (IsDone()) | |
133 { | |
134 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
135 } | |
136 | |
137 const JobOperationValue* input; | |
138 | |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
139 if (currentInput_ < originalInputs_->GetSize()) |
2603 | 140 { |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
141 input = &originalInputs_->GetValue(currentInput_); |
2603 | 142 } |
143 else | |
144 { | |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
145 input = &workInputs_->GetValue(currentInput_ - originalInputs_->GetSize()); |
2603 | 146 } |
147 | |
148 JobOperationValues outputs; | |
2608
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
149 operation_->Apply(outputs, *input, connectionManager); |
2603 | 150 |
151 if (!nextOperations_.empty()) | |
152 { | |
153 std::list<Operation*>::iterator first = nextOperations_.begin(); | |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
154 outputs.Move(*(*first)->workInputs_); |
2603 | 155 |
156 std::list<Operation*>::iterator current = first; | |
157 ++current; | |
158 | |
159 while (current != nextOperations_.end()) | |
160 { | |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
161 (*first)->workInputs_->Copy(*(*current)->workInputs_); |
2603 | 162 ++current; |
163 } | |
164 } | |
165 | |
166 currentInput_ += 1; | |
167 } | |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
168 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
169 void Serialize(Json::Value& target) const |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
170 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
171 target = Json::objectValue; |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
172 target[CURRENT] = static_cast<unsigned int>(currentInput_); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
173 operation_->Serialize(target[OPERATION]); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
174 originalInputs_->Serialize(target[ORIGINAL_INPUTS]); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
175 workInputs_->Serialize(target[WORK_INPUTS]); |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
176 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
177 Json::Value tmp = Json::arrayValue; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
178 for (std::list<Operation*>::const_iterator it = nextOperations_.begin(); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
179 it != nextOperations_.end(); ++it) |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
180 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
181 tmp.append(static_cast<int>((*it)->index_)); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
182 } |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
183 |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
184 target[NEXT_OPERATIONS] = tmp; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
185 } |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
186 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
187 Operation(IJobUnserializer& unserializer, |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
188 Json::Value::ArrayIndex index, |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
189 const Json::Value& serialized) : |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
190 index_(index) |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
191 { |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
192 if (serialized.type() != Json::objectValue || |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
193 !serialized.isMember(OPERATION) || |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
194 !serialized.isMember(ORIGINAL_INPUTS) || |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
195 !serialized.isMember(WORK_INPUTS)) |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
196 { |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
197 throw OrthancException(ErrorCode_BadFileFormat); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
198 } |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
199 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
200 currentInput_ = SerializationToolbox::ReadUnsignedInteger(serialized, CURRENT); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
201 operation_.reset(unserializer.UnserializeOperation(serialized[OPERATION])); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
202 originalInputs_.reset(JobOperationValues::Unserialize |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
203 (unserializer, serialized[ORIGINAL_INPUTS])); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
204 workInputs_.reset(JobOperationValues::Unserialize |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
205 (unserializer, serialized[WORK_INPUTS])); |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
206 } |
2603 | 207 }; |
208 | |
209 | |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
210 SequenceOfOperationsJob::SequenceOfOperationsJob() : |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
211 done_(false), |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
212 current_(0), |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
213 trailingTimeout_(boost::posix_time::milliseconds(1000)) |
2603 | 214 { |
215 } | |
216 | |
217 | |
218 SequenceOfOperationsJob::~SequenceOfOperationsJob() | |
219 { | |
220 for (size_t i = 0; i < operations_.size(); i++) | |
221 { | |
222 if (operations_[i] != NULL) | |
223 { | |
224 delete operations_[i]; | |
225 } | |
226 } | |
227 } | |
228 | |
229 | |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
230 void SequenceOfOperationsJob::SetDescription(const std::string& description) |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
231 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
232 boost::mutex::scoped_lock lock(mutex_); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
233 description_ = description; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
234 } |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
235 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
236 |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
237 void SequenceOfOperationsJob::GetDescription(std::string& description) |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
238 { |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
239 boost::mutex::scoped_lock lock(mutex_); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
240 description = description_; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
241 } |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
242 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
243 |
2603 | 244 void SequenceOfOperationsJob::Register(IObserver& observer) |
245 { | |
246 boost::mutex::scoped_lock lock(mutex_); | |
247 observers_.push_back(&observer); | |
248 } | |
249 | |
250 | |
251 void SequenceOfOperationsJob::Lock::SetTrailingOperationTimeout(unsigned int timeout) | |
252 { | |
253 that_.trailingTimeout_ = boost::posix_time::milliseconds(timeout); | |
254 } | |
255 | |
2608
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
256 |
2620
1232922c8793
speeding up shutdown if Lua script is in trailing phase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2616
diff
changeset
|
257 void SequenceOfOperationsJob::Lock::SetDicomAssociationTimeout(unsigned int timeout) |
2608
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
258 { |
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
259 that_.connectionManager_.SetTimeout(timeout); |
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
260 } |
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
261 |
2603 | 262 |
263 size_t SequenceOfOperationsJob::Lock::AddOperation(IJobOperation* operation) | |
264 { | |
265 if (IsDone()) | |
266 { | |
267 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
268 } | |
269 | |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
270 size_t index = that_.operations_.size(); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
271 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
272 that_.operations_.push_back(new Operation(index, operation)); |
2603 | 273 that_.operationAdded_.notify_one(); |
274 | |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
275 return index; |
2603 | 276 } |
277 | |
278 | |
279 void SequenceOfOperationsJob::Lock::AddInput(size_t index, | |
280 const JobOperationValue& value) | |
281 { | |
282 if (IsDone()) | |
283 { | |
284 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
285 } | |
286 else if (index >= that_.operations_.size() || | |
287 index < that_.current_) | |
288 { | |
289 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
290 } | |
291 else | |
292 { | |
293 that_.operations_[index]->AddOriginalInput(value); | |
294 } | |
295 } | |
296 | |
297 | |
298 void SequenceOfOperationsJob::Lock::Connect(size_t input, | |
299 size_t output) | |
300 { | |
301 if (IsDone()) | |
302 { | |
303 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
304 } | |
305 else if (input >= output || | |
306 input >= that_.operations_.size() || | |
307 output >= that_.operations_.size() || | |
308 input < that_.current_ || | |
309 output < that_.current_) | |
310 { | |
311 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
312 } | |
313 else | |
314 { | |
315 Operation& a = *that_.operations_[input]; | |
316 Operation& b = *that_.operations_[output]; | |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
317 a.AddNextOperation(b, false /* not unserializing */); |
2603 | 318 } |
319 } | |
320 | |
321 | |
3658
2d90dd30858c
providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
322 JobStepResult SequenceOfOperationsJob::Step(const std::string& jobId) |
2603 | 323 { |
324 boost::mutex::scoped_lock lock(mutex_); | |
325 | |
326 if (current_ == operations_.size()) | |
327 { | |
328 LOG(INFO) << "Executing the trailing timeout in the sequence of operations"; | |
329 operationAdded_.timed_wait(lock, trailingTimeout_); | |
330 | |
331 if (current_ == operations_.size()) | |
332 { | |
333 // No operation was added during the trailing timeout: The | |
334 // job is over | |
335 LOG(INFO) << "The sequence of operations is over"; | |
336 done_ = true; | |
337 | |
338 for (std::list<IObserver*>::iterator it = observers_.begin(); | |
339 it != observers_.end(); ++it) | |
340 { | |
341 (*it)->SignalDone(*this); | |
342 } | |
343 | |
2608
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
344 connectionManager_.Close(); |
2603 | 345 return JobStepResult::Success(); |
346 } | |
347 else | |
348 { | |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
349 LOG(INFO) << "New operation were added to the sequence of operations"; |
2603 | 350 } |
351 } | |
352 | |
353 assert(current_ < operations_.size()); | |
354 | |
355 while (current_ < operations_.size() && | |
356 operations_[current_]->IsDone()) | |
357 { | |
358 current_++; | |
359 } | |
360 | |
361 if (current_ < operations_.size()) | |
362 { | |
2608
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
363 operations_[current_]->Step(connectionManager_); |
2603 | 364 } |
365 | |
2608
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
366 connectionManager_.CheckTimeout(); |
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
367 |
2603 | 368 return JobStepResult::Continue(); |
369 } | |
370 | |
371 | |
2812
ea7aea6f6a95
improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2811
diff
changeset
|
372 void SequenceOfOperationsJob::Reset() |
2603 | 373 { |
374 boost::mutex::scoped_lock lock(mutex_); | |
375 | |
376 current_ = 0; | |
377 done_ = false; | |
378 | |
379 for (size_t i = 0; i < operations_.size(); i++) | |
380 { | |
381 operations_[i]->Reset(); | |
382 } | |
383 } | |
384 | |
385 | |
2812
ea7aea6f6a95
improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2811
diff
changeset
|
386 void SequenceOfOperationsJob::Stop(JobStopReason reason) |
2608
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
387 { |
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
388 boost::mutex::scoped_lock lock(mutex_); |
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
389 connectionManager_.Close(); |
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
390 } |
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
391 |
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
392 |
2603 | 393 float SequenceOfOperationsJob::GetProgress() |
394 { | |
395 boost::mutex::scoped_lock lock(mutex_); | |
396 | |
397 return (static_cast<float>(current_) / | |
398 static_cast<float>(operations_.size() + 1)); | |
399 } | |
400 | |
401 | |
402 void SequenceOfOperationsJob::GetPublicContent(Json::Value& value) | |
403 { | |
404 boost::mutex::scoped_lock lock(mutex_); | |
405 | |
406 value["CountOperations"] = static_cast<unsigned int>(operations_.size()); | |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
407 value["Description"] = description_; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
408 } |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
409 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
410 |
2663
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
411 bool SequenceOfOperationsJob::Serialize(Json::Value& value) |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
412 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
413 boost::mutex::scoped_lock lock(mutex_); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
414 |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
415 value = Json::objectValue; |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
416 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
417 std::string jobType; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
418 GetJobType(jobType); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
419 value[TYPE] = jobType; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
420 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
421 value[DESCRIPTION] = description_; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
422 value[TRAILING_TIMEOUT] = static_cast<unsigned int>(trailingTimeout_.total_milliseconds()); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
423 value[DICOM_TIMEOUT] = connectionManager_.GetTimeout(); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
424 value[CURRENT] = static_cast<unsigned int>(current_); |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
425 |
2621
83ac5a05ce84
primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2620
diff
changeset
|
426 Json::Value tmp = Json::arrayValue; |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
427 for (size_t i = 0; i < operations_.size(); i++) |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
428 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
429 Json::Value operation = Json::objectValue; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
430 operations_[i]->Serialize(operation); |
2621
83ac5a05ce84
primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2620
diff
changeset
|
431 tmp.append(operation); |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
432 } |
2621
83ac5a05ce84
primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2620
diff
changeset
|
433 |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
434 value[OPERATIONS] = tmp; |
2663
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
435 |
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
436 return true; |
2603 | 437 } |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
438 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
439 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
440 SequenceOfOperationsJob::SequenceOfOperationsJob(IJobUnserializer& unserializer, |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
441 const Json::Value& serialized) : |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
442 done_(false) |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
443 { |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
444 std::string jobType; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
445 GetJobType(jobType); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
446 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
447 if (SerializationToolbox::ReadString(serialized, TYPE) != jobType || |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
448 !serialized.isMember(OPERATIONS) || |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
449 serialized[OPERATIONS].type() != Json::arrayValue) |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
450 { |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
451 throw OrthancException(ErrorCode_BadFileFormat); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
452 } |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
453 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
454 description_ = SerializationToolbox::ReadString(serialized, DESCRIPTION); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
455 trailingTimeout_ = boost::posix_time::milliseconds |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
456 (SerializationToolbox::ReadUnsignedInteger(serialized, TRAILING_TIMEOUT)); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
457 connectionManager_.SetTimeout |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
458 (SerializationToolbox::ReadUnsignedInteger(serialized, DICOM_TIMEOUT)); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
459 current_ = SerializationToolbox::ReadUnsignedInteger(serialized, CURRENT); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
460 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
461 const Json::Value& ops = serialized[OPERATIONS]; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
462 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
463 // Unserialize the individual operations |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
464 operations_.reserve(ops.size()); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
465 for (Json::Value::ArrayIndex i = 0; i < ops.size(); i++) |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
466 { |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
467 operations_.push_back(new Operation(unserializer, i, ops[i])); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
468 } |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
469 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
470 // Connect the next operations |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
471 for (Json::Value::ArrayIndex i = 0; i < ops.size(); i++) |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
472 { |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
473 if (!ops[i].isMember(NEXT_OPERATIONS) || |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
474 ops[i][NEXT_OPERATIONS].type() != Json::arrayValue) |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
475 { |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
476 throw OrthancException(ErrorCode_BadFileFormat); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
477 } |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
478 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
479 const Json::Value& next = ops[i][NEXT_OPERATIONS]; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
480 for (Json::Value::ArrayIndex j = 0; j < next.size(); j++) |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
481 { |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
482 if (next[j].type() != Json::intValue || |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
483 next[j].asInt() < 0 || |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
484 next[j].asUInt() >= operations_.size()) |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
485 { |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
486 throw OrthancException(ErrorCode_BadFileFormat); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
487 } |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
488 else |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
489 { |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
490 operations_[i]->AddNextOperation(*operations_[next[j].asUInt()], true); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
491 } |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
492 } |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
493 } |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
494 } |
2603 | 495 } |