Ref T709, settings provider to get settings

* allows to use the provider without and overhead
* single source, can be made threadsafe

Signed-off-by: Klaus Basan <klaus.basan@klausbasan.de>
This commit is contained in:
Klaus Basan
2019-07-30 00:52:46 +02:00
committed by Mat Sutcliffe
parent 7004e85117
commit 006fbc88ae
2 changed files with 28 additions and 0 deletions

View File

@@ -27,5 +27,17 @@ namespace XSwiftBus
// void
}
CSettings ISettingsProvider::getSettings() const
{
std::lock_guard<std::mutex> l(m_settingsMutex);
return m_pluginSettings;
}
void ISettingsProvider::setSettings(const CSettings &settings)
{
std::lock_guard<std::mutex> l(m_settingsMutex);
m_pluginSettings = settings;
}
} // ns

View File

@@ -11,6 +11,7 @@
#include "blackmisc/simulation/settings/xswiftbussettingsqtfree.h"
#include <string>
#include <mutex>
namespace XSwiftBus
{
@@ -30,6 +31,21 @@ namespace XSwiftBus
virtual ~CSettings() {}
};
//! Something owning the settings
class ISettingsProvider
{
public:
//! By value
//! \threadsafe
CSettings getSettings() const;
//! Set settings
//! \threadsafe
void setSettings(const CSettings &settings);
private:
mutable std::mutex m_settingsMutex;
CSettings m_pluginSettings; //!< owner of the settings
};
} // ns