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 +
10
11#include <boost/python/class.hpp>
12#include <boost/python/register_ptr_to_python.hpp>
13
14using namespace Mantid::API;
15using namespace Mantid::PythonInterface;
16using namespace boost::python;
17
18GNU_DIAG_OFF("dangling-reference")
19
20void observeFinish(AlgorithmObserver &self, const boost::python::object &alg) {
21 const IAlgorithm_sptr &calg = boost::python::extract<IAlgorithm_sptr &>(alg);
22 self.observeFinish(calg);
23}
24
25void observeError(AlgorithmObserver &self, const boost::python::object &alg) {
26 const IAlgorithm_sptr &calg = boost::python::extract<IAlgorithm_sptr &>(alg);
27 self.observeError(calg);
28}
29
30void observeProgress(AlgorithmObserver &self, const boost::python::object &alg) {
31 const IAlgorithm_sptr &calg = boost::python::extract<IAlgorithm_sptr &>(alg);
32 self.observeProgress(calg);
33}
34
35void stopObserving(AlgorithmObserver &self, const boost::python::object &alg) {
36 const IAlgorithm_sptr &calg = boost::python::extract<IAlgorithm_sptr &>(alg);
37 self.stopObserving(calg);
38}
39
41
43
44 register_ptr_to_python<std::shared_ptr<AlgorithmObserver>>();
45
46 class_<AlgorithmObserver, bases<>, std::shared_ptr<AlgorithmObserverAdapter>, boost::noncopyable>(
47 "AlgorithmObserver", "Observes Algorithm notifications: start,progress,finish,error.")
48 .def("observeStarting", &AlgorithmObserver::observeStarting, arg("self"),
49 "Observe the AlgorithmManager for starting algorithms.")
50 .def("observeFinish", &observeFinish, (arg("self"), arg("alg")), "Observe algorithm for its finish notification.")
51 .def("observeError", &observeError, (arg("self"), arg("alg")), "Observe algorithm for its error notification.")
52 .def("observeProgress", &observeProgress, (arg("self"), arg("alg")),
53 "Observe algorithm for its progress notification.")
54 .def("stopObserving", &stopObserving, (arg("self"), arg("alg")), "Remove all observers from the algorithm.");
55}
#define GET_POINTER_SPECIALIZATION(TYPE)
Definition GetPointer.h:17
void stopObserving(AlgorithmObserver &self, const boost::python::object &alg)
void observeProgress(AlgorithmObserver &self, const boost::python::object &alg)
void observeFinish(AlgorithmObserver &self, const boost::python::object &alg)
void export_algorithm_observer()
void observeError(AlgorithmObserver &self, const boost::python::object &alg)
#define GNU_DIAG_OFF(x)
This is a collection of macros for turning compiler warnings off in a controlled manner.
Observes Algorithm notifications: start,progress,finish,error.
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.
void stopObserving(const IAlgorithm_const_sptr &alg)
Disconnect from algorithm alg.
void observeError(const IAlgorithm_const_sptr &alg)
Connect to algorithm alg and observe its error notification.
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm