annotate Framework/Oracle/ThreadedOracle.h @ 1049:348866dd217c

removing classes OpenGLContextLostException and StoneOrthancException
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 10 Oct 2019 14:29:02 +0200
parents 3a984741686f
children 81b29bc7c3d4 2d8ab34c8c91
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
748
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #pragma once
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #if !defined(ORTHANC_ENABLE_THREADS)
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 # error The macro ORTHANC_ENABLE_THREADS must be defined
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #endif
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #if ORTHANC_ENABLE_THREADS != 1
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 # error This file can only compiled for native targets
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #endif
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include "../Messages/IMessageEmitter.h"
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include "IOracle.h"
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include <Core/WebServiceParameters.h>
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include <Core/MultiThreading/SharedMessageQueue.h>
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 namespace OrthancStone
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 class ThreadedOracle : public IOracle
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 private:
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 enum State
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 State_Setup,
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 State_Running,
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 State_Stopped
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 };
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 class Item;
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 class SleepingCommands;
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 IMessageEmitter& emitter_;
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 Orthanc::WebServiceParameters orthanc_;
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 Orthanc::SharedMessageQueue queue_;
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 State state_;
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 boost::mutex mutex_;
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 std::vector<boost::thread*> workers_;
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 boost::shared_ptr<SleepingCommands> sleepingCommands_;
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 boost::thread sleepingWorker_;
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 unsigned int sleepingTimeResolution_;
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 void Step();
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 static void Worker(ThreadedOracle* that);
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 static void SleepingWorker(ThreadedOracle* that);
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 void StopInternal();
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 public:
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 ThreadedOracle(IMessageEmitter& emitter);
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
765
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
75 virtual ~ThreadedOracle();
748
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
828
28f99af358fa Merge + FusionMprSdl
Benjamin Golinvaux <bgo@osimis.io>
parents: 765
diff changeset
77 // The reference is not stored.
748
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 void SetOrthancParameters(const Orthanc::WebServiceParameters& orthanc);
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
760
1181e1ad98ec progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 748
diff changeset
80 void SetThreadsCount(unsigned int count);
748
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 void SetSleepingTimeResolution(unsigned int milliseconds);
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
84 void Start();
748
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
86 void Stop()
748
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 {
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 StopInternal();
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 }
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 virtual void Schedule(const IObserver& receiver,
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 IOracleCommand* command);
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 };
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 }