Newer
Older
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2007 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source
// & Institut Laue - Langevin
// SPDX - License - Identifier: GPL - 3.0 +
Peterson, Peter
committed
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
Gigg, Martyn Anthony
committed
#include "MantidAPI/DllConfig.h"
Peterson, Peter
committed
#include "MantidKernel/SingletonHolder.h"
Peterson, Peter
committed
#include <deque>
#include <mutex>
#include <string>
namespace Mantid {
namespace API {
//----------------------------------------------------------------------------
/// Class for when an algorithm is starting asynchronously
class AlgorithmStartingNotification : public Poco::Notification {
public:
AlgorithmStartingNotification(IAlgorithm_sptr alg)
: Poco::Notification(), m_alg(alg) {}
/// Returns the algorithm that is starting
IAlgorithm_sptr getAlgorithm() const { return m_alg; }
private:
IAlgorithm_sptr m_alg; ///< Algorithm
};
//----------------------------------------------------------------------------
/** The AlgorithmManagerImpl class is responsible for controlling algorithm
Peterson, Peter
committed
instances. It incorporates the algorithm factory and initializes algorithms.
*/
class MANTID_API_DLL AlgorithmManagerImpl {
Peterson, Peter
committed
public:
Gigg, Martyn Anthony
committed
/// Creates a managed algorithm with the option of choosing a version
IAlgorithm_sptr create(const std::string &algName, const int &version = -1,
bool makeProxy = true);
Gigg, Martyn Anthony
committed
/// Creates an unmanaged algorithm with the option of choosing a version
boost::shared_ptr<Algorithm> createUnmanaged(const std::string &algName,
const int &version = -1) const;
Peterson, Peter
committed
void setMaxAlgorithms(int n);
Peterson, Peter
committed
IAlgorithm_sptr getAlgorithm(AlgorithmID id) const;
void removeById(AlgorithmID id);
std::vector<IAlgorithm_const_sptr> runningInstances() const;
std::vector<IAlgorithm_const_sptr>
runningInstancesOf(const std::string &algorithmName) const;
Peterson, Peter
committed
/// Sends notifications to observers. Observers can subscribe to
/// notificationCenter
/// using Poco::NotificationCenter::addObserver(...)
Poco::NotificationCenter notificationCenter;
void notifyAlgorithmStarting(AlgorithmID id);
void cancelAll();
Peterson, Peter
committed
private:
friend struct Mantid::Kernel::CreateUsingNew<AlgorithmManagerImpl>;
AlgorithmManagerImpl();
~AlgorithmManagerImpl();
/// Unimplemented copy constructor
AlgorithmManagerImpl(const AlgorithmManagerImpl &);
/// Unimplemented assignment operator
AlgorithmManagerImpl &operator=(const AlgorithmManagerImpl &);
Peterson, Peter
committed
/// Removes any finished algorithms from the list of managed algorithms
size_t removeFinishedAlgorithms();
Peterson, Peter
committed
/// The maximum size of the algorithm store
Peterson, Peter
committed
/// The list of managed algorithms
std::deque<IAlgorithm_sptr>
m_managed_algs; ///< pointers to managed algorithms [policy???]
/// Mutex for modifying/accessing the m_managed_algs member.
mutable std::mutex m_managedMutex;
Peterson, Peter
committed
};
using AlgorithmManager = Mantid::Kernel::SingletonHolder<AlgorithmManagerImpl>;
Peterson, Peter
committed
} // namespace API
Peterson, Peter
committed
namespace Mantid {
namespace Kernel {
EXTERN_MANTID_API template class MANTID_API_DLL
Mantid::Kernel::SingletonHolder<Mantid::API::AlgorithmManagerImpl>;