Skip to content
Snippets Groups Projects
AlgorithmManager.h 4.12 KiB
Newer Older
#ifndef MANTID_API_ALGORITHMMANAGER_H_
#define MANTID_API_ALGORITHMMANAGER_H_

//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include <Poco/NotificationCenter.h>
#include "MantidKernel/SingletonHolder.h"
#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
    instances. It incorporates the algorithm factory and initializes algorithms.

    Copyright &copy; 2007-2013 ISIS Rutherford Appleton Laboratory, NScD Oak
   Ridge National Laboratory & European Spallation Source
    This file is part of Mantid.

    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>.
    Code Documentation is available at: <http://doxygen.mantidproject.org>
 */
class MANTID_API_DLL AlgorithmManagerImpl {
  /// 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);
  /// 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;
  std::size_t size() const;
  void setMaxAlgorithms(int n);
  IAlgorithm_sptr getAlgorithm(AlgorithmID id) const;
  IAlgorithm_sptr newestInstanceOf(const std::string &algorithmName) const;
  std::vector<IAlgorithm_const_sptr>
  runningInstancesOf(const std::string &algorithmName) const;
  /// Sends notifications to observers. Observers can subscribe to
  /// notificationCenter
  /// using Poco::NotificationCenter::addObserver(...)
  Poco::NotificationCenter notificationCenter;
  void notifyAlgorithmStarting(AlgorithmID id);

  void clear();
Nick Draper's avatar
Nick Draper committed
  void shutdown();
private:
  friend struct Mantid::Kernel::CreateUsingNew<AlgorithmManagerImpl>;

  AlgorithmManagerImpl();
  ~AlgorithmManagerImpl();

  /// Unimplemented copy constructor
  AlgorithmManagerImpl(const AlgorithmManagerImpl &);
  /// Unimplemented assignment operator
  AlgorithmManagerImpl &operator=(const AlgorithmManagerImpl &);
  int m_max_no_algs;
  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;
};

typedef Mantid::Kernel::SingletonHolder<AlgorithmManagerImpl> AlgorithmManager;

} // namespace API
} // Namespace Mantid
namespace Mantid {
namespace Kernel {
EXTERN_MANTID_API template class MANTID_API_DLL
    Mantid::Kernel::SingletonHolder<Mantid::API::AlgorithmManagerImpl>;
#endif /* MANTID_API_ALGORITHMMANAGER_H_ */