mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-27 02:55:44 +08:00
refs #709, access to timestamp/count per entity
* utility functions * made protected functions public
This commit is contained in:
@@ -62,7 +62,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
const bool changedUrl = this->hasChangedUrl(currentEntity);
|
const bool changedUrl = this->hasChangedUrl(currentEntity);
|
||||||
const QDateTime cacheTs(this->getCacheTimestamp(currentEntity));
|
const QDateTime cacheTs(this->getCacheTimestamp(currentEntity));
|
||||||
const QDateTime latestEntityTs(this->getLatestEntityTimestamp(currentEntity));
|
const QDateTime latestEntityTs(this->getLatestEntityTimestampFromInfoObjects(currentEntity));
|
||||||
const qint64 cacheTimestamp = cacheTs.isValid() ? cacheTs.toMSecsSinceEpoch() : -1;
|
const qint64 cacheTimestamp = cacheTs.isValid() ? cacheTs.toMSecsSinceEpoch() : -1;
|
||||||
const qint64 latestEntityTimestamp = latestEntityTs.isValid() ? latestEntityTs.toMSecsSinceEpoch() : -1;
|
const qint64 latestEntityTimestamp = latestEntityTs.isValid() ? latestEntityTs.toMSecsSinceEpoch() : -1;
|
||||||
Q_ASSERT_X(latestEntityTimestamp >= 0, Q_FUNC_INFO, "Missing timestamp");
|
Q_ASSERT_X(latestEntityTimestamp >= 0, Q_FUNC_INFO, "Missing timestamp");
|
||||||
@@ -180,7 +180,7 @@ namespace BlackCore
|
|||||||
return infoList().size() > 0;
|
return infoList().size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDateTime CDatabaseReader::getLatestEntityTimestamp(CEntityFlags::Entity entity) const
|
QDateTime CDatabaseReader::getLatestEntityTimestampFromInfoObjects(CEntityFlags::Entity entity) const
|
||||||
{
|
{
|
||||||
static const QDateTime e;
|
static const QDateTime e;
|
||||||
const CDbInfoList il(infoList());
|
const CDbInfoList il(infoList());
|
||||||
@@ -190,6 +190,16 @@ namespace BlackCore
|
|||||||
return info.getUtcTimestamp();
|
return info.getUtcTimestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CDatabaseReader::getCountFromInfoObjects(CEntityFlags::Entity entity) const
|
||||||
|
{
|
||||||
|
static const QDateTime e;
|
||||||
|
const CDbInfoList il(infoList());
|
||||||
|
if (il.isEmpty() || entity == CEntityFlags::NoEntity) { return -1; }
|
||||||
|
CDbInfo info = il.findFirstByEntityOrDefault(entity);
|
||||||
|
if (!info.isValid()) { return -1; }
|
||||||
|
return info.getEntries();
|
||||||
|
}
|
||||||
|
|
||||||
CDatabaseReaderConfig CDatabaseReader::getConfigForEntity(CEntityFlags::Entity entity) const
|
CDatabaseReaderConfig CDatabaseReader::getConfigForEntity(CEntityFlags::Entity entity) const
|
||||||
{
|
{
|
||||||
return this->m_config.findFirstOrDefaultForEntity(entity);
|
return this->m_config.findFirstOrDefaultForEntity(entity);
|
||||||
|
|||||||
@@ -103,6 +103,23 @@ namespace BlackCore
|
|||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
bool canConnect(QString &message) const;
|
bool canConnect(QString &message) const;
|
||||||
|
|
||||||
|
//! Get cache timestamp
|
||||||
|
virtual QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entities) const = 0;
|
||||||
|
|
||||||
|
//! Cache`s number of entities
|
||||||
|
virtual int getCacheCount(BlackMisc::Network::CEntityFlags::Entity entity) const = 0;
|
||||||
|
|
||||||
|
//! Info objects available?
|
||||||
|
bool hasInfoObjects() const;
|
||||||
|
|
||||||
|
//! Obtain latest object timestamp from info objects
|
||||||
|
//! \sa BlackCore::Db::CInfoDataReader
|
||||||
|
QDateTime getLatestEntityTimestampFromInfoObjects(BlackMisc::Network::CEntityFlags::Entity entity) const;
|
||||||
|
|
||||||
|
//! Count from info objects
|
||||||
|
//! \sa BlackCore::Db::CInfoDataReader
|
||||||
|
int getCountFromInfoObjects(BlackMisc::Network::CEntityFlags::Entity entity) const;
|
||||||
|
|
||||||
//! Status message (error message)
|
//! Status message (error message)
|
||||||
const QString &getStatusMessage() const;
|
const QString &getStatusMessage() const;
|
||||||
|
|
||||||
@@ -138,13 +155,6 @@ namespace BlackCore
|
|||||||
//! \sa BlackCore::Db::CInfoDataReader
|
//! \sa BlackCore::Db::CInfoDataReader
|
||||||
BlackMisc::Db::CDbInfoList infoList() const;
|
BlackMisc::Db::CDbInfoList infoList() const;
|
||||||
|
|
||||||
//! Info objects available?
|
|
||||||
bool hasInfoObjects() const;
|
|
||||||
|
|
||||||
//! Obtain latest object timestamp
|
|
||||||
//! \sa BlackCore::Db::CInfoDataReader
|
|
||||||
QDateTime getLatestEntityTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) const;
|
|
||||||
|
|
||||||
//! Config for given entity
|
//! Config for given entity
|
||||||
CDatabaseReaderConfig getConfigForEntity(BlackMisc::Network::CEntityFlags::Entity entity) const;
|
CDatabaseReaderConfig getConfigForEntity(BlackMisc::Network::CEntityFlags::Entity entity) const;
|
||||||
|
|
||||||
@@ -159,16 +169,9 @@ namespace BlackCore
|
|||||||
|
|
||||||
//! \name Cache access
|
//! \name Cache access
|
||||||
//! @{
|
//! @{
|
||||||
|
|
||||||
//! Syncronize caches for given entities
|
//! Syncronize caches for given entities
|
||||||
virtual void syncronizeCaches(BlackMisc::Network::CEntityFlags::Entity entities) = 0;
|
virtual void syncronizeCaches(BlackMisc::Network::CEntityFlags::Entity entities) = 0;
|
||||||
|
|
||||||
//! Cache`s timestamp for given entity
|
|
||||||
virtual QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entities) const = 0;
|
|
||||||
|
|
||||||
//! Cache`s number of entities
|
|
||||||
virtual int getCacheCount(BlackMisc::Network::CEntityFlags::Entity entity) const = 0;
|
|
||||||
|
|
||||||
//! Invalidate the caches for given entities
|
//! Invalidate the caches for given entities
|
||||||
virtual void invalidateCaches(BlackMisc::Network::CEntityFlags::Entity entities) = 0;
|
virtual void invalidateCaches(BlackMisc::Network::CEntityFlags::Entity entities) = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -114,15 +114,15 @@ namespace BlackCore
|
|||||||
//! Write to static DB data file
|
//! Write to static DB data file
|
||||||
bool writeToJsonFiles(const QString &dir) const;
|
bool writeToJsonFiles(const QString &dir) const;
|
||||||
|
|
||||||
protected:
|
// cache handling for base class
|
||||||
//! \name cache handling for base class
|
|
||||||
//! @{
|
|
||||||
virtual void syncronizeCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
|
|
||||||
virtual void invalidateCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
|
|
||||||
virtual QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
virtual QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
||||||
virtual int getCacheCount(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
virtual int getCacheCount(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
||||||
|
virtual void syncronizeCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// cache handling for base class
|
||||||
|
virtual void invalidateCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
|
||||||
virtual bool hasChangedUrl(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
virtual bool hasChangedUrl(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
||||||
//! @}
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
//! Aircraft have been read
|
//! Aircraft have been read
|
||||||
|
|||||||
@@ -48,19 +48,19 @@ namespace BlackCore
|
|||||||
//! URL info objects web service
|
//! URL info objects web service
|
||||||
BlackMisc::Network::CUrl getInfoObjectsUrl() const;
|
BlackMisc::Network::CUrl getInfoObjectsUrl() const;
|
||||||
|
|
||||||
|
// cache handling for base class
|
||||||
|
virtual QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
||||||
|
virtual int getCacheCount(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
//! Allow to call CInfoDataReader::ps_read directly, special for info objects
|
//! Allow to call CInfoDataReader::ps_read directly, special for info objects
|
||||||
void read(BlackMisc::Network::CEntityFlags::Entity entities = BlackMisc::Network::CEntityFlags::InfoObjectEntity, const QDateTime &newerThan = QDateTime());
|
void read(BlackMisc::Network::CEntityFlags::Entity entities = BlackMisc::Network::CEntityFlags::InfoObjectEntity, const QDateTime &newerThan = QDateTime());
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! \name cache handling for base class
|
// cache handling for base class
|
||||||
//! @{
|
|
||||||
virtual void syncronizeCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
|
virtual void syncronizeCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
|
||||||
virtual void invalidateCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
|
virtual void invalidateCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
|
||||||
virtual QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
|
||||||
virtual int getCacheCount(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
|
||||||
virtual bool hasChangedUrl(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
virtual bool hasChangedUrl(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
||||||
//! @}
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
//! Info objects have been read
|
//! Info objects have been read
|
||||||
|
|||||||
@@ -120,15 +120,15 @@ namespace BlackCore
|
|||||||
//! Write to JSON file
|
//! Write to JSON file
|
||||||
bool writeToJsonFiles(const QString &dir) const;
|
bool writeToJsonFiles(const QString &dir) const;
|
||||||
|
|
||||||
protected:
|
// cache handling for base class
|
||||||
//! \name cache handling for base class
|
|
||||||
//! @{
|
|
||||||
virtual void syncronizeCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
|
|
||||||
virtual void invalidateCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
|
|
||||||
virtual QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
virtual QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
||||||
virtual int getCacheCount(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
virtual int getCacheCount(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
||||||
|
virtual void syncronizeCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// cache handling for base class
|
||||||
|
virtual void invalidateCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
|
||||||
virtual bool hasChangedUrl(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
virtual bool hasChangedUrl(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
||||||
//! @}
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
//! Liveries have been read
|
//! Liveries have been read
|
||||||
|
|||||||
@@ -213,6 +213,69 @@ namespace BlackCore
|
|||||||
return triggeredRead;
|
return triggeredRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDateTime CWebDataServices::getCacheTimestamp(CEntityFlags::Entity entity) const
|
||||||
|
{
|
||||||
|
Q_ASSERT_X(CEntityFlags::isSingleEntity(entity), Q_FUNC_INFO, "Need single entity");
|
||||||
|
if (CEntityFlags::anySwiftDbEntity(entity))
|
||||||
|
{
|
||||||
|
CDatabaseReader *dr = this->getDbReader(entity);
|
||||||
|
if (!dr) { return QDateTime(); }
|
||||||
|
return dr->getCacheTimestamp(entity);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// non DB entities would go here
|
||||||
|
return QDateTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QDateTime CWebDataServices::getDbLatestEntityTimestamp(CEntityFlags::Entity entity) const
|
||||||
|
{
|
||||||
|
Q_ASSERT_X(CEntityFlags::isSingleEntity(entity), Q_FUNC_INFO, "Need single entity");
|
||||||
|
if (CEntityFlags::anySwiftDbEntity(entity))
|
||||||
|
{
|
||||||
|
CInfoDataReader *ir = this->getInfoDataReader();
|
||||||
|
if (!ir) { return QDateTime(); }
|
||||||
|
return ir->getLatestEntityTimestampFromInfoObjects(entity);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return QDateTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int CWebDataServices::getCacheCount(CEntityFlags::Entity entity) const
|
||||||
|
{
|
||||||
|
Q_ASSERT_X(CEntityFlags::isSingleEntity(entity), Q_FUNC_INFO, "Need single entity");
|
||||||
|
if (CEntityFlags::anySwiftDbEntity(entity))
|
||||||
|
{
|
||||||
|
CDatabaseReader *dr = this->getDbReader(entity);
|
||||||
|
if (!dr) { return -1; }
|
||||||
|
return dr->getCacheCount(entity);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// non DB entities would go here
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int CWebDataServices::getDbInfoCount(CEntityFlags::Entity entity) const
|
||||||
|
{
|
||||||
|
Q_ASSERT_X(CEntityFlags::isSingleEntity(entity), Q_FUNC_INFO, "Need single entity");
|
||||||
|
if (CEntityFlags::anySwiftDbEntity(entity))
|
||||||
|
{
|
||||||
|
CDatabaseReader *dr = this->getDbReader(entity);
|
||||||
|
if (!dr) { return -1; }
|
||||||
|
return dr->getCountFromInfoObjects(entity);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// non DB entities would go here
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CDistributorList CWebDataServices::getDistributors() const
|
CDistributorList CWebDataServices::getDistributors() const
|
||||||
{
|
{
|
||||||
if (m_modelDataReader) { return m_modelDataReader->getDistributors(); }
|
if (m_modelDataReader) { return m_modelDataReader->getDistributors(); }
|
||||||
@@ -535,6 +598,20 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CDatabaseReader *CWebDataServices::getDbReader(CEntityFlags::Entity entity) const
|
||||||
|
{
|
||||||
|
Q_ASSERT_X(CEntityFlags::isSingleEntity(entity), Q_FUNC_INFO, "Need single entity");
|
||||||
|
Q_ASSERT_X(CEntityFlags::anySwiftDbEntity(entity), Q_FUNC_INFO, "No swift DB entity");
|
||||||
|
|
||||||
|
CWebReaderFlags::WebReader wr = CWebReaderFlags::entityToReader(entity);
|
||||||
|
switch (wr)
|
||||||
|
{
|
||||||
|
case CWebReaderFlags::IcaoDataReader: return this->m_icaoDataReader;
|
||||||
|
case CWebReaderFlags::ModelReader: return this->m_modelDataReader;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void CWebDataServices::initWriters()
|
void CWebDataServices::initWriters()
|
||||||
{
|
{
|
||||||
this->m_databaseWriter = new CDatabaseWriter(
|
this->m_databaseWriter = new CDatabaseWriter(
|
||||||
@@ -630,6 +707,7 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// read entities
|
||||||
if (delayMs > 100)
|
if (delayMs > 100)
|
||||||
{
|
{
|
||||||
this->singleShotReadInBackground(entities, 0);
|
this->singleShotReadInBackground(entities, 0);
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ namespace BlackCore
|
|||||||
namespace Db
|
namespace Db
|
||||||
{
|
{
|
||||||
class CDatabaseWriter;
|
class CDatabaseWriter;
|
||||||
|
class CDatabaseReader;
|
||||||
class CIcaoDataReader;
|
class CIcaoDataReader;
|
||||||
class CModelDataReader;
|
class CModelDataReader;
|
||||||
class CInfoDataReader;
|
class CInfoDataReader;
|
||||||
@@ -284,6 +285,22 @@ namespace BlackCore
|
|||||||
//! Trigger read of new data
|
//! Trigger read of new data
|
||||||
BlackMisc::Network::CEntityFlags::Entity triggerRead(BlackMisc::Network::CEntityFlags::Entity whatToRead, const QDateTime &dateTime = QDateTime());
|
BlackMisc::Network::CEntityFlags::Entity triggerRead(BlackMisc::Network::CEntityFlags::Entity whatToRead, const QDateTime &dateTime = QDateTime());
|
||||||
|
|
||||||
|
//! Corresponding cache timestamp if applicable
|
||||||
|
//! \threadsafe
|
||||||
|
QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) const;
|
||||||
|
|
||||||
|
//! Corresponding DB timestamp if applicable
|
||||||
|
//! \threadsafe
|
||||||
|
QDateTime getDbLatestEntityTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) const;
|
||||||
|
|
||||||
|
//! Cache count for entity
|
||||||
|
//! \threadsafe
|
||||||
|
int getCacheCount(BlackMisc::Network::CEntityFlags::Entity entity) const;
|
||||||
|
|
||||||
|
//! Count for entity from entity objects
|
||||||
|
//! \threadsafe
|
||||||
|
int getDbInfoCount(BlackMisc::Network::CEntityFlags::Entity entity) const;
|
||||||
|
|
||||||
//! Can connect to swift DB?
|
//! Can connect to swift DB?
|
||||||
bool canConnectSwiftDb() const;
|
bool canConnectSwiftDb() const;
|
||||||
|
|
||||||
@@ -321,6 +338,9 @@ namespace BlackCore
|
|||||||
//! Init the readers
|
//! Init the readers
|
||||||
void initReaders(CWebReaderFlags::WebReader flags);
|
void initReaders(CWebReaderFlags::WebReader flags);
|
||||||
|
|
||||||
|
//! DB reader for given entity
|
||||||
|
Db::CDatabaseReader *getDbReader(BlackMisc::Network::CEntityFlags::Entity entity) const;
|
||||||
|
|
||||||
//! Init the writers
|
//! Init the writers
|
||||||
void initWriters();
|
void initWriters();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user