Mercurial > hg > orthanc-stone
diff 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 |
line wrap: on
line diff
--- a/Framework/Loaders/LoaderStateMachine.h Mon Apr 20 18:26:32 2020 +0200 +++ b/Framework/Loaders/LoaderStateMachine.h Wed Apr 22 14:05:47 2020 +0200 @@ -22,7 +22,7 @@ #pragma once #include "../Messages/IObservable.h" -#include "../Messages/IObserver.h" +#include "../Messages/ObserverBase.h" #include "../Oracle/GetOrthancImageCommand.h" #include "../Oracle/GetOrthancWebViewerJpegCommand.h" #include "../Oracle/IOracle.h" @@ -35,15 +35,23 @@ namespace OrthancStone { + class ILoadersContext; + /** This class is supplied with Oracle commands and will schedule up to simultaneousDownloads_ of them at the same time, then will schedule the rest once slots become available. It is used, a.o., by the OrtancMultiframeVolumeLoader class. + + To use it, you need to create commands that derive from State. + + You need to initialize them with the object that must be called when + an answer is received. */ - class LoaderStateMachine : public IObserver + + class LoaderStateMachine : public OrthancStone::ObserverBase<LoaderStateMachine> { - protected: + public: class State : public Orthanc::IDynamicObject { private: @@ -60,7 +68,7 @@ { } - void Schedule(OracleCommandWithPayload* command) const + void Schedule(OrthancStone::OracleCommandBase* command) const { that_.Schedule(command); } @@ -71,14 +79,14 @@ return dynamic_cast<T&>(that_); } - virtual void Handle(const OrthancRestApiCommand::SuccessMessage& message); + virtual void Handle(const OrthancStone::OrthancRestApiCommand::SuccessMessage& message); - virtual void Handle(const GetOrthancImageCommand::SuccessMessage& message); + virtual void Handle(const OrthancStone::GetOrthancImageCommand::SuccessMessage& message); - virtual void Handle(const GetOrthancWebViewerJpegCommand::SuccessMessage& message); + virtual void Handle(const OrthancStone::GetOrthancWebViewerJpegCommand::SuccessMessage& message); }; - void Schedule(OracleCommandWithPayload* command); + void Schedule(OrthancStone::OracleCommandBase* command); void Start(); @@ -87,23 +95,24 @@ void Clear(); - void HandleExceptionMessage(const OracleCommandExceptionMessage& message); + void HandleExceptionMessage(const OrthancStone::OracleCommandExceptionMessage& message); template <typename T> void HandleSuccessMessage(const T& message); - typedef std::list<IOracleCommand*> PendingCommands; + typedef std::list<OrthancStone::IOracleCommand*> PendingCommands; - IOracle& oracle_; - IObservable& oracleObservable_; - bool active_; - unsigned int simultaneousDownloads_; - PendingCommands pendingCommands_; - unsigned int activeCommands_; + OrthancStone::ILoadersContext& loadersContext_; + bool active_; + unsigned int simultaneousDownloads_; + PendingCommands pendingCommands_; + unsigned int activeCommands_; + public: - LoaderStateMachine(IOracle& oracle, - IObservable& oracleObservable); + LoaderStateMachine(OrthancStone::ILoadersContext& loadersContext); + + void PostConstructor(); virtual ~LoaderStateMachine();