annotate Core/JobsEngine/Operations/SequenceOfOperationsJob.cpp @ 2608:25225f0b4f33 jobs

simplification wrt. dicom connection manager
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 19 May 2018 15:50:09 +0200
parents 988936118354
children 2f3007bf0708
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "../../PrecompiledHeaders.h"
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "SequenceOfOperationsJob.h"
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "../../Logging.h"
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include "../../OrthancException.h"
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 namespace Orthanc
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 class SequenceOfOperationsJob::Operation : public boost::noncopyable
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 private:
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 JobOperationValues originalInputs_;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 JobOperationValues workInputs_;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 std::auto_ptr<IJobOperation> operation_;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 std::list<Operation*> nextOperations_;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 size_t currentInput_;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 public:
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 Operation(IJobOperation* operation) :
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 operation_(operation),
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 currentInput_(0)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 if (operation == NULL)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 throw OrthancException(ErrorCode_NullPointer);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 void AddOriginalInput(const JobOperationValue& value)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 if (currentInput_ != 0)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 // Cannot add input after processing has started
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 throw OrthancException(ErrorCode_BadSequenceOfCalls);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 else
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 originalInputs_.Append(value.Clone());
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 const JobOperationValues& GetOriginalInputs() const
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 return originalInputs_;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 void Reset()
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 workInputs_.Clear();
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 currentInput_ = 0;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 void AddNextOperation(Operation& other)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 if (currentInput_ != 0)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 // Cannot add input after processing has started
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 throw OrthancException(ErrorCode_BadSequenceOfCalls);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 else
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 nextOperations_.push_back(&other);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 bool IsDone() const
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 return currentInput_ >= originalInputs_.GetSize() + workInputs_.GetSize();
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
2608
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
104 void Step(IDicomConnectionManager& connectionManager)
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 if (IsDone())
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 throw OrthancException(ErrorCode_BadSequenceOfCalls);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 const JobOperationValue* input;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 if (currentInput_ < originalInputs_.GetSize())
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 input = &originalInputs_.GetValue(currentInput_);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 else
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 input = &workInputs_.GetValue(currentInput_ - originalInputs_.GetSize());
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 JobOperationValues outputs;
2608
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
123 operation_->Apply(outputs, *input, connectionManager);
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 if (!nextOperations_.empty())
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 std::list<Operation*>::iterator first = nextOperations_.begin();
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 outputs.Move((*first)->workInputs_);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 std::list<Operation*>::iterator current = first;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 ++current;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 while (current != nextOperations_.end())
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 (*first)->workInputs_.Copy((*current)->workInputs_);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 ++current;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 currentInput_ += 1;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 };
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 // Invoked from constructors
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 void SequenceOfOperationsJob::Setup()
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 done_ = false;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 current_ = 0;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 trailingTimeout_ = boost::posix_time::milliseconds(1000);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 SequenceOfOperationsJob::~SequenceOfOperationsJob()
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 for (size_t i = 0; i < operations_.size(); i++)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 if (operations_[i] != NULL)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 delete operations_[i];
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 void SequenceOfOperationsJob::Register(IObserver& observer)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 boost::mutex::scoped_lock lock(mutex_);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 observers_.push_back(&observer);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 void SequenceOfOperationsJob::Lock::SetTrailingOperationTimeout(unsigned int timeout)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 that_.trailingTimeout_ = boost::posix_time::milliseconds(timeout);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177
2608
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
178
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
179 void SequenceOfOperationsJob::Lock::SetDicomConnectionTimeout(unsigned int timeout)
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
180 {
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
181 that_.connectionManager_.SetTimeout(timeout);
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
182 }
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
183
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 size_t SequenceOfOperationsJob::Lock::AddOperation(IJobOperation* operation)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 if (IsDone())
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 throw OrthancException(ErrorCode_BadSequenceOfCalls);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 that_.operations_.push_back(new Operation(operation));
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 that_.operationAdded_.notify_one();
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 return that_.operations_.size() - 1;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 void SequenceOfOperationsJob::Lock::AddInput(size_t index,
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 const JobOperationValue& value)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 if (IsDone())
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 throw OrthancException(ErrorCode_BadSequenceOfCalls);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 else if (index >= that_.operations_.size() ||
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 index < that_.current_)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 throw OrthancException(ErrorCode_ParameterOutOfRange);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 else
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 that_.operations_[index]->AddOriginalInput(value);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 void SequenceOfOperationsJob::Lock::Connect(size_t input,
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 size_t output)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 if (IsDone())
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 throw OrthancException(ErrorCode_BadSequenceOfCalls);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 else if (input >= output ||
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 input >= that_.operations_.size() ||
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 output >= that_.operations_.size() ||
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 input < that_.current_ ||
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 output < that_.current_)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 throw OrthancException(ErrorCode_ParameterOutOfRange);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 else
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 Operation& a = *that_.operations_[input];
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 Operation& b = *that_.operations_[output];
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 a.AddNextOperation(b);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 JobStepResult SequenceOfOperationsJob::ExecuteStep()
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 boost::mutex::scoped_lock lock(mutex_);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 if (current_ == operations_.size())
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 LOG(INFO) << "Executing the trailing timeout in the sequence of operations";
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 operationAdded_.timed_wait(lock, trailingTimeout_);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 if (current_ == operations_.size())
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 // No operation was added during the trailing timeout: The
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 // job is over
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 LOG(INFO) << "The sequence of operations is over";
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 done_ = true;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 for (std::list<IObserver*>::iterator it = observers_.begin();
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 it != observers_.end(); ++it)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 (*it)->SignalDone(*this);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263
2608
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
264 connectionManager_.Close();
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 return JobStepResult::Success();
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 else
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 LOG(INFO) << "New operation added to the sequence of operations";
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 assert(current_ < operations_.size());
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 while (current_ < operations_.size() &&
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 operations_[current_]->IsDone())
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 current_++;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 if (current_ < operations_.size())
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 {
2608
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
283 operations_[current_]->Step(connectionManager_);
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285
2608
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
286 connectionManager_.CheckTimeout();
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
287
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 return JobStepResult::Continue();
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 void SequenceOfOperationsJob::SignalResubmit()
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 boost::mutex::scoped_lock lock(mutex_);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 current_ = 0;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 done_ = false;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 for (size_t i = 0; i < operations_.size(); i++)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 operations_[i]->Reset();
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305
2608
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
306 void SequenceOfOperationsJob::ReleaseResources()
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
307 {
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
308 boost::mutex::scoped_lock lock(mutex_);
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
309 connectionManager_.Close();
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
310 }
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
311
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
312
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 float SequenceOfOperationsJob::GetProgress()
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 boost::mutex::scoped_lock lock(mutex_);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 return (static_cast<float>(current_) /
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 static_cast<float>(operations_.size() + 1));
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 void SequenceOfOperationsJob::GetPublicContent(Json::Value& value)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 boost::mutex::scoped_lock lock(mutex_);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 value["CountOperations"] = static_cast<unsigned int>(operations_.size());
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 }