comparison Framework/Deprecated/Loaders/LoaderStateMachine.h @ 1225:16738485e457 broker

deprecating DicomStructureSetLoader, OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sun, 08 Dec 2019 11:45:09 +0100
parents Framework/Loaders/LoaderStateMachine.h@8e3763d1736a
children 0ca50d275b9a
comparison
equal deleted inserted replaced
1224:37bc7f115f81 1225:16738485e457
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/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 <Core/IDynamicObject.h>
33
34 #include <list>
35
36 namespace Deprecated
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 OrthancStone::ObserverBase<LoaderStateMachine>
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(OrthancStone::OracleCommandBase* 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 OrthancStone::OrthancRestApiCommand::SuccessMessage& message);
75
76 virtual void Handle(const OrthancStone::GetOrthancImageCommand::SuccessMessage& message);
77
78 virtual void Handle(const OrthancStone::GetOrthancWebViewerJpegCommand::SuccessMessage& message);
79 };
80
81 void Schedule(OrthancStone::OracleCommandBase* command);
82
83 void Start();
84
85 private:
86 void Step();
87
88 void Clear();
89
90 void HandleExceptionMessage(const OrthancStone::OracleCommandExceptionMessage& message);
91
92 template <typename T>
93 void HandleSuccessMessage(const T& message);
94
95 typedef std::list<OrthancStone::IOracleCommand*> PendingCommands;
96
97 OrthancStone::IOracle& oracle_;
98 bool active_;
99 unsigned int simultaneousDownloads_;
100 PendingCommands pendingCommands_;
101 unsigned int activeCommands_;
102
103 public:
104 LoaderStateMachine(OrthancStone::IOracle& oracle,
105 OrthancStone::IObservable& oracleObservable);
106
107 virtual ~LoaderStateMachine();
108
109 bool IsActive() const
110 {
111 return active_;
112 }
113
114 void SetSimultaneousDownloads(unsigned int count);
115 };
116 }