Mercurial > hg > orthanc-stone
comparison Framework/Loaders/LoaderStateMachine.h @ 1381:f4a06ad1580b
Branch broker is now the new default
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Wed, 22 Apr 2020 14:05:47 +0200 |
parents | 2d8ab34c8c91 556b4bc19118 |
children | 30deba7bc8e2 |
comparison
equal
deleted
inserted
replaced
1375:4431ffdcc2a4 | 1381:f4a06ad1580b |
---|---|
20 | 20 |
21 | 21 |
22 #pragma once | 22 #pragma once |
23 | 23 |
24 #include "../Messages/IObservable.h" | 24 #include "../Messages/IObservable.h" |
25 #include "../Messages/IObserver.h" | 25 #include "../Messages/ObserverBase.h" |
26 #include "../Oracle/GetOrthancImageCommand.h" | 26 #include "../Oracle/GetOrthancImageCommand.h" |
27 #include "../Oracle/GetOrthancWebViewerJpegCommand.h" | 27 #include "../Oracle/GetOrthancWebViewerJpegCommand.h" |
28 #include "../Oracle/IOracle.h" | 28 #include "../Oracle/IOracle.h" |
29 #include "../Oracle/OracleCommandExceptionMessage.h" | 29 #include "../Oracle/OracleCommandExceptionMessage.h" |
30 #include "../Oracle/OrthancRestApiCommand.h" | 30 #include "../Oracle/OrthancRestApiCommand.h" |
33 | 33 |
34 #include <list> | 34 #include <list> |
35 | 35 |
36 namespace OrthancStone | 36 namespace OrthancStone |
37 { | 37 { |
38 class ILoadersContext; | |
39 | |
38 /** | 40 /** |
39 This class is supplied with Oracle commands and will schedule up to | 41 This class is supplied with Oracle commands and will schedule up to |
40 simultaneousDownloads_ of them at the same time, then will schedule the | 42 simultaneousDownloads_ of them at the same time, then will schedule the |
41 rest once slots become available. It is used, a.o., by the | 43 rest once slots become available. It is used, a.o., by the |
42 OrtancMultiframeVolumeLoader class. | 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. | |
43 */ | 50 */ |
44 class LoaderStateMachine : public IObserver | 51 |
52 class LoaderStateMachine : public OrthancStone::ObserverBase<LoaderStateMachine> | |
45 { | 53 { |
46 protected: | 54 public: |
47 class State : public Orthanc::IDynamicObject | 55 class State : public Orthanc::IDynamicObject |
48 { | 56 { |
49 private: | 57 private: |
50 LoaderStateMachine& that_; | 58 LoaderStateMachine& that_; |
51 | 59 |
58 State(const State& currentState) : | 66 State(const State& currentState) : |
59 that_(currentState.that_) | 67 that_(currentState.that_) |
60 { | 68 { |
61 } | 69 } |
62 | 70 |
63 void Schedule(OracleCommandWithPayload* command) const | 71 void Schedule(OrthancStone::OracleCommandBase* command) const |
64 { | 72 { |
65 that_.Schedule(command); | 73 that_.Schedule(command); |
66 } | 74 } |
67 | 75 |
68 template <typename T> | 76 template <typename T> |
69 T& GetLoader() const | 77 T& GetLoader() const |
70 { | 78 { |
71 return dynamic_cast<T&>(that_); | 79 return dynamic_cast<T&>(that_); |
72 } | 80 } |
73 | 81 |
74 virtual void Handle(const OrthancRestApiCommand::SuccessMessage& message); | 82 virtual void Handle(const OrthancStone::OrthancRestApiCommand::SuccessMessage& message); |
75 | 83 |
76 virtual void Handle(const GetOrthancImageCommand::SuccessMessage& message); | 84 virtual void Handle(const OrthancStone::GetOrthancImageCommand::SuccessMessage& message); |
77 | 85 |
78 virtual void Handle(const GetOrthancWebViewerJpegCommand::SuccessMessage& message); | 86 virtual void Handle(const OrthancStone::GetOrthancWebViewerJpegCommand::SuccessMessage& message); |
79 }; | 87 }; |
80 | 88 |
81 void Schedule(OracleCommandWithPayload* command); | 89 void Schedule(OrthancStone::OracleCommandBase* command); |
82 | 90 |
83 void Start(); | 91 void Start(); |
84 | 92 |
85 private: | 93 private: |
86 void Step(); | 94 void Step(); |
87 | 95 |
88 void Clear(); | 96 void Clear(); |
89 | 97 |
90 void HandleExceptionMessage(const OracleCommandExceptionMessage& message); | 98 void HandleExceptionMessage(const OrthancStone::OracleCommandExceptionMessage& message); |
91 | 99 |
92 template <typename T> | 100 template <typename T> |
93 void HandleSuccessMessage(const T& message); | 101 void HandleSuccessMessage(const T& message); |
94 | 102 |
95 typedef std::list<IOracleCommand*> PendingCommands; | 103 typedef std::list<OrthancStone::IOracleCommand*> PendingCommands; |
96 | 104 |
97 IOracle& oracle_; | 105 OrthancStone::ILoadersContext& loadersContext_; |
98 IObservable& oracleObservable_; | 106 bool active_; |
99 bool active_; | 107 unsigned int simultaneousDownloads_; |
100 unsigned int simultaneousDownloads_; | 108 PendingCommands pendingCommands_; |
101 PendingCommands pendingCommands_; | 109 unsigned int activeCommands_; |
102 unsigned int activeCommands_; | 110 |
103 | 111 |
104 public: | 112 public: |
105 LoaderStateMachine(IOracle& oracle, | 113 LoaderStateMachine(OrthancStone::ILoadersContext& loadersContext); |
106 IObservable& oracleObservable); | 114 |
115 void PostConstructor(); | |
107 | 116 |
108 virtual ~LoaderStateMachine(); | 117 virtual ~LoaderStateMachine(); |
109 | 118 |
110 bool IsActive() const | 119 bool IsActive() const |
111 { | 120 { |