Mercurial > hg > orthanc-stone
annotate Framework/Loaders/LoaderStateMachine.h @ 1337:b1396be5aa27 broker
Moved the fixed loaders back from the dead
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Fri, 03 Apr 2020 16:13:06 +0200 |
parents | Framework/Deprecated/Loaders/LoaderStateMachine.h@9b126de2cde2 |
children | 556b4bc19118 |
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 | |
1271
0ca50d275b9a
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1225
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
815 | 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 | |
1225
16738485e457
deprecating DicomStructureSetLoader, OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
24 #include "../../Messages/IObservable.h" |
16738485e457
deprecating DicomStructureSetLoader, OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
25 #include "../../Messages/ObserverBase.h" |
16738485e457
deprecating DicomStructureSetLoader, OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
26 #include "../../Oracle/GetOrthancImageCommand.h" |
16738485e457
deprecating DicomStructureSetLoader, OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
27 #include "../../Oracle/GetOrthancWebViewerJpegCommand.h" |
16738485e457
deprecating DicomStructureSetLoader, OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
28 #include "../../Oracle/IOracle.h" |
16738485e457
deprecating DicomStructureSetLoader, OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
29 #include "../../Oracle/OracleCommandExceptionMessage.h" |
16738485e457
deprecating DicomStructureSetLoader, OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
30 #include "../../Oracle/OrthancRestApiCommand.h" |
815 | 31 |
32 #include <Core/IDynamicObject.h> | |
33 | |
34 #include <list> | |
35 | |
1310
9bea7e15b519
- first pass at changes to cope with the refactoring of the loading system
Benjamin Golinvaux <bgo@osimis.io>
parents:
1279
diff
changeset
|
36 namespace OrthancStone |
9bea7e15b519
- first pass at changes to cope with the refactoring of the loading system
Benjamin Golinvaux <bgo@osimis.io>
parents:
1279
diff
changeset
|
37 { |
815 | 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. | |
1314
9b126de2cde2
Since the observer system now uses shared_ptr and many registrations are
Benjamin Golinvaux <bgo@osimis.io>
parents:
1310
diff
changeset
|
43 |
9b126de2cde2
Since the observer system now uses shared_ptr and many registrations are
Benjamin Golinvaux <bgo@osimis.io>
parents:
1310
diff
changeset
|
44 To use it, you need to create commands that derive from State. |
9b126de2cde2
Since the observer system now uses shared_ptr and many registrations are
Benjamin Golinvaux <bgo@osimis.io>
parents:
1310
diff
changeset
|
45 |
9b126de2cde2
Since the observer system now uses shared_ptr and many registrations are
Benjamin Golinvaux <bgo@osimis.io>
parents:
1310
diff
changeset
|
46 You need to initialize them with the object that must be called when |
9b126de2cde2
Since the observer system now uses shared_ptr and many registrations are
Benjamin Golinvaux <bgo@osimis.io>
parents:
1310
diff
changeset
|
47 an answer is received. |
815 | 48 */ |
1314
9b126de2cde2
Since the observer system now uses shared_ptr and many registrations are
Benjamin Golinvaux <bgo@osimis.io>
parents:
1310
diff
changeset
|
49 |
1225
16738485e457
deprecating DicomStructureSetLoader, OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
50 class LoaderStateMachine : public OrthancStone::ObserverBase<LoaderStateMachine> |
815 | 51 { |
1314
9b126de2cde2
Since the observer system now uses shared_ptr and many registrations are
Benjamin Golinvaux <bgo@osimis.io>
parents:
1310
diff
changeset
|
52 public: |
815 | 53 class State : public Orthanc::IDynamicObject |
54 { | |
55 private: | |
56 LoaderStateMachine& that_; | |
57 | |
58 public: | |
59 State(LoaderStateMachine& that) : | |
60 that_(that) | |
61 { | |
62 } | |
63 | |
64 State(const State& currentState) : | |
65 that_(currentState.that_) | |
66 { | |
67 } | |
68 | |
1225
16738485e457
deprecating DicomStructureSetLoader, OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
69 void Schedule(OrthancStone::OracleCommandBase* command) const |
815 | 70 { |
71 that_.Schedule(command); | |
72 } | |
73 | |
74 template <typename T> | |
75 T& GetLoader() const | |
76 { | |
77 return dynamic_cast<T&>(that_); | |
78 } | |
79 | |
1225
16738485e457
deprecating DicomStructureSetLoader, OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
80 virtual void Handle(const OrthancStone::OrthancRestApiCommand::SuccessMessage& message); |
815 | 81 |
1225
16738485e457
deprecating DicomStructureSetLoader, OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
82 virtual void Handle(const OrthancStone::GetOrthancImageCommand::SuccessMessage& message); |
815 | 83 |
1225
16738485e457
deprecating DicomStructureSetLoader, OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
84 virtual void Handle(const OrthancStone::GetOrthancWebViewerJpegCommand::SuccessMessage& message); |
815 | 85 }; |
86 | |
1225
16738485e457
deprecating DicomStructureSetLoader, OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
87 void Schedule(OrthancStone::OracleCommandBase* command); |
815 | 88 |
89 void Start(); | |
90 | |
91 private: | |
92 void Step(); | |
93 | |
94 void Clear(); | |
95 | |
1225
16738485e457
deprecating DicomStructureSetLoader, OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
96 void HandleExceptionMessage(const OrthancStone::OracleCommandExceptionMessage& message); |
815 | 97 |
98 template <typename T> | |
99 void HandleSuccessMessage(const T& message); | |
100 | |
1225
16738485e457
deprecating DicomStructureSetLoader, OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
101 typedef std::list<OrthancStone::IOracleCommand*> PendingCommands; |
815 | 102 |
1310
9bea7e15b519
- first pass at changes to cope with the refactoring of the loading system
Benjamin Golinvaux <bgo@osimis.io>
parents:
1279
diff
changeset
|
103 OrthancStone::ILoadersContext& loadersContext_; |
9bea7e15b519
- first pass at changes to cope with the refactoring of the loading system
Benjamin Golinvaux <bgo@osimis.io>
parents:
1279
diff
changeset
|
104 bool active_; |
9bea7e15b519
- first pass at changes to cope with the refactoring of the loading system
Benjamin Golinvaux <bgo@osimis.io>
parents:
1279
diff
changeset
|
105 unsigned int simultaneousDownloads_; |
9bea7e15b519
- first pass at changes to cope with the refactoring of the loading system
Benjamin Golinvaux <bgo@osimis.io>
parents:
1279
diff
changeset
|
106 PendingCommands pendingCommands_; |
9bea7e15b519
- first pass at changes to cope with the refactoring of the loading system
Benjamin Golinvaux <bgo@osimis.io>
parents:
1279
diff
changeset
|
107 unsigned int activeCommands_; |
815 | 108 |
1314
9b126de2cde2
Since the observer system now uses shared_ptr and many registrations are
Benjamin Golinvaux <bgo@osimis.io>
parents:
1310
diff
changeset
|
109 |
815 | 110 public: |
1310
9bea7e15b519
- first pass at changes to cope with the refactoring of the loading system
Benjamin Golinvaux <bgo@osimis.io>
parents:
1279
diff
changeset
|
111 LoaderStateMachine(OrthancStone::ILoadersContext& loadersContext); |
815 | 112 |
1314
9b126de2cde2
Since the observer system now uses shared_ptr and many registrations are
Benjamin Golinvaux <bgo@osimis.io>
parents:
1310
diff
changeset
|
113 void PostConstructor(); |
9b126de2cde2
Since the observer system now uses shared_ptr and many registrations are
Benjamin Golinvaux <bgo@osimis.io>
parents:
1310
diff
changeset
|
114 |
973
38409549db43
Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
815
diff
changeset
|
115 virtual ~LoaderStateMachine(); |
815 | 116 |
117 bool IsActive() const | |
118 { | |
119 return active_; | |
120 } | |
121 | |
122 void SetSimultaneousDownloads(unsigned int count); | |
123 }; | |
124 } |