Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Loaders/LoaderStateMachine.h @ 1512:244ad1e4e76a
reorganization of folders
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jul 2020 16:21:02 +0200 |
parents | Framework/Loaders/LoaderStateMachine.h@30deba7bc8e2 |
children | 85e117739eca |
comparison
equal
deleted
inserted
replaced
1511:9dfeee74c1e6 | 1512:244ad1e4e76a |
---|---|
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-2020 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/ObserverBase.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 <IDynamicObject.h> | |
33 | |
34 #include <list> | |
35 | |
36 namespace OrthancStone | |
37 { | |
38 class ILoadersContext; | |
39 | |
40 /** | |
41 This class is supplied with Oracle commands and will schedule up to | |
42 simultaneousDownloads_ of them at the same time, then will schedule the | |
43 rest once slots become available. It is used, a.o., by the | |
44 OrtancMultiframeVolumeLoader class. | |
45 | |
46 To use it, you need to create commands that derive from State. | |
47 | |
48 You need to initialize them with the object that must be called when | |
49 an answer is received. | |
50 */ | |
51 | |
52 class LoaderStateMachine : public OrthancStone::ObserverBase<LoaderStateMachine> | |
53 { | |
54 public: | |
55 class State : public Orthanc::IDynamicObject | |
56 { | |
57 private: | |
58 LoaderStateMachine& that_; | |
59 | |
60 public: | |
61 State(LoaderStateMachine& that) : | |
62 that_(that) | |
63 { | |
64 } | |
65 | |
66 State(const State& currentState) : | |
67 that_(currentState.that_) | |
68 { | |
69 } | |
70 | |
71 void Schedule(OrthancStone::OracleCommandBase* command) const | |
72 { | |
73 that_.Schedule(command); | |
74 } | |
75 | |
76 template <typename T> | |
77 T& GetLoader() const | |
78 { | |
79 return dynamic_cast<T&>(that_); | |
80 } | |
81 | |
82 virtual void Handle(const OrthancStone::OrthancRestApiCommand::SuccessMessage& message); | |
83 | |
84 virtual void Handle(const OrthancStone::GetOrthancImageCommand::SuccessMessage& message); | |
85 | |
86 virtual void Handle(const OrthancStone::GetOrthancWebViewerJpegCommand::SuccessMessage& message); | |
87 }; | |
88 | |
89 void Schedule(OrthancStone::OracleCommandBase* command); | |
90 | |
91 void Start(); | |
92 | |
93 private: | |
94 void Step(); | |
95 | |
96 void Clear(); | |
97 | |
98 void HandleExceptionMessage(const OrthancStone::OracleCommandExceptionMessage& message); | |
99 | |
100 template <typename T> | |
101 void HandleSuccessMessage(const T& message); | |
102 | |
103 typedef std::list<OrthancStone::IOracleCommand*> PendingCommands; | |
104 | |
105 OrthancStone::ILoadersContext& loadersContext_; | |
106 bool active_; | |
107 unsigned int simultaneousDownloads_; | |
108 PendingCommands pendingCommands_; | |
109 unsigned int activeCommands_; | |
110 | |
111 | |
112 public: | |
113 LoaderStateMachine(OrthancStone::ILoadersContext& loadersContext); | |
114 | |
115 void PostConstructor(); | |
116 | |
117 virtual ~LoaderStateMachine(); | |
118 | |
119 bool IsActive() const | |
120 { | |
121 return active_; | |
122 } | |
123 | |
124 void SetSimultaneousDownloads(unsigned int count); | |
125 }; | |
126 } |