Mercurial > hg > orthanc
comparison Core/JobsEngine/JobsEngine.cpp @ 2668:d26dd081df97 jobs
saving jobs engine on exit
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 08 Jun 2018 18:08:48 +0200 |
parents | 389d050a2e66 |
children | 7cfc8d266f41 |
comparison
equal
deleted
inserted
replaced
2667:5fa2f2ce74f0 | 2668:d26dd081df97 |
---|---|
35 #include "JobsEngine.h" | 35 #include "JobsEngine.h" |
36 | 36 |
37 #include "../Logging.h" | 37 #include "../Logging.h" |
38 #include "../OrthancException.h" | 38 #include "../OrthancException.h" |
39 | 39 |
40 #include <json/reader.h> | |
41 | |
40 namespace Orthanc | 42 namespace Orthanc |
41 { | 43 { |
42 bool JobsEngine::IsRunning() | 44 bool JobsEngine::IsRunning() |
43 { | 45 { |
44 boost::mutex::scoped_lock lock(stateMutex_); | 46 boost::mutex::scoped_lock lock(stateMutex_); |
154 } | 156 } |
155 | 157 |
156 | 158 |
157 JobsEngine::JobsEngine() : | 159 JobsEngine::JobsEngine() : |
158 state_(State_Setup), | 160 state_(State_Setup), |
161 registry_(new JobsRegistry), | |
159 threadSleep_(200), | 162 threadSleep_(200), |
160 workers_(1) | 163 workers_(1) |
161 { | 164 { |
162 } | 165 } |
163 | 166 |
170 LOG(ERROR) << "INTERNAL ERROR: JobsEngine::Stop() should be invoked manually to avoid mess in the destruction order!"; | 173 LOG(ERROR) << "INTERNAL ERROR: JobsEngine::Stop() should be invoked manually to avoid mess in the destruction order!"; |
171 Stop(); | 174 Stop(); |
172 } | 175 } |
173 } | 176 } |
174 | 177 |
175 | 178 |
179 JobsRegistry& JobsEngine::GetRegistry() | |
180 { | |
181 if (registry_.get() == NULL) | |
182 { | |
183 throw OrthancException(ErrorCode_InternalError); | |
184 } | |
185 | |
186 return *registry_; | |
187 } | |
188 | |
189 | |
190 void JobsEngine::LoadRegistryFromJson(IJobUnserializer& unserializer, | |
191 const Json::Value& serialized) | |
192 { | |
193 boost::mutex::scoped_lock lock(stateMutex_); | |
194 | |
195 if (state_ != State_Setup) | |
196 { | |
197 // Can only be invoked before calling "Start()" | |
198 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
199 } | |
200 | |
201 registry_.reset(new JobsRegistry(unserializer, serialized)); | |
202 } | |
203 | |
204 | |
205 void JobsEngine::LoadRegistryFromString(IJobUnserializer& unserializer, | |
206 const std::string& serialized) | |
207 { | |
208 Json::Value value; | |
209 Json::Reader reader; | |
210 if (reader.parse(serialized, value)) | |
211 { | |
212 LoadRegistryFromJson(unserializer, value); | |
213 } | |
214 else | |
215 { | |
216 throw OrthancException(ErrorCode_BadFileFormat); | |
217 } | |
218 } | |
219 | |
220 | |
176 void JobsEngine::SetWorkersCount(size_t count) | 221 void JobsEngine::SetWorkersCount(size_t count) |
177 { | 222 { |
178 boost::mutex::scoped_lock lock(stateMutex_); | 223 boost::mutex::scoped_lock lock(stateMutex_); |
179 | 224 |
180 if (state_ != State_Setup) | 225 if (state_ != State_Setup) |