Mantid
Loading...
Searching...
No Matches
AlgorithmObserver.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
10#include <utility>
11
14
15namespace Mantid::API {
16
20 : m_progressObserver(*this, &AlgorithmObserver::_progressHandle),
21 m_startObserver(*this, &AlgorithmObserver::_startHandle),
22 m_finishObserver(*this, &AlgorithmObserver::_finishHandle),
23 m_errorObserver(*this, &AlgorithmObserver::_errorHandle),
24 m_startingObserver(*this, &AlgorithmObserver::_startingHandle) {}
25
31 : m_progressObserver(*this, &AlgorithmObserver::_progressHandle),
32 m_startObserver(*this, &AlgorithmObserver::_startHandle),
33 m_finishObserver(*this, &AlgorithmObserver::_finishHandle),
34 m_errorObserver(*this, &AlgorithmObserver::_errorHandle),
35 m_startingObserver(*this, &AlgorithmObserver::_startingHandle) {
36 observeAll(alg);
37}
38
41
46 alg->addObserver(m_progressObserver);
47 alg->addObserver(m_startObserver);
48 alg->addObserver(m_finishObserver);
49 alg->addObserver(m_errorObserver);
50}
51
56
60 AlgorithmManager::Instance().notificationCenter.addObserver(m_startingObserver);
61}
62
67
72
77
83
89}
90
95 AlgorithmManager::Instance().notificationCenter.removeObserver(m_startingObserver);
96}
97
99
109void AlgorithmObserver::progressHandle(const IAlgorithm *alg, double p, const std::string &msg,
110 const double estimatedTime, const int progressPrecision) {
111 UNUSED_ARG(alg)
112 UNUSED_ARG(p)
113 UNUSED_ARG(msg)
114 UNUSED_ARG(estimatedTime)
115 UNUSED_ARG(progressPrecision)
116}
117
123
128void AlgorithmObserver::startHandle(const IAlgorithm *alg) { UNUSED_ARG(alg) }
129
134void AlgorithmObserver::finishHandle(const IAlgorithm *alg) { UNUSED_ARG(alg) }
135
141void AlgorithmObserver::errorHandle(const IAlgorithm *alg, const std::string &what) {
142 UNUSED_ARG(alg)
143 UNUSED_ARG(what)
144}
146
150void AlgorithmObserver::_progressHandle(const Poco::AutoPtr<Algorithm::ProgressNotification> &pNf) {
151 this->progressHandle(pNf->algorithm(), pNf->progress, pNf->message, pNf->estimatedTime, pNf->progressPrecision);
152}
153
157void AlgorithmObserver::_startHandle(const Poco::AutoPtr<Algorithm::StartedNotification> &pNf) {
158 this->startHandle(pNf->algorithm());
159}
160
164void AlgorithmObserver::_finishHandle(const Poco::AutoPtr<Algorithm::FinishedNotification> &pNf) {
165 this->finishHandle(pNf->algorithm());
166}
167
171void AlgorithmObserver::_errorHandle(const Poco::AutoPtr<Algorithm::ErrorNotification> &pNf) {
172 this->errorHandle(pNf->algorithm(), pNf->what);
173}
174
178void AlgorithmObserver::_startingHandle(const Poco::AutoPtr<AlgorithmStartingNotification> &pNf) {
179 this->startingHandle(pNf->getAlgorithm());
180}
181
182} // namespace Mantid::API
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition: System.h:64
Observes Algorithm notifications: start,progress,finish,error.
virtual void startingHandle(IAlgorithm_sptr alg)
void observeStart(const IAlgorithm_const_sptr &alg)
Connect to algorithm alg and observe its start notification.
void _errorHandle(const Poco::AutoPtr< Algorithm::ErrorNotification > &pNf)
Poco notification handler for Algorithm::ErrorNotification.
Poco::NObserver< AlgorithmObserver, AlgorithmStartingNotification > m_startingObserver
Poco::NObserver for API::AlgorithmStartingNotification.
void observeAll(const IAlgorithm_const_sptr &alg)
Connect to algorithm alg and observe all its notifications.
void observeFinish(const IAlgorithm_const_sptr &alg)
Connect to algorithm alg and observe its finish notification.
virtual ~AlgorithmObserver()
Virtual destructor.
AlgorithmObserver()
Default constructor.
void _finishHandle(const Poco::AutoPtr< Algorithm::FinishedNotification > &pNf)
Poco notification handler for Algorithm::FinishedNotification.
virtual void finishHandle(const IAlgorithm *alg)
Poco::NObserver< AlgorithmObserver, Algorithm::ProgressNotification > m_progressObserver
Poco::NObserver for Algorithm::ProgressNotification.
void observeStarting()
Connect to AlgorithmManager and observe its starting notifications.
void observeProgress(const IAlgorithm_const_sptr &alg)
Connect to algorithm alg and observe its progress notification.
virtual void errorHandle(const IAlgorithm *alg, const std::string &what)
virtual void startHandle(const IAlgorithm *alg)
void _startingHandle(const Poco::AutoPtr< AlgorithmStartingNotification > &pNf)
Poco notification handler for API::AlgorithmStartingNotification.
void _startHandle(const Poco::AutoPtr< Algorithm::StartedNotification > &pNf)
Poco notification handler for Algorithm::StartedNotification.
void _progressHandle(const Poco::AutoPtr< Algorithm::ProgressNotification > &pNf)
Poco notification handler for Algorithm::ProgressNotification.
void stopObserving(const IAlgorithm_const_sptr &alg)
Disconnect from algorithm alg.
Poco::NObserver< AlgorithmObserver, Algorithm::StartedNotification > m_startObserver
Poco::NObserver for Algorithm::StartedNotification.
virtual void progressHandle(const IAlgorithm *alg, double p, const std::string &msg, const double estimatedTime, const int progressPrecision)
void observeError(const IAlgorithm_const_sptr &alg)
Connect to algorithm alg and observe its error notification.
Poco::NObserver< AlgorithmObserver, Algorithm::ErrorNotification > m_errorObserver
Poco::NObserver for Algorithm::ErrorNotification.
Poco::NObserver< AlgorithmObserver, Algorithm::FinishedNotification > m_finishObserver
Poco::NObserver for Algorithm::FinishedNotification.
void stopObservingManager()
Disconnect from the algorithm manager.
IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:45
virtual void removeObserver(const Poco::AbstractObserver &observer) const =0
Remove an observer.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
std::shared_ptr< const IAlgorithm > IAlgorithm_const_sptr
shared pointer to Mantid::API::IAlgorithm (const version)