LiveListenerFactory.h 3.69 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
#ifndef MANTID_API_LIVELISTENERFACTORYIMPL_H_
#define MANTID_API_LIVELISTENERFACTORYIMPL_H_

/* Used to register unit classes into the factory. creates a global object in an
 * anonymous namespace. The object itself does nothing, but the comma operator
 * is used in the call to its constructor to effect a call to the factory's
 * subscribe method.
 *
 * The second operation that this macro performs is to provide the definition
 * of the unitID method for the concrete unit.
 */
12
13
14
15
16
17
#define DECLARE_LISTENER(classname)                                            \
  namespace {                                                                  \
  Mantid::Kernel::RegistrationHelper register_listener_##classname(            \
      ((Mantid::API::LiveListenerFactory::Instance().subscribe<classname>(     \
           #classname)),                                                       \
       0));                                                                    \
18
19
20
21
22
23
24
25
26
27
  }

//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/DllConfig.h"
#include "MantidKernel/DynamicFactory.h"
#include "MantidKernel/SingletonHolder.h"
#include "MantidAPI/ILiveListener.h"

28
29
30
namespace Mantid {
namespace API {
/** The factory for creating instances of ILiveListener implementations.
31

32
33
    Copyright &copy; 2012 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
   National Laboratory & European Spallation Source
34

35
    This file is part of Mantid.
36

37
38
39
40
    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.
41

42
43
44
45
    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.
46

47
48
49
50
51
52
53
54
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
class MANTID_API_DLL LiveListenerFactoryImpl
    : public Kernel::DynamicFactory<ILiveListener> {
public:
  boost::shared_ptr<ILiveListener>
  create(const std::string &instrumentName, bool connect,
55
         const Kernel::IPropertyManager *properties = nullptr) const;
56
57
  LiveListenerFactoryImpl(const LiveListenerFactoryImpl &) = delete;
  LiveListenerFactoryImpl &operator=(const LiveListenerFactoryImpl &) = delete;
58
  bool checkConnection(const std::string &instrumentName) const;
59

60
61
private:
  friend struct Kernel::CreateUsingNew<LiveListenerFactoryImpl>;
62

63
  /// Private constructor for singleton class
64
  LiveListenerFactoryImpl() = default;
65

66
  /// Private destructor
67
  ~LiveListenerFactoryImpl() override = default;
68

69
70
71
72
  // Unhide the base class method to avoid a warning, but make private.
  using Kernel::DynamicFactory<ILiveListener>::create;
  /// Override the DynamicFactory::createUnwrapped() method. We don't want it
  /// used here.
73
  ILiveListener *createUnwrapped(const std::string &className) const override;
74
};
75

76
77
/// Forward declaration of a specialisation of SingletonHolder (needed for
/// dllexport/dllimport).
78
#ifdef _WIN32
79
80
// this breaks new namespace declaration rules; need to find a better fix
template class MANTID_API_DLL Kernel::SingletonHolder<LiveListenerFactoryImpl>;
81
#endif /* _WIN32 */
82
83
84
/// The specialisation of the SingletonHolder class that holds the
/// LiveListenerFactory
typedef Kernel::SingletonHolder<LiveListenerFactoryImpl> LiveListenerFactory;
85

86
} // namespace API
87
88
} // namespace Mantid

89
#endif /* MANTID_API_LIVELISTENERFACTORYIMPL_H_ */