Mercurial > hg > orthanc-stone
annotate Framework/Loaders/LoaderStateMachine.h @ 1036:d7d3227c11a9
merge
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 07 Oct 2019 15:26:29 +0200 |
parents | 262a0244e9b2 |
children | e713f1a99861 2d8ab34c8c91 |
rev | line source |
---|---|
815 | 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 #include "../Messages/IObservable.h" | |
25 #include "../Messages/IObserver.h" | |
26 #include "../Oracle/GetOrthancImageCommand.h" | |
27 #include "../Oracle/GetOrthancWebViewerJpegCommand.h" | |
28 #include "../Oracle/IOracle.h" | |
29 #include "../Oracle/OracleCommandExceptionMessage.h" | |
30 #include "../Oracle/OrthancRestApiCommand.h" | |
31 | |
32 #include <Core/IDynamicObject.h> | |
33 | |
34 #include <list> | |
35 | |
36 namespace OrthancStone | |
37 { | |
38 /** | |
39 This class is supplied with Oracle commands and will schedule up to | |
40 simultaneousDownloads_ of them at the same time, then will schedule the | |
41 rest once slots become available. It is used, a.o., by the | |
42 OrtancMultiframeVolumeLoader class. | |
43 */ | |
44 class LoaderStateMachine : public IObserver | |
45 { | |
46 protected: | |
47 class State : public Orthanc::IDynamicObject | |
48 { | |
49 private: | |
50 LoaderStateMachine& that_; | |
51 | |
52 public: | |
53 State(LoaderStateMachine& that) : | |
54 that_(that) | |
55 { | |
56 } | |
57 | |
58 State(const State& currentState) : | |
59 that_(currentState.that_) | |
60 { | |
61 } | |
62 | |
63 void Schedule(OracleCommandWithPayload* command) const | |
64 { | |
65 that_.Schedule(command); | |
66 } | |
67 | |
68 template <typename T> | |
69 T& GetLoader() const | |
70 { | |
71 return dynamic_cast<T&>(that_); | |
72 } | |
73 | |
74 virtual void Handle(const OrthancRestApiCommand::SuccessMessage& message); | |
75 | |
76 virtual void Handle(const GetOrthancImageCommand::SuccessMessage& message); | |
77 | |
78 virtual void Handle(const GetOrthancWebViewerJpegCommand::SuccessMessage& message); | |
79 }; | |
80 | |
81 void Schedule(OracleCommandWithPayload* command); | |
82 | |
83 void Start(); | |
84 | |
85 private: | |
86 void Step(); | |
87 | |
88 void Clear(); | |
89 | |
90 void HandleExceptionMessage(const OracleCommandExceptionMessage& message); | |
91 | |
92 template <typename T> | |
93 void HandleSuccessMessage(const T& message); | |
94 | |
95 typedef std::list<IOracleCommand*> PendingCommands; | |
96 | |
97 IOracle& oracle_; | |
977
262a0244e9b2
Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents:
973
diff
changeset
|
98 IObservable& oracleObservable_; |
815 | 99 bool active_; |
100 unsigned int simultaneousDownloads_; | |
101 PendingCommands pendingCommands_; | |
102 unsigned int activeCommands_; | |
103 | |
104 public: | |
105 LoaderStateMachine(IOracle& oracle, | |
106 IObservable& oracleObservable); | |
107 | |
973
38409549db43
Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
815
diff
changeset
|
108 virtual ~LoaderStateMachine(); |
815 | 109 |
110 bool IsActive() const | |
111 { | |
112 return active_; | |
113 } | |
114 | |
115 void SetSimultaneousDownloads(unsigned int count); | |
116 }; | |
117 } |