mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 16:56:53 +08:00
refs #748, further airport from DB follow up fixes
* Ignore mode, not all applications need to load everything (mapping tool no airports) * removed signal in airport reader which is already in base class * added "virtual" keyword * fixed another syncronize typo * added allDbEntiiesUsed() to also reflect the config (ignore flag) * ensure allSwiftDbData are signaled correctly even with ignore flag
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2015
|
||||
/* Copyright (C) 2016
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2015
|
||||
/* Copyright (C) 2016
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
@@ -30,10 +30,6 @@ namespace BlackCore
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
signals:
|
||||
//! Emitted when data is parsed
|
||||
void dataRead(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState state, int number);
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
CAirportDataReader(QObject* parent, const CDatabaseReaderConfigList &config);
|
||||
@@ -42,21 +38,15 @@ namespace BlackCore
|
||||
//! \threadsafe
|
||||
BlackMisc::Aviation::CAirportList getAirports() const;
|
||||
|
||||
//! \copydoc BlackCore::Db::CDatabaseReader::getCacheTimestamp()
|
||||
QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entities) const override;
|
||||
|
||||
//! \copydoc BlackCore::Db::CDatabaseReader::getCacheCount()
|
||||
int getCacheCount(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
||||
// base class overrides
|
||||
virtual QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entities) const override;
|
||||
virtual int getCacheCount(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
||||
|
||||
protected:
|
||||
//! \copydoc BlackCore::Db::CDatabaseReader::synchronizeCaches()
|
||||
void synchronizeCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
|
||||
|
||||
//! \copydoc BlackCore::Db::CDatabaseReader::invalidateCaches()
|
||||
void invalidateCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
|
||||
|
||||
//! \copydoc BlackCore::Db::CDatabaseReader::hasChangedUrl()
|
||||
bool hasChangedUrl(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
||||
// base class overrides
|
||||
virtual void synchronizeCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
|
||||
virtual void invalidateCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
|
||||
virtual bool hasChangedUrl(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
||||
|
||||
private:
|
||||
//! URL for airport list
|
||||
@@ -80,7 +70,6 @@ namespace BlackCore
|
||||
|
||||
//! Reader URL (we read from where?) used to detect changes of location
|
||||
BlackMisc::CData<BlackCore::Data::TDbModelReaderBaseUrl> m_readerUrlCache {this, &CAirportDataReader::ps_baseUrlCacheChanged };
|
||||
|
||||
};
|
||||
}
|
||||
} // ns
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace BlackCore
|
||||
|
||||
// we accept cached cached data
|
||||
Q_ASSERT_X(!entities.testFlag(CEntityFlags::InfoObjectEntity), Q_FUNC_INFO, "Read info objects directly");
|
||||
const bool hasInfoObjects = this->hasInfoObjects(); // no info objects is no necessarily error, but indicates a) either data not available or b) only caches is used
|
||||
const bool hasInfoObjects = this->hasInfoObjects(); // no info objects is no necessarily error, but indicates a) either data not available (DB down) or b) only caches are used
|
||||
CEntityFlags::Entity allEntities = entities;
|
||||
CEntityFlags::Entity cachedEntities = CEntityFlags::NoEntity;
|
||||
CEntityFlags::Entity currentEntity = CEntityFlags::iterateDbEntities(allEntities); // CEntityFlags::InfoObjectEntity will be ignored
|
||||
@@ -56,7 +56,13 @@ namespace BlackCore
|
||||
{
|
||||
const CDatabaseReaderConfig config(this->getConfigForEntity(currentEntity));
|
||||
const QString currentEntityName = CEntityFlags::flagToString(currentEntity);
|
||||
if (config.getRetrievalMode().testFlag(CDbFlags::Cached))
|
||||
const CDbFlags::DataRetrievalMode rm = config.getRetrievalMode();
|
||||
Q_ASSERT_X(!rm.testFlag(CDbFlags::Unspecified), Q_FUNC_INFO, "Missing retrieval mode");
|
||||
if (rm.testFlag(CDbFlags::Ignore) || rm.testFlag(CDbFlags::Canceled))
|
||||
{
|
||||
entities &= ~currentEntity; // do not load from web database
|
||||
}
|
||||
else if (rm.testFlag(CDbFlags::Cached))
|
||||
{
|
||||
if (hasInfoObjects)
|
||||
{
|
||||
@@ -69,7 +75,7 @@ namespace BlackCore
|
||||
if (!changedUrl && cacheTimestamp >= latestEntityTimestamp && cacheTimestamp >= 0 && latestEntityTimestamp >= 0)
|
||||
{
|
||||
this->synchronizeCaches(currentEntity);
|
||||
entities &= ~currentEntity; // do not load from web
|
||||
entities &= ~currentEntity; // do not load from web database
|
||||
cachedEntities |= currentEntity; // read from cache
|
||||
CLogMessage(this).info("Using cache for %1 (%2, %3)") << currentEntityName << cacheTs.toString() << cacheTimestamp;
|
||||
}
|
||||
@@ -91,7 +97,7 @@ namespace BlackCore
|
||||
this->synchronizeCaches(currentEntity);
|
||||
const int c = this->getCacheCount(currentEntity);
|
||||
CLogMessage(this).info("No info object for %1, using cache with %2 objects") << currentEntityName << c;
|
||||
entities &= ~currentEntity; // do not load from web
|
||||
entities &= ~currentEntity; // do not load from web database
|
||||
cachedEntities |= currentEntity; // read from cache
|
||||
}
|
||||
}
|
||||
@@ -207,6 +213,7 @@ namespace BlackCore
|
||||
|
||||
void CDatabaseReader::emitReadSignalPerSingleCachedEntity(CEntityFlags::Entity cachedEntities)
|
||||
{
|
||||
if (cachedEntities == CEntityFlags::NoEntity) { return; }
|
||||
CEntityFlags::Entity cachedEntitiesToEmit = cachedEntities;
|
||||
CEntityFlags::Entity currentCachedEntity = CEntityFlags::iterateDbEntities(cachedEntitiesToEmit);
|
||||
while (currentCachedEntity)
|
||||
|
||||
@@ -66,6 +66,12 @@ namespace BlackCore
|
||||
return (this->getRetrievalMode().testFlag(CDbFlags::DbDirect) || this->getRetrievalMode().testFlag(CDbFlags::Shared));
|
||||
}
|
||||
|
||||
bool CDatabaseReaderConfig::possiblyReadsFromCache() const
|
||||
{
|
||||
if (!this->isValid()) { return false; }
|
||||
return (this->getRetrievalMode().testFlag(CDbFlags::Cached) || this->getRetrievalMode().testFlag(CDbFlags::CacheThenDb) || this->getRetrievalMode().testFlag(CDbFlags::CacheThenShared));
|
||||
}
|
||||
|
||||
bool CDatabaseReaderConfig::isValid() const
|
||||
{
|
||||
return this->m_entities != BlackMisc::Network::CEntityFlags::NoEntity;
|
||||
@@ -118,6 +124,19 @@ namespace BlackCore
|
||||
return false;
|
||||
}
|
||||
|
||||
CEntityFlags::Entity CDatabaseReaderConfigList::getEntitesCachedOrReadFromDB() const
|
||||
{
|
||||
CEntityFlags::Entity entities = CEntityFlags::NoEntity;
|
||||
for (const CDatabaseReaderConfig &config : *this)
|
||||
{
|
||||
if (config.possiblyReadsFromSwiftDb() || config.possiblyReadsFromCache())
|
||||
{
|
||||
entities |= config.getEntities();
|
||||
}
|
||||
}
|
||||
return entities;
|
||||
}
|
||||
|
||||
CDatabaseReaderConfigList CDatabaseReaderConfigList::forMappingTool()
|
||||
{
|
||||
const CTime timeout(5.0, CTimeUnit::min());
|
||||
@@ -125,6 +144,7 @@ namespace BlackCore
|
||||
CDatabaseReaderConfigList l;
|
||||
l.push_back(CDatabaseReaderConfig(CEntityFlags::AircraftIcaoEntity, retrievalFlags, timeout));
|
||||
l.push_back(CDatabaseReaderConfig(CEntityFlags::AirlineIcaoEntity, retrievalFlags, timeout));
|
||||
l.push_back(CDatabaseReaderConfig(CEntityFlags::AirportEntity, CDbFlags::Ignore, timeout)); // not needed in mapping tool
|
||||
l.push_back(CDatabaseReaderConfig(CEntityFlags::DistributorEntity, retrievalFlags, timeout));
|
||||
l.push_back(CDatabaseReaderConfig(CEntityFlags::ModelEntity, retrievalFlags, timeout));
|
||||
l.push_back(CDatabaseReaderConfig(CEntityFlags::LiveryEntity, retrievalFlags, timeout));
|
||||
@@ -139,6 +159,7 @@ namespace BlackCore
|
||||
CDatabaseReaderConfigList l;
|
||||
l.push_back(CDatabaseReaderConfig(CEntityFlags::AircraftIcaoEntity, retrievalFlags, timeout));
|
||||
l.push_back(CDatabaseReaderConfig(CEntityFlags::AirlineIcaoEntity, retrievalFlags, timeout));
|
||||
l.push_back(CDatabaseReaderConfig(CEntityFlags::AirportEntity, retrievalFlags, timeout));
|
||||
l.push_back(CDatabaseReaderConfig(CEntityFlags::DistributorEntity, retrievalFlags, timeout));
|
||||
l.push_back(CDatabaseReaderConfig(CEntityFlags::ModelEntity, retrievalFlags, timeout));
|
||||
l.push_back(CDatabaseReaderConfig(CEntityFlags::LiveryEntity, retrievalFlags, timeout));
|
||||
@@ -158,6 +179,7 @@ namespace BlackCore
|
||||
CDatabaseReaderConfigList l;
|
||||
l.push_back(CDatabaseReaderConfig(CEntityFlags::AircraftIcaoEntity, retrievalFlags, timeout));
|
||||
l.push_back(CDatabaseReaderConfig(CEntityFlags::AirlineIcaoEntity, retrievalFlags, timeout));
|
||||
l.push_back(CDatabaseReaderConfig(CEntityFlags::AirportEntity, retrievalFlags, timeout));
|
||||
l.push_back(CDatabaseReaderConfig(CEntityFlags::DistributorEntity, retrievalFlags, timeout));
|
||||
l.push_back(CDatabaseReaderConfig(CEntityFlags::ModelEntity, retrievalFlags, timeout));
|
||||
l.push_back(CDatabaseReaderConfig(CEntityFlags::LiveryEntity, retrievalFlags, timeout));
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace BlackCore
|
||||
{
|
||||
namespace Db
|
||||
{
|
||||
//! Details how to read
|
||||
//! Details how to read a certain entity
|
||||
class BLACKCORE_EXPORT CDatabaseReaderConfig : public BlackMisc::CValueObject<CDatabaseReaderConfig>
|
||||
{
|
||||
public:
|
||||
@@ -62,6 +62,9 @@ namespace BlackCore
|
||||
//! Will read from swift DB
|
||||
bool possiblyReadsFromSwiftDb() const;
|
||||
|
||||
//! Will read from cache
|
||||
bool possiblyReadsFromCache() const;
|
||||
|
||||
//! Fully initialized
|
||||
bool isValid() const;
|
||||
|
||||
@@ -103,6 +106,9 @@ namespace BlackCore
|
||||
//! Will read from swift DB
|
||||
bool possiblyReadsFromSwiftDb() const;
|
||||
|
||||
//! Entities which will use cache or DB, so no canceled or ignored ones
|
||||
BlackMisc::Network::CEntityFlags::Entity getEntitesCachedOrReadFromDB() const;
|
||||
|
||||
//! Init for mapping tool
|
||||
static CDatabaseReaderConfigList forMappingTool();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user