Newer
Older
Peterson, Peter
committed
#ifndef MANTID_API_ALGORITHMMANAGER_H_
#define MANTID_API_ALGORITHMMANAGER_H_
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
Gigg, Martyn Anthony
committed
#include "MantidAPI/DllConfig.h"
Peterson, Peter
committed
#include "MantidKernel/SingletonHolder.h"
Russell Taylor
committed
#include "MantidAPI/Algorithm.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.
Copyright © 2007-2013 ISIS Rutherford Appleton Laboratory, NScD Oak
Ridge National Laboratory & European Spallation Source
Peterson, Peter
committed
Peterson, Peter
committed
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>.
Peterson, Peter
committed
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
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);
IAlgorithm_sptr newestInstanceOf(const std::string &algorithmName) 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
/// 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
};
typedef Mantid::Kernel::SingletonHolder<AlgorithmManagerImpl> AlgorithmManager;
} // namespace API
Peterson, Peter
committed
namespace Mantid {
namespace Kernel {
EXTERN_MANTID_API template class MANTID_API_DLL
Mantid::Kernel::SingletonHolder<Mantid::API::AlgorithmManagerImpl>;
Peterson, Peter
committed
#endif /* MANTID_API_ALGORITHMMANAGER_H_ */