mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
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:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -68,8 +68,7 @@ namespace BlackMisc
|
||||
CDataCacheRevision *m_rev = nullptr;
|
||||
};
|
||||
|
||||
CDataCache::CDataCache() :
|
||||
CValueCache(CValueCache::Distributed)
|
||||
CDataCache::CDataCache()
|
||||
{
|
||||
if (! QDir::root().mkpath(persistentStore()))
|
||||
{
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
CSettingsCache::CSettingsCache() :
|
||||
CValueCache(CValueCache::Distributed)
|
||||
CSettingsCache::CSettingsCache()
|
||||
{}
|
||||
|
||||
CSettingsCache *CSettingsCache::instance()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace BlackMiscTest
|
||||
{ "value4", CVariant::from(4) }
|
||||
};
|
||||
|
||||
CValueCache cache(CValueCache::LocalOnly);
|
||||
CValueCache cache;
|
||||
QVERIFY(cache.getAllValues() == CVariantMap());
|
||||
cache.insertValues({ testData, QDateTime::currentMSecsSinceEpoch() });
|
||||
QVERIFY(cache.getAllValues() == testData);
|
||||
@@ -131,7 +131,7 @@ namespace BlackMiscTest
|
||||
|
||||
void CTestValueCache::localOnly()
|
||||
{
|
||||
CValueCache cache(CValueCache::LocalOnly);
|
||||
CValueCache cache;
|
||||
for (int i = 0; i < 4; ++i) { QTest::ignoreMessage(QtDebugMsg, QRegularExpression("Empty cache value")); }
|
||||
CValueCacheUser user1(&cache);
|
||||
CValueCacheUser user2(&cache);
|
||||
@@ -140,7 +140,7 @@ namespace BlackMiscTest
|
||||
|
||||
void CTestValueCache::localOnlyWithThreads()
|
||||
{
|
||||
CValueCache cache(CValueCache::LocalOnly);
|
||||
CValueCache cache;
|
||||
for (int i = 0; i < 4; ++i) { QTest::ignoreMessage(QtDebugMsg, QRegularExpression("Empty cache value")); }
|
||||
CValueCacheUser user1(&cache);
|
||||
CValueCacheUser user2(&cache);
|
||||
@@ -158,8 +158,8 @@ namespace BlackMiscTest
|
||||
json.insert("processId", otherProcess.getProcessId() + 1);
|
||||
otherProcess.convertFromJson(json);
|
||||
|
||||
CValueCache thisCache(CValueCache::Distributed);
|
||||
CValueCache otherCache(CValueCache::Distributed);
|
||||
CValueCache thisCache;
|
||||
CValueCache otherCache;
|
||||
connect(&thisCache, &CValueCache::valuesChangedByLocal, &thisCache, [ & ](const CValueCachePacket &values)
|
||||
{
|
||||
QMetaObject::invokeMethod(&thisCache, "changeValuesFromRemote", Q_ARG(BlackMisc::CValueCachePacket, values), Q_ARG(BlackMisc::CIdentifier, thisProcess));
|
||||
@@ -191,7 +191,7 @@ namespace BlackMiscTest
|
||||
|
||||
void CTestValueCache::batched()
|
||||
{
|
||||
CValueCache cache(CValueCache::LocalOnly);
|
||||
CValueCache cache;
|
||||
for (int i = 0; i < 4; ++i) { QTest::ignoreMessage(QtDebugMsg, QRegularExpression("Empty cache value")); }
|
||||
CValueCacheUser user1(&cache);
|
||||
CValueCacheUser user2(&cache);
|
||||
@@ -225,7 +225,7 @@ namespace BlackMiscTest
|
||||
{ "value3", CVariant::from(3) }
|
||||
};
|
||||
|
||||
CValueCache cache(CValueCache::LocalOnly);
|
||||
CValueCache cache;
|
||||
cache.loadFromJson(testJson);
|
||||
QVERIFY(cache.getAllValues() == testData);
|
||||
QVERIFY(cache.saveToJson() == testJson);
|
||||
@@ -243,7 +243,7 @@ namespace BlackMiscTest
|
||||
{ "namespace2/aircraft", CVariant::from(aircraft) },
|
||||
{ "namespace2/atcstations", CVariant::from(atcStations) }
|
||||
};
|
||||
CValueCache cache(CValueCache::LocalOnly);
|
||||
CValueCache cache;
|
||||
cache.insertValues({ testData, QDateTime::currentMSecsSinceEpoch() });
|
||||
|
||||
QDir dir(QDir::currentPath() + "/testcache");
|
||||
@@ -257,7 +257,7 @@ namespace BlackMiscTest
|
||||
QCOMPARE(files[0].fileName(), QString("namespace1.json"));
|
||||
QCOMPARE(files[1].fileName(), QString("namespace2.json"));
|
||||
|
||||
CValueCache cache2(CValueCache::LocalOnly);
|
||||
CValueCache cache2;
|
||||
status = cache2.loadFromFiles(dir.absolutePath());
|
||||
QVERIFY(status.isSuccess());
|
||||
QCOMPARE(cache2.getAllValues(), testData);
|
||||
|
||||
Reference in New Issue
Block a user