Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Loaders/LoaderStateMachine.cpp @ 1640:52b8b96cb55f
cleaning namespaces
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 10 Nov 2020 16:55:22 +0100 |
parents | 8563ea5d8ae4 |
children | 9ac2a65d4172 |
comparison
equal
deleted
inserted
replaced
1639:5cdc5b98f14d | 1640:52b8b96cb55f |
---|---|
26 | 26 |
27 #include <OrthancException.h> | 27 #include <OrthancException.h> |
28 | 28 |
29 namespace OrthancStone | 29 namespace OrthancStone |
30 { | 30 { |
31 void LoaderStateMachine::State::Handle(const OrthancStone::OrthancRestApiCommand::SuccessMessage& message) | 31 void LoaderStateMachine::State::Handle(const OrthancRestApiCommand::SuccessMessage& message) |
32 { | 32 { |
33 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | 33 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
34 } | 34 } |
35 | 35 |
36 | 36 |
37 void LoaderStateMachine::State::Handle(const OrthancStone::GetOrthancImageCommand::SuccessMessage& message) | 37 void LoaderStateMachine::State::Handle(const GetOrthancImageCommand::SuccessMessage& message) |
38 { | 38 { |
39 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | 39 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
40 } | 40 } |
41 | 41 |
42 | 42 |
43 void LoaderStateMachine::State::Handle(const OrthancStone::GetOrthancWebViewerJpegCommand::SuccessMessage& message) | 43 void LoaderStateMachine::State::Handle(const GetOrthancWebViewerJpegCommand::SuccessMessage& message) |
44 { | 44 { |
45 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | 45 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
46 } | 46 } |
47 | 47 |
48 | 48 |
49 void LoaderStateMachine::Schedule(OrthancStone::OracleCommandBase* command) | 49 void LoaderStateMachine::Schedule(OracleCommandBase* command) |
50 { | 50 { |
51 LOG(TRACE) << "LoaderStateMachine(" << std::hex << this << std::dec << ")::Schedule()"; | 51 LOG(TRACE) << "LoaderStateMachine(" << std::hex << this << std::dec << ")::Schedule()"; |
52 | 52 |
53 std::unique_ptr<OrthancStone::OracleCommandBase> protection(command); | 53 std::unique_ptr<OracleCommandBase> protection(command); |
54 | 54 |
55 if (command == NULL) | 55 if (command == NULL) |
56 { | 56 { |
57 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | 57 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
58 } | 58 } |
91 { | 91 { |
92 if (!pendingCommands_.empty() && | 92 if (!pendingCommands_.empty() && |
93 activeCommands_ < simultaneousDownloads_) | 93 activeCommands_ < simultaneousDownloads_) |
94 { | 94 { |
95 | 95 |
96 OrthancStone::IOracleCommand* nextCommand = pendingCommands_.front(); | 96 IOracleCommand* nextCommand = pendingCommands_.front(); |
97 | 97 |
98 LOG(TRACE) << " LoaderStateMachine(" << std::hex << this << std::dec << | 98 LOG(TRACE) << " LoaderStateMachine(" << std::hex << this << std::dec << |
99 ")::Step(): activeCommands_ (" << activeCommands_ << | 99 ")::Step(): activeCommands_ (" << activeCommands_ << |
100 ") < simultaneousDownloads_ (" << simultaneousDownloads_ << | 100 ") < simultaneousDownloads_ (" << simultaneousDownloads_ << |
101 ") --> will Schedule command addr " << std::hex << nextCommand << std::dec; | 101 ") --> will Schedule command addr " << std::hex << nextCommand << std::dec; |
102 | 102 |
103 { | 103 { |
104 std::unique_ptr<OrthancStone::ILoadersContext::ILock> lock(loadersContext_.Lock()); | 104 std::unique_ptr<ILoadersContext::ILock> lock(loadersContext_.Lock()); |
105 boost::shared_ptr<IObserver> observer(GetSharedObserver()); | 105 boost::shared_ptr<IObserver> observer(GetSharedObserver()); |
106 lock->Schedule(observer, 0, nextCommand); // TODO: priority! | 106 lock->Schedule(observer, 0, nextCommand); // TODO: priority! |
107 } | 107 } |
108 pendingCommands_.pop_front(); | 108 pendingCommands_.pop_front(); |
109 | 109 |
130 | 130 |
131 pendingCommands_.clear(); | 131 pendingCommands_.clear(); |
132 } | 132 } |
133 | 133 |
134 | 134 |
135 void LoaderStateMachine::HandleExceptionMessage(const OrthancStone::OracleCommandExceptionMessage& message) | 135 void LoaderStateMachine::HandleExceptionMessage(const OracleCommandExceptionMessage& message) |
136 { | 136 { |
137 LOG(ERROR) << "LoaderStateMachine::HandleExceptionMessage: error in the state machine, stopping all processing"; | 137 LOG(ERROR) << "LoaderStateMachine::HandleExceptionMessage: error in the state machine, stopping all processing"; |
138 LOG(ERROR) << "Error: " << message.GetException().What() << " Details: " << | 138 LOG(ERROR) << "Error: " << message.GetException().What() << " Details: " << |
139 message.GetException().GetDetails(); | 139 message.GetException().GetDetails(); |
140 Clear(); | 140 Clear(); |
162 } | 162 } |
163 } | 163 } |
164 | 164 |
165 | 165 |
166 LoaderStateMachine::LoaderStateMachine( | 166 LoaderStateMachine::LoaderStateMachine( |
167 OrthancStone::ILoadersContext& loadersContext) | 167 ILoadersContext& loadersContext) |
168 : loadersContext_(loadersContext) | 168 : loadersContext_(loadersContext) |
169 , active_(false) | 169 , active_(false) |
170 , simultaneousDownloads_(4) | 170 , simultaneousDownloads_(4) |
171 , activeCommands_(0) | 171 , activeCommands_(0) |
172 { | 172 { |
173 using OrthancStone::ILoadersContext; | 173 LOG(TRACE) << "LoaderStateMachine(" << std::hex << this |
174 | 174 << std::dec << ")::LoaderStateMachine()"; |
175 LOG(TRACE) | |
176 << "LoaderStateMachine(" << std::hex << this | |
177 << std::dec << ")::LoaderStateMachine()"; | |
178 } | 175 } |
179 | 176 |
180 void LoaderStateMachine::PostConstructor() | 177 void LoaderStateMachine::PostConstructor() |
181 { | 178 { |
182 std::unique_ptr<OrthancStone::ILoadersContext::ILock> | 179 std::unique_ptr<ILoadersContext::ILock> |
183 lock(loadersContext_.Lock()); | 180 lock(loadersContext_.Lock()); |
184 | 181 |
185 OrthancStone::IObservable& observable = lock->GetOracleObservable(); | 182 IObservable& observable = lock->GetOracleObservable(); |
186 | 183 |
187 // TODO => Move this out of constructor | 184 // TODO => Move this out of constructor |
188 Register<OrthancStone::OrthancRestApiCommand::SuccessMessage>( | 185 Register<OrthancRestApiCommand::SuccessMessage>( |
189 observable, &LoaderStateMachine::HandleSuccessMessage); | 186 observable, &LoaderStateMachine::HandleSuccessMessage); |
190 Register<OrthancStone::GetOrthancImageCommand::SuccessMessage>( | 187 Register<GetOrthancImageCommand::SuccessMessage>( |
191 observable, &LoaderStateMachine::HandleSuccessMessage); | 188 observable, &LoaderStateMachine::HandleSuccessMessage); |
192 Register<OrthancStone::GetOrthancWebViewerJpegCommand::SuccessMessage>( | 189 Register<GetOrthancWebViewerJpegCommand::SuccessMessage>( |
193 observable, &LoaderStateMachine::HandleSuccessMessage); | 190 observable, &LoaderStateMachine::HandleSuccessMessage); |
194 Register<OrthancStone::OracleCommandExceptionMessage>( | 191 Register<OracleCommandExceptionMessage>( |
195 observable, &LoaderStateMachine::HandleExceptionMessage); | 192 observable, &LoaderStateMachine::HandleExceptionMessage); |
196 } | 193 } |
197 | 194 |
198 LoaderStateMachine::~LoaderStateMachine() | 195 LoaderStateMachine::~LoaderStateMachine() |
199 { | 196 { |