Mercurial > hg > orthanc-stone
comparison Framework/Oracle/ThreadedOracle.h @ 748:ab236bb5dbc7
ThreadedOracle
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 22 May 2019 14:46:26 +0200 |
parents | |
children | 1181e1ad98ec |
comparison
equal
deleted
inserted
replaced
746:d716bfb3e07c | 748:ab236bb5dbc7 |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
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 | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #pragma once | |
23 | |
24 #if !defined(ORTHANC_ENABLE_THREADS) | |
25 # error The macro ORTHANC_ENABLE_THREADS must be defined | |
26 #endif | |
27 | |
28 #if ORTHANC_ENABLE_THREADS != 1 | |
29 # error This file can only compiled for native targets | |
30 #endif | |
31 | |
32 #include "../Messages/IMessageEmitter.h" | |
33 #include "IOracle.h" | |
34 | |
35 #include <Core/WebServiceParameters.h> | |
36 #include <Core/MultiThreading/SharedMessageQueue.h> | |
37 | |
38 | |
39 namespace OrthancStone | |
40 { | |
41 class ThreadedOracle : public IOracle | |
42 { | |
43 private: | |
44 enum State | |
45 { | |
46 State_Setup, | |
47 State_Running, | |
48 State_Stopped | |
49 }; | |
50 | |
51 class Item; | |
52 class SleepingCommands; | |
53 | |
54 IMessageEmitter& emitter_; | |
55 Orthanc::WebServiceParameters orthanc_; | |
56 Orthanc::SharedMessageQueue queue_; | |
57 State state_; | |
58 boost::mutex mutex_; | |
59 std::vector<boost::thread*> workers_; | |
60 boost::shared_ptr<SleepingCommands> sleepingCommands_; | |
61 boost::thread sleepingWorker_; | |
62 unsigned int sleepingTimeResolution_; | |
63 | |
64 void Step(); | |
65 | |
66 static void Worker(ThreadedOracle* that); | |
67 | |
68 static void SleepingWorker(ThreadedOracle* that); | |
69 | |
70 void StopInternal(); | |
71 | |
72 public: | |
73 ThreadedOracle(IMessageEmitter& emitter); | |
74 | |
75 virtual ~ThreadedOracle() | |
76 { | |
77 StopInternal(); | |
78 } | |
79 | |
80 void SetOrthancParameters(const Orthanc::WebServiceParameters& orthanc); | |
81 | |
82 void SetWorkersCount(unsigned int count); | |
83 | |
84 void SetSleepingTimeResolution(unsigned int milliseconds); | |
85 | |
86 void Start(); | |
87 | |
88 void Stop() | |
89 { | |
90 StopInternal(); | |
91 } | |
92 | |
93 virtual void Schedule(const IObserver& receiver, | |
94 IOracleCommand* command); | |
95 }; | |
96 } |