Mercurial > hg > orthanc
diff 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 |
line wrap: on
line diff
--- a/Core/JobsEngine/JobsEngine.cpp Fri Jun 08 15:48:35 2018 +0200 +++ b/Core/JobsEngine/JobsEngine.cpp Fri Jun 08 18:08:48 2018 +0200 @@ -37,6 +37,8 @@ #include "../Logging.h" #include "../OrthancException.h" +#include <json/reader.h> + namespace Orthanc { bool JobsEngine::IsRunning() @@ -156,6 +158,7 @@ JobsEngine::JobsEngine() : state_(State_Setup), + registry_(new JobsRegistry), threadSleep_(200), workers_(1) { @@ -172,7 +175,49 @@ } } - + + JobsRegistry& JobsEngine::GetRegistry() + { + if (registry_.get() == NULL) + { + throw OrthancException(ErrorCode_InternalError); + } + + return *registry_; + } + + + void JobsEngine::LoadRegistryFromJson(IJobUnserializer& unserializer, + const Json::Value& serialized) + { + boost::mutex::scoped_lock lock(stateMutex_); + + if (state_ != State_Setup) + { + // Can only be invoked before calling "Start()" + throw OrthancException(ErrorCode_BadSequenceOfCalls); + } + + registry_.reset(new JobsRegistry(unserializer, serialized)); + } + + + void JobsEngine::LoadRegistryFromString(IJobUnserializer& unserializer, + const std::string& serialized) + { + Json::Value value; + Json::Reader reader; + if (reader.parse(serialized, value)) + { + LoadRegistryFromJson(unserializer, value); + } + else + { + throw OrthancException(ErrorCode_BadFileFormat); + } + } + + void JobsEngine::SetWorkersCount(size_t count) { boost::mutex::scoped_lock lock(stateMutex_);