Mercurial > hg > orthanc
annotate OrthancFramework/Sources/JobsEngine/JobsEngine.h @ 4224:38d446c9ee1d
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 30 Sep 2020 17:59:09 +0200 |
parents | 2007ab69ac16 |
children | d9473bd5ed43 |
rev | line source |
---|---|
2569 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
2569 | 6 * |
7 * 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:
4063
diff
changeset
|
8 * 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:
4063
diff
changeset
|
9 * 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:
4063
diff
changeset
|
10 * the License, or (at your option) any later version. |
2569 | 11 * |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * 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:
4063
diff
changeset
|
15 * Lesser General Public License for more details. |
2569 | 16 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
17 * 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:
4063
diff
changeset
|
18 * 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:
4063
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
2569 | 20 **/ |
21 | |
22 | |
23 #pragma once | |
24 | |
25 #include "JobsRegistry.h" | |
26 | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
27 #include "../Compatibility.h" |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
28 |
2569 | 29 #include <boost/thread.hpp> |
30 | |
31 namespace Orthanc | |
32 { | |
4063
e00f3d089991
shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
33 class ORTHANC_PUBLIC JobsEngine : public boost::noncopyable |
2569 | 34 { |
35 private: | |
36 enum State | |
37 { | |
38 State_Setup, | |
39 State_Running, | |
40 State_Stopping, | |
41 State_Done | |
42 }; | |
43 | |
2591
441f23af9d89
fix for older releases of boost::thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
44 boost::mutex stateMutex_; |
441f23af9d89
fix for older releases of boost::thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
45 State state_; |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
46 std::unique_ptr<JobsRegistry> registry_; |
2591
441f23af9d89
fix for older releases of boost::thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
47 boost::thread retryHandler_; |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2591
diff
changeset
|
48 unsigned int threadSleep_; |
2591
441f23af9d89
fix for older releases of boost::thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
49 std::vector<boost::thread*> workers_; |
2569 | 50 |
2573
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
51 bool IsRunning(); |
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
52 |
2569 | 53 bool ExecuteStep(JobsRegistry::RunningJob& running, |
54 size_t workerIndex); | |
55 | |
56 static void RetryHandler(JobsEngine* engine); | |
57 | |
58 static void Worker(JobsEngine* engine, | |
59 size_t workerIndex); | |
60 | |
61 public: | |
4202
2007ab69ac16
moving ORTHANC_FORCE_INLINE and ORTHANC_OVERRIDE from Enumerations.h to Compatibility.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
62 explicit JobsEngine(size_t maxCompletedJobs); |
2569 | 63 |
64 ~JobsEngine(); | |
65 | |
2668
d26dd081df97
saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
66 JobsRegistry& GetRegistry(); |
d26dd081df97
saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
67 |
d26dd081df97
saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
68 void LoadRegistryFromJson(IJobUnserializer& unserializer, |
d26dd081df97
saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
69 const Json::Value& serialized); |
d26dd081df97
saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
70 |
d26dd081df97
saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
71 void LoadRegistryFromString(IJobUnserializer& unserializer, |
d26dd081df97
saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
72 const std::string& serialized); |
d26dd081df97
saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
73 |
2569 | 74 void SetWorkersCount(size_t count); |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2591
diff
changeset
|
75 |
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2591
diff
changeset
|
76 void SetThreadSleep(unsigned int sleep); |
2569 | 77 |
78 void Start(); | |
79 | |
80 void Stop(); | |
81 }; | |
82 } |