refs #679 CValueCache local signal relay moved to the point of emission, to tolerate different orders of initialization of application.

This commit is contained in:
Mathew Sutcliffe
2016-06-30 02:06:16 +01:00
parent 8b73da6ed6
commit 242e041ceb
6 changed files with 18 additions and 46 deletions

View File

@@ -207,15 +207,6 @@ namespace BlackCore
bool s = this->startHookIn();
// enable local relay of settings changes in case there is no context
if (!this->supportsContexts())
{
connect(CSettingsCache::instance(), &CSettingsCache::valuesChangedByLocal, CSettingsCache::instance(), [](const CValueCachePacket & values)
{
CSettingsCache::instance()->changeValuesFromRemote(values, CIdentifier());
});
}
// trigger loading and saving of settings in appropriate scenarios
if (this->m_coreFacadeConfig.getModeApplication() != CCoreFacadeConfig::Remote)
{

View File

@@ -68,8 +68,7 @@ namespace BlackMisc
CDataCacheRevision *m_rev = nullptr;
};
CDataCache::CDataCache() :
CValueCache(CValueCache::Distributed)
CDataCache::CDataCache()
{
if (! QDir::root().mkpath(persistentStore()))
{

View File

@@ -15,8 +15,7 @@
namespace BlackMisc
{
CSettingsCache::CSettingsCache() :
CValueCache(CValueCache::Distributed)
CSettingsCache::CSettingsCache()
{}
CSettingsCache *CSettingsCache::instance()

View File

@@ -136,18 +136,8 @@ namespace BlackMisc
return cats;
}
CValueCache::CValueCache(CValueCache::DistributionMode mode, QObject *parent) :
QObject(parent)
{
if (mode == LocalOnly)
{
// loopback signal to own slot for local operation
connect(this, &CValueCache::valuesChangedByLocal, this, [ = ](const CValueCachePacket & values)
{
changeValuesFromRemote(values, CIdentifier());
});
}
}
CValueCache::CValueCache(QObject *parent) : QObject(parent)
{}
struct CValueCache::Element
{
@@ -242,8 +232,10 @@ namespace BlackMisc
if (values.valuesChanged()) { emit valuesChanged(values, sender()); }
emit valuesChangedByLocal(values);
Q_ASSERT_X(isSignalConnected(QMetaMethod::fromSignal(&CValueCache::valuesChangedByLocal)), Q_FUNC_INFO,
"signal must be connected for cache to function properly");
if (! isSignalConnected(QMetaMethod::fromSignal(&CValueCache::valuesChangedByLocal)))
{
changeValuesFromRemote(values, CIdentifier());
}
}
void CValueCache::changeValuesFromRemote(const CValueCachePacket &values, const CIdentifier &originator)

View File

@@ -147,20 +147,11 @@ namespace BlackMisc
public:
class BatchGuard;
//! Whether or not the cache can be distributed among multiple processes.
enum DistributionMode
{
LocalOnly, //!< Not distributed.
Distributed //!< Distributed among multiple processes.
};
//! Log categories
static const CLogCategoryList &getLogCategories();
//! Constructor.
//! \param mode Whether or not the cache can be distributed among multiple processes.
//! \param parent The parent of the QObject.
explicit CValueCache(DistributionMode mode, QObject *parent = nullptr);
explicit CValueCache(QObject *parent = nullptr);
//! Return map containing all values in the cache.
//! If prefix is provided then only those values whose keys start with that prefix.