AlgorithmFactoryObserver.h 1.66 KB
Newer Older
1
2
3
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2019 ISIS Rutherford Appleton Laboratory UKRI,
4
5
//   NScD Oak Ridge National Laboratory, European Spallation Source,
//   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6
// SPDX - License - Identifier: GPL - 3.0 +
7
#pragma once
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

#include "MantidAPI/AlgorithmFactory.h"
#include <Poco/NObserver.h>

namespace Mantid {
namespace API {

/*
 * To use the AlgorithmFactoryObserver you will need to do a few things:
 *
 * 1. Inherit from this class in the class you wish to take effect on
 *
 * 2. Make sure that the effect you are attempting to observe has been added
 * to the AlgorithmFactory itself by using the public method in this
 * class, e.g. observeSubscribe
 *
 * 3. The last thing to actually have something take effect is by overriding
 * the relevant handle function e.g. when observing subscriptions override
 * subscribeHandle and anything done in that overridden method will happen
 * every time something is subscribed to AlgorithmFactory.
 *
 * This works in both C++ and Python, some functionality is limited in
 * python, but the handlers will all be called.
 */

class MANTID_API_DLL AlgorithmFactoryObserver {
public:
  AlgorithmFactoryObserver();
  virtual ~AlgorithmFactoryObserver();

  void observeUpdate(bool turnOn = true);

  virtual void updateHandle();

private:
  bool m_observingUpdate{false};

Tom Titcombe's avatar
Tom Titcombe committed
45
  void _updateHandle(AlgorithmFactoryUpdateNotification_ptr pNf);
46
47

  /// Poco::NObserver for SubscribeNotification.
48
  Poco::NObserver<AlgorithmFactoryObserver, AlgorithmFactoryUpdateNotification>
49
50
51
52
53
      m_updateObserver;
};

} // namespace API
} // namespace Mantid