Mantid
Loading...
Searching...
No Matches
ConfigService.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9//----------------------------------------------------------------------
10// Includes
11//----------------------------------------------------------------------
12#include "MantidKernel/DllConfig.h"
15#include <boost/optional/optional.hpp>
16
17#include <map>
18#include <set>
19#include <string>
20#include <vector>
21
22#include <Poco/Notification.h>
23#include <Poco/NotificationCenter.h>
24
25//----------------------------------------------------------------------
26// Forward declarations
27//----------------------------------------------------------------------
29namespace Poco {
30class AbstractObserver;
31class Channel;
32template <class C> class AutoPtr;
33namespace Util {
34class PropertyFileConfiguration;
35class SystemConfiguration;
36} // namespace Util
37} // namespace Poco
39
40namespace Mantid {
41
43MANTID_KERNEL_DLL std::string welcomeMessage();
44
45namespace Kernel {
46//----------------------------------------------------------------------
47// More forward declarations
48//----------------------------------------------------------------------
49class FacilityInfo;
50class InstrumentInfo;
51
63class MANTID_KERNEL_DLL ConfigServiceImpl final {
64public:
70 class ConfigServiceNotification : public Poco::Notification {
71 public:
73 ConfigServiceNotification() : Poco::Notification() {}
74 };
75
82 public:
88 ValueChanged(const std::string &name, const std::string &newvalue, const std::string &prevvalue)
89 : ConfigServiceNotification(), m_name(name), m_value(newvalue), m_prev(prevvalue) {}
92 const std::string &key() const { return this->m_name; }
94 const std::string &curValue() const { return this->m_value; }
96 const std::string &preValue() const { return this->m_prev; }
97 private:
98 std::string m_name;
99 std::string m_value;
100 std::string m_prev;
101 };
102
104 void setBaseDirectory();
106 void reset();
108 void updateConfig(const std::string &filename, const bool append = false, const bool update_caches = true);
110 void saveConfig(const std::string &filename) const;
112 std::string getString(const std::string &keyName, bool pathAbsolute = true) const;
114 std::vector<std::string> getKeys(const std::string &keyName) const;
116 std::vector<std::string> keys() const;
118 void remove(const std::string &rootName);
120 bool hasProperty(const std::string &rootName) const;
122 bool isExecutable(const std::string &target) const;
124 void launchProcess(const std::string &programFilePath, const std::vector<std::string> &programArguments) const;
126 void setString(const std::string &key, const std::string &value);
127 // Searches for a configuration property and returns its value
128 template <typename T> boost::optional<T> getValue(const std::string &keyName);
130 std::string getLocalFilename() const;
132 std::string getUserFilename() const;
133
137 std::string getEnvironment(const std::string &keyName);
139 std::string getOSName();
141 std::string getComputerName();
143 std::string getOSArchitecture();
145 std::string getOSVersion();
147 std::string getOSVersionReadable();
149 std::string getUsername();
151 std::string getCurrentDir();
153 std::string getCurrentDir() const;
155 std::string getTempDir();
157 std::string getAppDataDir();
158 // Return the executable path
159 std::string getDirectoryOfExecutable() const;
160 // Return the full path to the executable
161 std::string getPathToExecutable() const;
162 // Check if the path is on a network drive
163 bool isNetworkDrive([[maybe_unused]] const std::string &path);
165
167 std::string getPropertiesDir() const;
170 std::string getUserPropertiesDir() const;
171
175 const std::vector<std::string> &getDataSearchDirs() const;
177 void setDataSearchDirs(const std::vector<std::string> &searchDirs);
179 void setDataSearchDirs(const std::string &searchDirs);
181 void appendDataSearchDir(const std::string &path);
183 void appendDataSearchSubDir(const std::string &subdir);
185 void setInstrumentDirectories(const std::vector<std::string> &directories);
187 const std::vector<std::string> &getInstrumentDirectories() const;
189 const std::string getInstrumentDirectory() const;
191 const std::string getVTPFileDirectory();
193
195 void updateFacilities(const std::string &fName = "");
197 const std::vector<FacilityInfo *> getFacilities() const;
199 const std::vector<std::string> getFacilityNames() const;
201 const FacilityInfo &getFacility() const;
203 const FacilityInfo &getFacility(const std::string &facilityName) const;
205 void setFacility(const std::string &facilityName);
207 void setLogLevel(int logLevel, bool quiet = false);
208
210 const InstrumentInfo &getInstrument(const std::string &instrumentName = "") const;
211
213 void addObserver(const Poco::AbstractObserver &observer) const;
214
216 void removeObserver(const Poco::AbstractObserver &observer) const;
217
218 // Starts up the logging
219 void configureLogging();
220
222 Kernel::ProxyInfo &getProxy(const std::string &url);
223
224 std::string getFullPath(const std::string &filename, const bool ignoreDirs, const int options) const;
225
226private:
229 mutable Poco::NotificationCenter m_notificationCenter;
230
231 // Private constructors and destructor for singleton class
235
236 virtual ~ConfigServiceImpl();
237
239 void loadConfig(const std::string &filename, const bool append = false);
241 bool readFile(const std::string &filename, std::string &contents) const;
242
244 void createUserPropertiesFile() const;
246 std::string makeAbsolute(const std::string &dir, const std::string &key) const;
248 void cacheDataSearchPaths();
250 void cacheInstrumentPaths();
252 bool isInDataSearchList(const std::string &path) const;
255 void clearFacilities();
257 const std::vector<std::string> getFacilityFilenames(const std::string &fName);
260 bool addDirectoryifExists(const std::string &directoryName, std::vector<std::string> &directoryList);
262 void getKeysRecursive(const std::string &root, std::vector<std::string> &allKeys) const;
263
265 Poco::AutoPtr<Poco::Util::PropertyFileConfiguration> m_pConf;
267 Poco::AutoPtr<Poco::Util::SystemConfiguration> m_pSysConfig;
268
270 mutable std::set<std::string> m_changed_keys;
271
273 std::string m_strBaseDir;
275 std::string m_propertyString;
277 const std::string m_properties_file_name;
281 std::vector<std::string> m_dataSearchDirs;
283 std::vector<std::string> m_instrumentDirs;
284
286 std::vector<FacilityInfo *> m_facilities;
287
289 std::set<std::string> m_configPaths;
290
295};
296
297EXTERN_MANTID_KERNEL template class MANTID_KERNEL_DLL Mantid::Kernel::SingletonHolder<ConfigServiceImpl>;
299
301using ConfigValChangeNotification_ptr = const Poco::AutoPtr<Mantid::Kernel::ConfigServiceImpl::ValueChanged> &;
302
303} // namespace Kernel
304} // namespace Mantid
const std::string & m_value
Definition: Algorithm.cpp:71
double value
The value of the point.
Definition: FitMW.cpp:51
This is the base class for POCO Notifications sent out from the Config Service.
Definition: ConfigService.h:70
ConfigServiceNotification()
Empty constructor for ConfigServiceNotification Base Class.
Definition: ConfigService.h:73
This is the class for the notification that is to be sent when a value has been changed in config ser...
Definition: ConfigService.h:81
std::string m_name
The name of the changed the property.
Definition: ConfigService.h:98
ValueChanged(const std::string &name, const std::string &newvalue, const std::string &prevvalue)
Creates the Notification object with the required values.
Definition: ConfigService.h:88
std::string m_prev
The previous value for the property.
std::string m_value
The new value for the property.
Definition: ConfigService.h:99
const std::string & curValue() const
The new value for the property.
Definition: ConfigService.h:94
const std::string & key() const
The name of the user property that has changed, as it appears in the user.properties file.
Definition: ConfigService.h:92
const std::string & preValue() const
The previous value for the property.
Definition: ConfigService.h:96
The ConfigService class provides a simple facade to access the Configuration functionality of the Man...
Definition: ConfigService.h:63
std::string m_propertyString
The configuration properties in string format.
const std::string m_properties_file_name
The filename of the Mantid properties file.
std::set< std::string > m_configPaths
List of config paths that may be relative.
std::string m_strBaseDir
The directory that is considered to be the base directory.
std::set< std::string > m_changed_keys
A set of property keys that have been changed.
std::vector< std::string > m_dataSearchDirs
Store a list of data search paths.
ConfigServiceImpl(const ConfigServiceImpl &)
Private copy constructor. Prevents singleton being copied.
Poco::AutoPtr< Poco::Util::SystemConfiguration > m_pSysConfig
the POCO system Config Object
bool m_isProxySet
whether the proxy has been populated yet
Poco::NotificationCenter m_notificationCenter
Handles distribution of Poco signals.
Kernel::ProxyInfo m_proxyInfo
local cache of proxy details
const std::string m_user_properties_file_name
The filename of the Mantid user properties file.
Poco::AutoPtr< Poco::Util::PropertyFileConfiguration > m_pConf
the POCO file config object
std::vector< FacilityInfo * > m_facilities
The list of available facilities.
std::vector< std::string > m_instrumentDirs
Store a list of instrument directory paths.
A class that holds information about a facility.
Definition: FacilityInfo.h:36
A class that holds information about an instrument.
ProxyInfo : Container for carrying around network proxy information.
Definition: ProxyInfo.h:17
Manage the lifetime of a class intended to be a singleton.
const Poco::AutoPtr< Mantid::Kernel::ConfigServiceImpl::ValueChanged > & ConfigValChangeNotification_ptr
Helper class which provides the Collimation Length for SANS instruments.
MANTID_KERNEL_DLL std::string welcomeMessage()
Returns the welcome message for Mantid.
Definition: Algorithm.h:30
Policy class controlling creation of the singleton Implementation classes should mark their default c...