annotate OrthancFramework/Sources/JobsEngine/SetOfCommandsJob.cpp @ 5660:e4d9a872998f

replaced incorrect macro WIN32 by _WIN32
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sun, 23 Jun 2024 10:24:31 +0200
parents f7adfb22e20e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
8b00e4cb4a6b SetOfCommandsJob
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
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
8b00e4cb4a6b SetOfCommandsJob
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.
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
8b00e4cb4a6b SetOfCommandsJob
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.
2860
8b00e4cb4a6b SetOfCommandsJob
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/>.
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 **/
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "../PrecompiledHeaders.h"
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "SetOfCommandsJob.h"
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include "../Logging.h"
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include "../OrthancException.h"
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include "../SerializationToolbox.h"
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include <cassert>
2866
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2860
diff changeset
33 #include <memory>
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 namespace Orthanc
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 SetOfCommandsJob::SetOfCommandsJob() :
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 started_(false),
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 permissive_(false),
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 position_(0)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 SetOfCommandsJob::~SetOfCommandsJob()
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 for (size_t i = 0; i < commands_.size(); i++)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 assert(commands_[i] != NULL);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 delete commands_[i];
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
54 size_t SetOfCommandsJob::GetPosition() const
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
55 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
56 return position_;
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
57 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
58
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
59 void SetOfCommandsJob::SetDescription(const std::string &description)
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
60 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
61 description_ = description;
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
62 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
63
4304
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4303
diff changeset
64 const std::string& SetOfCommandsJob::GetDescription() const
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4303
diff changeset
65 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4303
diff changeset
66 return description_;
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4303
diff changeset
67 }
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
68
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 void SetOfCommandsJob::Reserve(size_t size)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 if (started_)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 throw OrthancException(ErrorCode_BadSequenceOfCalls);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 else
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 commands_.reserve(size);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
81 size_t SetOfCommandsJob::GetCommandsCount() const
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
82 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
83 return commands_.size();
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
84 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
85
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
86
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 void SetOfCommandsJob::AddCommand(ICommand* command)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 if (command == NULL)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 throw OrthancException(ErrorCode_NullPointer);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 else if (started_)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 throw OrthancException(ErrorCode_BadSequenceOfCalls);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 else
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 commands_.push_back(command);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
103 bool SetOfCommandsJob::IsPermissive() const
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
104 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
105 return permissive_;
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
106 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
107
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 void SetOfCommandsJob::SetPermissive(bool permissive)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 if (started_)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 throw OrthancException(ErrorCode_BadSequenceOfCalls);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 else
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 permissive_ = permissive;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 void SetOfCommandsJob::Reset()
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 if (started_)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 position_ = 0;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 else
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 throw OrthancException(ErrorCode_BadSequenceOfCalls);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
134 void SetOfCommandsJob::Start()
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
135 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
136 started_ = true;
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
137 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
138
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
139
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 float SetOfCommandsJob::GetProgress()
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 if (commands_.empty())
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 return 1;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 else
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 return (static_cast<float>(position_) /
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 static_cast<float>(commands_.size()));
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
153 bool SetOfCommandsJob::IsStarted() const
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
154 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
155 return started_;
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
156 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
157
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 const SetOfCommandsJob::ICommand& SetOfCommandsJob::GetCommand(size_t index) const
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 if (index >= commands_.size())
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 throw OrthancException(ErrorCode_ParameterOutOfRange);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 else
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 assert(commands_[index] != NULL);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 return *commands_[index];
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172
3658
2d90dd30858c providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
173 JobStepResult SetOfCommandsJob::Step(const std::string& jobId)
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 if (!started_)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 throw OrthancException(ErrorCode_InternalError);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 if (commands_.empty() &&
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 position_ == 0)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 // No command to handle: We're done
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 position_ = 1;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 return JobStepResult::Success();
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 if (position_ >= commands_.size())
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 // Already done
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 throw OrthancException(ErrorCode_BadSequenceOfCalls);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 try
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 // Not at the trailing step: Handle the current command
3658
2d90dd30858c providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
197 if (!commands_[position_]->Execute(jobId))
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 // Error
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 if (!permissive_)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 {
3240
e44e0127e553 Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
202 return JobStepResult::Failure(ErrorCode_InternalError, NULL);
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 catch (OrthancException& e)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 if (permissive_)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 LOG(WARNING) << "Ignoring an error in a permissive job: " << e.What();
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 else
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 {
3240
e44e0127e553 Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
214 return JobStepResult::Failure(e);
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 position_ += 1;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 if (position_ == commands_.size())
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 // We're done
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 return JobStepResult::Success();
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 else
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 return JobStepResult::Continue();
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 static const char* KEY_DESCRIPTION = "Description";
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 static const char* KEY_PERMISSIVE = "Permissive";
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 static const char* KEY_POSITION = "Position";
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 static const char* KEY_TYPE = "Type";
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 static const char* KEY_COMMANDS = "Commands";
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 void SetOfCommandsJob::GetPublicContent(Json::Value& value)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 value[KEY_DESCRIPTION] = GetDescription();
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 bool SetOfCommandsJob::Serialize(Json::Value& target)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 target = Json::objectValue;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 std::string type;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 GetJobType(type);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 target[KEY_TYPE] = type;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 target[KEY_PERMISSIVE] = permissive_;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 target[KEY_POSITION] = static_cast<unsigned int>(position_);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 target[KEY_DESCRIPTION] = description_;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 target[KEY_COMMANDS] = Json::arrayValue;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 Json::Value& tmp = target[KEY_COMMANDS];
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 for (size_t i = 0; i < commands_.size(); i++)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 assert(commands_[i] != NULL);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 Json::Value command;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 commands_[i]->Serialize(command);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 tmp.append(command);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 return true;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 SetOfCommandsJob::SetOfCommandsJob(ICommandUnserializer* unserializer,
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 const Json::Value& source) :
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 started_(false)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 {
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
278 std::unique_ptr<ICommandUnserializer> raii(unserializer);
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 permissive_ = SerializationToolbox::ReadBoolean(source, KEY_PERMISSIVE);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 position_ = SerializationToolbox::ReadUnsignedInteger(source, KEY_POSITION);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 description_ = SerializationToolbox::ReadString(source, KEY_DESCRIPTION);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 if (!source.isMember(KEY_COMMANDS) ||
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 source[KEY_COMMANDS].type() != Json::arrayValue)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 throw OrthancException(ErrorCode_BadFileFormat);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 else
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 const Json::Value& tmp = source[KEY_COMMANDS];
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 commands_.resize(tmp.size());
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 for (Json::Value::ArrayIndex i = 0; i < tmp.size(); i++)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 try
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 commands_[i] = unserializer->Unserialize(tmp[i]);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 catch (OrthancException&)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 if (commands_[i] == NULL)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 for (size_t j = 0; j < i; j++)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 delete commands_[j];
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 throw OrthancException(ErrorCode_BadFileFormat);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 if (commands_.empty())
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 if (position_ > 1)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 throw OrthancException(ErrorCode_BadFileFormat);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 else if (position_ > commands_.size())
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 throw OrthancException(ErrorCode_BadFileFormat);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 }