annotate OrthancFramework/Sources/JobsEngine/Operations/SequenceOfOperationsJob.cpp @ 5860:9b654590fbcf find-refactoring tip

re-enable IntegratedFind for SQLite
author Alain Mazy <am@orthanc.team>
date Tue, 05 Nov 2024 15:28:41 +0100
parents f7adfb22e20e
children
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
5640
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5310
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
10 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
11 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
12 * the License, or (at your option) any later version.
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
17 * Lesser General Public License for more details.
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
19 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
20 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
21 * <http://www.gnu.org/licenses/>.
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 **/
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "../../PrecompiledHeaders.h"
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "SequenceOfOperationsJob.h"
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include "../../Logging.h"
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include "../../OrthancException.h"
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
30 #include "../../SerializationToolbox.h"
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
31 #include "../IJobUnserializer.h"
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 namespace Orthanc
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
35 static const char* CURRENT = "Current";
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
36 static const char* DESCRIPTION = "Description";
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
37 static const char* NEXT_OPERATIONS = "Next";
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
38 static const char* OPERATION = "Operation";
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
39 static const char* OPERATIONS = "Operations";
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
40 static const char* ORIGINAL_INPUTS = "OriginalInputs";
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
41 static const char* TRAILING_TIMEOUT = "TrailingTimeout";
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
42 static const char* TYPE = "Type";
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
43 static const char* WORK_INPUTS = "WorkInputs";
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
44
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
45
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 class SequenceOfOperationsJob::Operation : public boost::noncopyable
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 private:
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
49 size_t index_;
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
50 std::unique_ptr<IJobOperation> operation_;
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
51 std::unique_ptr<JobOperationValues> originalInputs_;
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
52 std::unique_ptr<JobOperationValues> workInputs_;
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
53 std::list<Operation*> nextOperations_;
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
54 size_t currentInput_;
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 public:
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
57 Operation(size_t index,
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
58 IJobOperation* operation) :
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
59 index_(index),
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
60 operation_(operation),
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
61 originalInputs_(new JobOperationValues),
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
62 workInputs_(new JobOperationValues),
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
63 currentInput_(0)
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 if (operation == NULL)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 throw OrthancException(ErrorCode_NullPointer);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
4310
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
71 void AddOriginalInput(const IJobOperationValue& value)
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 if (currentInput_ != 0)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 // Cannot add input after processing has started
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 throw OrthancException(ErrorCode_BadSequenceOfCalls);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 else
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 {
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
80 originalInputs_->Append(value.Clone());
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 const JobOperationValues& GetOriginalInputs() const
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
86 return *originalInputs_;
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 void Reset()
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 {
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
91 workInputs_->Clear();
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 currentInput_ = 0;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
95 void AddNextOperation(Operation& other,
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
96 bool unserializing)
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 {
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
98 if (other.index_ <= index_)
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
99 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
100 throw OrthancException(ErrorCode_InternalError);
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
101 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
102
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
103 if (!unserializing &&
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
104 currentInput_ != 0)
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 // Cannot add input after processing has started
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 throw OrthancException(ErrorCode_BadSequenceOfCalls);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 else
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 nextOperations_.push_back(&other);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 bool IsDone() const
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 {
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
117 return currentInput_ >= originalInputs_->GetSize() + workInputs_->GetSize();
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
3851
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
120 void Step()
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 if (IsDone())
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 throw OrthancException(ErrorCode_BadSequenceOfCalls);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
4310
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
127 const IJobOperationValue* input;
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
129 if (currentInput_ < originalInputs_->GetSize())
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 {
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
131 input = &originalInputs_->GetValue(currentInput_);
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 else
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 {
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
135 input = &workInputs_->GetValue(currentInput_ - originalInputs_->GetSize());
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 JobOperationValues outputs;
3851
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
139 operation_->Apply(outputs, *input);
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 if (!nextOperations_.empty())
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 std::list<Operation*>::iterator first = nextOperations_.begin();
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
144 outputs.Move(*(*first)->workInputs_);
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 std::list<Operation*>::iterator current = first;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 ++current;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 while (current != nextOperations_.end())
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 {
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
151 (*first)->workInputs_->Copy(*(*current)->workInputs_);
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 ++current;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 currentInput_ += 1;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 }
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
158
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
159 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
160 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
161 target = Json::objectValue;
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
162 target[CURRENT] = static_cast<unsigned int>(currentInput_);
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
163 operation_->Serialize(target[OPERATION]);
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
164 originalInputs_->Serialize(target[ORIGINAL_INPUTS]);
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
165 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
166
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
167 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
168 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
169 it != nextOperations_.end(); ++it)
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 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
172 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
173
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
174 target[NEXT_OPERATIONS] = tmp;
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
175 }
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
176
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
177 Operation(IJobUnserializer& unserializer,
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
178 Json::Value::ArrayIndex index,
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
179 const Json::Value& serialized) :
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
180 index_(index)
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
181 {
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
182 if (serialized.type() != Json::objectValue ||
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
183 !serialized.isMember(OPERATION) ||
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
184 !serialized.isMember(ORIGINAL_INPUTS) ||
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
185 !serialized.isMember(WORK_INPUTS))
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 throw OrthancException(ErrorCode_BadFileFormat);
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
188 }
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
189
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
190 currentInput_ = SerializationToolbox::ReadUnsignedInteger(serialized, CURRENT);
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
191 operation_.reset(unserializer.UnserializeOperation(serialized[OPERATION]));
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
192 originalInputs_.reset(JobOperationValues::Unserialize
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
193 (unserializer, serialized[ORIGINAL_INPUTS]));
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
194 workInputs_.reset(JobOperationValues::Unserialize
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
195 (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
196 }
2603
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
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
200 SequenceOfOperationsJob::SequenceOfOperationsJob() :
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
201 done_(false),
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
202 current_(0),
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
203 trailingTimeout_(boost::posix_time::milliseconds(1000))
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 SequenceOfOperationsJob::~SequenceOfOperationsJob()
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 for (size_t i = 0; i < operations_.size(); i++)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 if (operations_[i] != NULL)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 delete operations_[i];
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
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
220 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
221 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
222 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
223 description_ = description;
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
224 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
225
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
226
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
227 void SequenceOfOperationsJob::GetDescription(std::string& description)
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
228 {
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
229 boost::mutex::scoped_lock lock(mutex_);
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
230 description = description_;
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
231 }
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
232
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
233
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 void SequenceOfOperationsJob::Register(IObserver& observer)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 boost::mutex::scoped_lock lock(mutex_);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 observers_.push_back(&observer);
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
4348
93c281752e7a reintroduced backward ABI compatibility in Orthanc Framework .so for unit tests of Orthanc 1.7.2 to 1.8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
241 #if ORTHANC_BUILDING_FRAMEWORK_LIBRARY == 1
93c281752e7a reintroduced backward ABI compatibility in Orthanc Framework .so for unit tests of Orthanc 1.7.2 to 1.8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
242 void SequenceOfOperationsJob::Lock::AddInput(size_t index,
93c281752e7a reintroduced backward ABI compatibility in Orthanc Framework .so for unit tests of Orthanc 1.7.2 to 1.8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
243 const JobOperationValue& value)
93c281752e7a reintroduced backward ABI compatibility in Orthanc Framework .so for unit tests of Orthanc 1.7.2 to 1.8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
244 {
93c281752e7a reintroduced backward ABI compatibility in Orthanc Framework .so for unit tests of Orthanc 1.7.2 to 1.8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
245 throw OrthancException(ErrorCode_DiscontinuedAbi, "Removed in 1.8.1");
93c281752e7a reintroduced backward ABI compatibility in Orthanc Framework .so for unit tests of Orthanc 1.7.2 to 1.8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
246 }
93c281752e7a reintroduced backward ABI compatibility in Orthanc Framework .so for unit tests of Orthanc 1.7.2 to 1.8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
247 #endif
93c281752e7a reintroduced backward ABI compatibility in Orthanc Framework .so for unit tests of Orthanc 1.7.2 to 1.8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
248
93c281752e7a reintroduced backward ABI compatibility in Orthanc Framework .so for unit tests of Orthanc 1.7.2 to 1.8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
249
4304
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
250 SequenceOfOperationsJob::Lock::Lock(SequenceOfOperationsJob& that) :
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
251 that_(that),
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
252 lock_(that.mutex_)
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
253 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
254 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
255
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
256 bool SequenceOfOperationsJob::Lock::IsDone() const
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
257 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
258 return that_.done_;
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
259 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
260
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 void SequenceOfOperationsJob::Lock::SetTrailingOperationTimeout(unsigned int timeout)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 that_.trailingTimeout_ = boost::posix_time::milliseconds(timeout);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265
2608
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
266
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 size_t SequenceOfOperationsJob::Lock::AddOperation(IJobOperation* operation)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 if (IsDone())
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 throw OrthancException(ErrorCode_BadSequenceOfCalls);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
274 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
275
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
276 that_.operations_.push_back(new Operation(index, operation));
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 that_.operationAdded_.notify_one();
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
279 return index;
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281
4304
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
282 size_t SequenceOfOperationsJob::Lock::GetOperationsCount() const
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
283 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
284 return that_.operations_.size();
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
285 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
286
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 void SequenceOfOperationsJob::Lock::AddInput(size_t index,
4310
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
289 const IJobOperationValue& value)
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 if (IsDone())
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 throw OrthancException(ErrorCode_BadSequenceOfCalls);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 else if (index >= that_.operations_.size() ||
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 index < that_.current_)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 throw OrthancException(ErrorCode_ParameterOutOfRange);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 else
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 that_.operations_[index]->AddOriginalInput(value);
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
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 void SequenceOfOperationsJob::Lock::Connect(size_t input,
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 size_t output)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 if (IsDone())
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 throw OrthancException(ErrorCode_BadSequenceOfCalls);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 else if (input >= output ||
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 input >= that_.operations_.size() ||
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 output >= that_.operations_.size() ||
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 input < that_.current_ ||
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 output < that_.current_)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 throw OrthancException(ErrorCode_ParameterOutOfRange);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 else
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 Operation& a = *that_.operations_[input];
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 Operation& b = *that_.operations_[output];
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
326 a.AddNextOperation(b, false /* not unserializing */);
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330
4304
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
331 void SequenceOfOperationsJob::Start()
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
332 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
333 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
334
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
335
3658
2d90dd30858c providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
336 JobStepResult SequenceOfOperationsJob::Step(const std::string& jobId)
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 boost::mutex::scoped_lock lock(mutex_);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 if (current_ == operations_.size())
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 LOG(INFO) << "Executing the trailing timeout in the sequence of operations";
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 operationAdded_.timed_wait(lock, trailingTimeout_);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 if (current_ == operations_.size())
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 // No operation was added during the trailing timeout: The
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 // job is over
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 LOG(INFO) << "The sequence of operations is over";
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 done_ = true;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 for (std::list<IObserver*>::iterator it = observers_.begin();
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 it != observers_.end(); ++it)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 (*it)->SignalDone(*this);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 return JobStepResult::Success();
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 else
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 {
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
362 LOG(INFO) << "New operation were added to the sequence of operations";
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 assert(current_ < operations_.size());
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 while (current_ < operations_.size() &&
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 operations_[current_]->IsDone())
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 current_++;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 if (current_ < operations_.size())
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 {
3851
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
376 operations_[current_]->Step();
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 return JobStepResult::Continue();
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2811
diff changeset
383 void SequenceOfOperationsJob::Reset()
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 boost::mutex::scoped_lock lock(mutex_);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 current_ = 0;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 done_ = false;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 for (size_t i = 0; i < operations_.size(); i++)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 operations_[i]->Reset();
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395
4304
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
396 void SequenceOfOperationsJob::Stop(JobStopReason reason)
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
397 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
398 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
399
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 float SequenceOfOperationsJob::GetProgress()
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 boost::mutex::scoped_lock lock(mutex_);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 return (static_cast<float>(current_) /
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 static_cast<float>(operations_.size() + 1));
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408
4304
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
409 void SequenceOfOperationsJob::GetJobType(std::string& target)
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
410 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
411 target = "SequenceOfOperations";
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
412 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
413
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 void SequenceOfOperationsJob::GetPublicContent(Json::Value& value)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 boost::mutex::scoped_lock lock(mutex_);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 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
420 value["Description"] = description_;
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
421 }
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
422
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
423
2663
228e2783ce83 some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
424 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
425 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
426 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
427
2665
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2663
diff changeset
428 value = Json::objectValue;
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
429
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
430 std::string jobType;
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
431 GetJobType(jobType);
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
432 value[TYPE] = jobType;
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
433
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
434 value[DESCRIPTION] = description_;
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
435 value[TRAILING_TIMEOUT] = static_cast<unsigned int>(trailingTimeout_.total_milliseconds());
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
436 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
437
2621
83ac5a05ce84 primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
438 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
439 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
440 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
441 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
442 operations_[i]->Serialize(operation);
2621
83ac5a05ce84 primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
443 tmp.append(operation);
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
444 }
2621
83ac5a05ce84 primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
445
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
446 value[OPERATIONS] = tmp;
2663
228e2783ce83 some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
447
228e2783ce83 some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
448 return true;
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 }
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
450
4304
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
451
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
452 void SequenceOfOperationsJob::AwakeTrailingSleep()
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
453 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
454 operationAdded_.notify_one();
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
455 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
456
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
457
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
458 SequenceOfOperationsJob::SequenceOfOperationsJob(IJobUnserializer& unserializer,
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
459 const Json::Value& serialized) :
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
460 done_(false)
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
461 {
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
462 std::string jobType;
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
463 GetJobType(jobType);
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
464
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
465 if (SerializationToolbox::ReadString(serialized, TYPE) != jobType ||
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
466 !serialized.isMember(OPERATIONS) ||
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
467 serialized[OPERATIONS].type() != Json::arrayValue)
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 throw OrthancException(ErrorCode_BadFileFormat);
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
470 }
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
471
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
472 description_ = SerializationToolbox::ReadString(serialized, DESCRIPTION);
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
473 trailingTimeout_ = boost::posix_time::milliseconds
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
474 (SerializationToolbox::ReadUnsignedInteger(serialized, TRAILING_TIMEOUT));
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
475 current_ = SerializationToolbox::ReadUnsignedInteger(serialized, CURRENT);
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
476
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
477 const Json::Value& ops = serialized[OPERATIONS];
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 // Unserialize the individual operations
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
480 operations_.reserve(ops.size());
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
481 for (Json::Value::ArrayIndex i = 0; i < ops.size(); i++)
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
482 {
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
483 operations_.push_back(new Operation(unserializer, i, ops[i]));
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
484 }
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 // Connect the next operations
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
487 for (Json::Value::ArrayIndex i = 0; i < ops.size(); i++)
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
488 {
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
489 if (!ops[i].isMember(NEXT_OPERATIONS) ||
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
490 ops[i][NEXT_OPERATIONS].type() != Json::arrayValue)
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 throw OrthancException(ErrorCode_BadFileFormat);
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
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
495 const Json::Value& next = ops[i][NEXT_OPERATIONS];
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
496 for (Json::Value::ArrayIndex j = 0; j < next.size(); j++)
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
497 {
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
498 if (next[j].type() != Json::intValue ||
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
499 next[j].asInt() < 0 ||
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
500 next[j].asUInt() >= operations_.size())
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
501 {
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
502 throw OrthancException(ErrorCode_BadFileFormat);
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
503 }
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
504 else
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
505 {
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
506 operations_[i]->AddNextOperation(*operations_[next[j].asUInt()], true);
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
507 }
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
508 }
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
509 }
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
510 }
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 }