annotate Framework/Deprecated/Loaders/LoaderStateMachine.h @ 1314:9b126de2cde2 broker

Since the observer system now uses shared_ptr and many registrations are done in the constructors, and since we cannot called shared_from_this() in the constructors, it is mandatory to split construction from registration. This has been done by making many ctors protected and replacing them by factory methods that directly return shared_ptrs + added PostConstructor method when base classes perform shared_from_this() calls too.
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 16 Mar 2020 11:19:50 +0100
parents 9bea7e15b519
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #pragma once
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include <Core/IDynamicObject.h>
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include <list>
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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 {
9bea7e15b519 - first pass at changes to cope with the refactoring of the loading system
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
38 class ILoadersContext;
9bea7e15b519 - first pass at changes to cope with the refactoring of the loading system
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
39 }
9bea7e15b519 - first pass at changes to cope with the refactoring of the loading system
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
40
1225
16738485e457 deprecating DicomStructureSetLoader, OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1128
diff changeset
41 namespace Deprecated
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 /**
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 This class is supplied with Oracle commands and will schedule up to
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 simultaneousDownloads_ of them at the same time, then will schedule the
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 rest once slots become available. It is used, a.o., by the
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 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
48
9b126de2cde2 Since the observer system now uses shared_ptr and many registrations are
Benjamin Golinvaux <bgo@osimis.io>
parents: 1310
diff changeset
49 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
50
9b126de2cde2 Since the observer system now uses shared_ptr and many registrations are
Benjamin Golinvaux <bgo@osimis.io>
parents: 1310
diff changeset
51 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
52 an answer is received.
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 */
1314
9b126de2cde2 Since the observer system now uses shared_ptr and many registrations are
Benjamin Golinvaux <bgo@osimis.io>
parents: 1310
diff changeset
54
1225
16738485e457 deprecating DicomStructureSetLoader, OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1128
diff changeset
55 class LoaderStateMachine : public OrthancStone::ObserverBase<LoaderStateMachine>
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
1314
9b126de2cde2 Since the observer system now uses shared_ptr and many registrations are
Benjamin Golinvaux <bgo@osimis.io>
parents: 1310
diff changeset
57 public:
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 class State : public Orthanc::IDynamicObject
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 private:
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 LoaderStateMachine& that_;
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 public:
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 State(LoaderStateMachine& that) :
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 that_(that)
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 }
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 State(const State& currentState) :
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 that_(currentState.that_)
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 }
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
1225
16738485e457 deprecating DicomStructureSetLoader, OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1128
diff changeset
74 void Schedule(OrthancStone::OracleCommandBase* command) const
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 {
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 that_.Schedule(command);
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 }
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 template <typename T>
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 T& GetLoader() const
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 {
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 return dynamic_cast<T&>(that_);
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 }
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
1225
16738485e457 deprecating DicomStructureSetLoader, OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1128
diff changeset
85 virtual void Handle(const OrthancStone::OrthancRestApiCommand::SuccessMessage& message);
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
1225
16738485e457 deprecating DicomStructureSetLoader, OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1128
diff changeset
87 virtual void Handle(const OrthancStone::GetOrthancImageCommand::SuccessMessage& message);
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
1225
16738485e457 deprecating DicomStructureSetLoader, OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1128
diff changeset
89 virtual void Handle(const OrthancStone::GetOrthancWebViewerJpegCommand::SuccessMessage& message);
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 };
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
1225
16738485e457 deprecating DicomStructureSetLoader, OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1128
diff changeset
92 void Schedule(OrthancStone::OracleCommandBase* command);
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 void Start();
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 private:
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 void Step();
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 void Clear();
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
1225
16738485e457 deprecating DicomStructureSetLoader, OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1128
diff changeset
101 void HandleExceptionMessage(const OrthancStone::OracleCommandExceptionMessage& message);
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 template <typename T>
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 void HandleSuccessMessage(const T& message);
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
1225
16738485e457 deprecating DicomStructureSetLoader, OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1128
diff changeset
106 typedef std::list<OrthancStone::IOracleCommand*> PendingCommands;
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
1310
9bea7e15b519 - first pass at changes to cope with the refactoring of the loading system
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
108 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
109 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
110 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
111 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
112 unsigned int activeCommands_;
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
1314
9b126de2cde2 Since the observer system now uses shared_ptr and many registrations are
Benjamin Golinvaux <bgo@osimis.io>
parents: 1310
diff changeset
114
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 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
116 LoaderStateMachine(OrthancStone::ILoadersContext& loadersContext);
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117
1314
9b126de2cde2 Since the observer system now uses shared_ptr and many registrations are
Benjamin Golinvaux <bgo@osimis.io>
parents: 1310
diff changeset
118 void PostConstructor();
9b126de2cde2 Since the observer system now uses shared_ptr and many registrations are
Benjamin Golinvaux <bgo@osimis.io>
parents: 1310
diff changeset
119
973
38409549db43 Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents: 815
diff changeset
120 virtual ~LoaderStateMachine();
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 bool IsActive() const
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 {
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 return active_;
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 }
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 void SetSimultaneousDownloads(unsigned int count);
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 };
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 }