diff --git a/src/blackcore/application.cpp b/src/blackcore/application.cpp index 05d0f1775..e1173d8de 100644 --- a/src/blackcore/application.cpp +++ b/src/blackcore/application.cpp @@ -479,7 +479,7 @@ namespace BlackCore return this->startCoreFacade(); // will do nothing if setup is not yet loaded } - bool CApplication::useWebDataServices(const CWebReaderFlags::WebReader webReader, const CDatabaseReaderConfigList &dbReaderConfig) + bool CApplication::useWebDataServices(const CWebReaderFlags::WebReader webReaders, const CDatabaseReaderConfigList &dbReaderConfig) { Q_ASSERT_X(this->m_webDataServices.isNull(), Q_FUNC_INFO, "Services already started"); BLACK_VERIFY_X(QSslSocket::supportsSsl(), Q_FUNC_INFO, "No SSL"); @@ -489,7 +489,7 @@ namespace BlackCore return false; } - this->m_webReader = webReader; + this->m_webReadersUsed = webReaders; this->m_dbReaderConfig = dbReaderConfig; this->m_useWebData = true; return this->startWebDataServices(); @@ -524,7 +524,7 @@ namespace BlackCore { CLogMessage(this).info("Will start web data services now"); this->m_webDataServices.reset( - new CWebDataServices(this->m_webReader, this->m_dbReaderConfig, {}, this) + new CWebDataServices(this->m_webReadersUsed, this->m_dbReaderConfig, {}, this) ); } return true; diff --git a/src/blackcore/application.h b/src/blackcore/application.h index 5b81e8464..c1e2e4154 100644 --- a/src/blackcore/application.h +++ b/src/blackcore/application.h @@ -394,7 +394,7 @@ namespace BlackCore SwiftApplication m_application = Unknown; //!< Application if specified QReadWriteLock m_accessManagerLock; //!< lock to make access manager access threadsafe CCoreFacadeConfig m_coreFacadeConfig; //!< Core facade config if any - CWebReaderFlags::WebReader m_webReader; //!< Readers used + CWebReaderFlags::WebReader m_webReadersUsed; //!< Readers to be used BlackCore::Db::CDatabaseReaderConfigList m_dbReaderConfig; //!< Load or used caching? std::atomic m_shutdown { false }; //!< is being shutdown? bool m_useContexts = false; //!< use contexts diff --git a/src/blackcore/db/databasereader.cpp b/src/blackcore/db/databasereader.cpp index dd535059e..9a386238b 100644 --- a/src/blackcore/db/databasereader.cpp +++ b/src/blackcore/db/databasereader.cpp @@ -48,9 +48,10 @@ namespace BlackCore // we accept cached cached data Q_ASSERT_X(!entities.testFlag(CEntityFlags::InfoObjectEntity), Q_FUNC_INFO, "Read info objects directly"); - CEntityFlags::Entity allEntities = entities; - CEntityFlags::Entity currentEntity = CEntityFlags::iterateDbEntities(allEntities); // CEntityFlags::InfoObjectEntity will be ignored - const bool hasInfoObjects = this->hasInfoObjects(); + 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 + CEntityFlags::Entity allEntities = entities; + CEntityFlags::Entity cachedEntities = CEntityFlags::NoEntity; + CEntityFlags::Entity currentEntity = CEntityFlags::iterateDbEntities(allEntities); // CEntityFlags::InfoObjectEntity will be ignored while (currentEntity) { const CDatabaseReaderConfig config(this->getConfigForEntity(currentEntity)); @@ -68,6 +69,7 @@ namespace BlackCore { this->syncronizeCaches(currentEntity); entities &= ~currentEntity; // do not load from web + cachedEntities |= currentEntity; // read from cache CLogMessage(this).info("Using cache for %1 (%2, %3)") << CEntityFlags::flagToString(currentEntity) << cacheTs.toString() << cacheTimestamp; @@ -93,14 +95,17 @@ namespace BlackCore this->syncronizeCaches(currentEntity); const int c = this->getCacheCount(currentEntity); CLogMessage(this).info("No info object for %1, using cache with %2 objects") - << CEntityFlags::flagToString(currentEntity) - << c; + << CEntityFlags::flagToString(currentEntity) << c; entities &= ~currentEntity; // do not load from web + cachedEntities |= currentEntity; // read from cache } } currentEntity = CEntityFlags::iterateDbEntities(allEntities); } + // signals for the cached entities + this->emitReadSignalPerSingleCachedEntity(cachedEntities); + // ps_read is implemented in the derived classes if (entities == CEntityFlags::NoEntity) { return; } const bool s = QMetaObject::invokeMethod(this, "ps_read", @@ -195,6 +200,18 @@ namespace BlackCore return this->m_config.findFirstOrDefaultForEntity(entity); } + void CDatabaseReader::emitReadSignalPerSingleCachedEntity(CEntityFlags::Entity cachedEntities) + { + CEntityFlags::Entity cachedEntitiesToEmit = cachedEntities; + CEntityFlags::Entity currentCachedEntity = CEntityFlags::iterateDbEntities(cachedEntitiesToEmit); + while (currentCachedEntity) + { + const int c = this->getCacheCount(currentCachedEntity); + emit dataRead(currentCachedEntity, CEntityFlags::ReadFinished, c); + currentCachedEntity = CEntityFlags::iterateDbEntities(cachedEntitiesToEmit); + } + } + bool CDatabaseReader::isChangedUrl(const CUrl &oldUrl, const CUrl ¤tUrl) { if (oldUrl.isEmpty()) { return true; } diff --git a/src/blackcore/db/databasereader.h b/src/blackcore/db/databasereader.h index 729424474..7bd960065 100644 --- a/src/blackcore/db/databasereader.h +++ b/src/blackcore/db/databasereader.h @@ -118,12 +118,16 @@ namespace BlackCore //! Name of parameter for latest id static const QString ¶meterLatestId(); + signals: + //! Combined read signal + void dataRead(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState state, int number); + protected: - CDatabaseReaderConfigList m_config; //!< DB reder configuration - BlackMisc::Network::CUrl m_sharedUrl; //!< URL for shared files - QString m_statusMessage; //!< Returned status message from watchdog - bool m_canConnect = false; //!< Successful connection? - mutable QReadWriteLock m_statusLock; //!< Lock + CDatabaseReaderConfigList m_config; //!< DB reder configuration + BlackMisc::Network::CUrl m_sharedUrl; //!< URL for shared files + QString m_statusMessage; //!< Returned status message from watchdog + bool m_canConnect = false; //!< Successful connection? + mutable QReadWriteLock m_statusLock; //!< Lock //! Constructor CDatabaseReader(QObject *owner, const CDatabaseReaderConfigList &config, const QString &name); @@ -145,6 +149,9 @@ namespace BlackCore //! Config for given entity CDatabaseReaderConfig getConfigForEntity(BlackMisc::Network::CEntityFlags::Entity entity) const; + //! Split into single entity and send dataRead signal + void emitReadSignalPerSingleCachedEntity(BlackMisc::Network::CEntityFlags::Entity cachedEntities); + //! Syncronize caches for given entities virtual void syncronizeCaches(BlackMisc::Network::CEntityFlags::Entity entities) = 0; diff --git a/src/blackcore/db/databasereaderconfig.cpp b/src/blackcore/db/databasereaderconfig.cpp index a539576c8..c8843e332 100644 --- a/src/blackcore/db/databasereaderconfig.cpp +++ b/src/blackcore/db/databasereaderconfig.cpp @@ -52,6 +52,13 @@ namespace BlackCore this->m_cacheLifetime = time; } + bool CDatabaseReaderConfig::possiblyReadsFromSwiftDb() const + { + if (!this->isValid()) { return false; } + if (!CEntityFlags::anySwiftDbEntity(this->getEntities())) { return false; } + return (this->getRetrievalMode().testFlag(CDbFlags::DbDirect) || this->getRetrievalMode().testFlag(CDbFlags::Shared)); + } + bool CDatabaseReaderConfig::isValid() const { return this->m_entities != BlackMisc::Network::CEntityFlags::NoEntity; @@ -87,10 +94,19 @@ namespace BlackCore } } + bool CDatabaseReaderConfigList::possiblyReadsFromSwiftDb() const + { + for (const CDatabaseReaderConfig &config : *this) + { + if (config.possiblyReadsFromSwiftDb()) { return true; } + } + return false; + } + CDatabaseReaderConfigList CDatabaseReaderConfigList::forMappingTool() { const CTime timeout(5.0, CTimeUnit::min()); - const CDbFlags::DataRetrievalMode retrievalFlags = CDbFlags::DbCached; + const CDbFlags::DataRetrievalMode retrievalFlags = CDbFlags::CacheThenDb; CDatabaseReaderConfigList l; l.push_back(CDatabaseReaderConfig(CEntityFlags::AircraftIcaoEntity, retrievalFlags, timeout)); l.push_back(CDatabaseReaderConfig(CEntityFlags::AirlineIcaoEntity, retrievalFlags, timeout)); @@ -104,7 +120,7 @@ namespace BlackCore CDatabaseReaderConfigList CDatabaseReaderConfigList::forPilotClient() { const CTime timeout(24.0, CTimeUnit::h()); - const CDbFlags::DataRetrievalMode retrievalFlags = CDbFlags::SharedCached; + const CDbFlags::DataRetrievalMode retrievalFlags = CDbFlags::CacheThenDb; CDatabaseReaderConfigList l; l.push_back(CDatabaseReaderConfig(CEntityFlags::AircraftIcaoEntity, retrievalFlags, timeout)); l.push_back(CDatabaseReaderConfig(CEntityFlags::AirlineIcaoEntity, retrievalFlags, timeout)); diff --git a/src/blackcore/db/databasereaderconfig.h b/src/blackcore/db/databasereaderconfig.h index b2999098b..98631f0c3 100644 --- a/src/blackcore/db/databasereaderconfig.h +++ b/src/blackcore/db/databasereaderconfig.h @@ -56,6 +56,9 @@ namespace BlackCore //! Timeout void setCacheLifetime(const BlackMisc::PhysicalQuantities::CTime &time); + //! Will read from swift DB + bool possiblyReadsFromSwiftDb() const; + //! Fully initialized bool isValid() const; @@ -91,6 +94,9 @@ namespace BlackCore //! Update lifetimes void setCacheLifetimes(const BlackMisc::PhysicalQuantities::CTime &time); + //! Will read from swift DB + bool possiblyReadsFromSwiftDb() const; + //! Init for mapping tool static CDatabaseReaderConfigList forMappingTool(); diff --git a/src/blackcore/db/icaodatareader.h b/src/blackcore/db/icaodatareader.h index a219c1485..4cb908244 100644 --- a/src/blackcore/db/icaodatareader.h +++ b/src/blackcore/db/icaodatareader.h @@ -114,10 +114,6 @@ namespace BlackCore //! Write to static DB data file bool writeToJsonFiles(const QString &dir) const; - signals: - //! Combined read signal - void dataRead(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState state, int number); - protected: //! \name cache handling for base class //! @{ diff --git a/src/blackcore/db/infodatareader.cpp b/src/blackcore/db/infodatareader.cpp index 3c10760b8..a6c67a0f7 100644 --- a/src/blackcore/db/infodatareader.cpp +++ b/src/blackcore/db/infodatareader.cpp @@ -30,7 +30,8 @@ namespace BlackCore CInfoDataReader::CInfoDataReader(QObject *owner, const CDatabaseReaderConfigList &config) : CDatabaseReader(owner, config, "CInfoDataReader") { - // void + // init to avoid threading issues + getBaseUrl(); } CDbInfoList CInfoDataReader::getDbInfoObjects() const @@ -121,6 +122,8 @@ namespace BlackCore // wrap pointer, make sure any exit cleans up reply // required to use delete later as object is created in a different thread QScopedPointer nwReply(nwReplyPtr); + if (this->isAbandoned()) { return; } + QString urlString(nwReply->url().toString()); CDatabaseReader::JsonDatastoreResponse res = this->setStatusAndTransformReplyIntoDatastoreResponse(nwReply.data()); if (res.hasErrorMessage()) @@ -146,9 +149,9 @@ namespace BlackCore CLogMessage(this).info("Read %1 %2 from %3") << n << CEntityFlags::flagToString(CEntityFlags::InfoObjectEntity) << urlString; } - CUrl CInfoDataReader::getBaseUrl() const + const CUrl &CInfoDataReader::getBaseUrl() { - const CUrl baseUrl(sApp->getGlobalSetup().getDbInfoReaderUrl()); + static const CUrl baseUrl(sApp->getGlobalSetup().getDbInfoReaderUrl()); return baseUrl; } @@ -156,6 +159,5 @@ namespace BlackCore { return getBaseUrl().withAppendedPath("service/jsondbinfo.php"); } - } // namespace } // namespace diff --git a/src/blackcore/db/infodatareader.h b/src/blackcore/db/infodatareader.h index 95083d770..409bea285 100644 --- a/src/blackcore/db/infodatareader.h +++ b/src/blackcore/db/infodatareader.h @@ -52,10 +52,6 @@ namespace BlackCore //! 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()); - signals: - //! Combined read signal - void dataRead(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState state, int number); - protected: //! \name cache handling for base class //! @{ @@ -79,7 +75,7 @@ namespace BlackCore mutable QReadWriteLock m_lockInfoObjects; //! Base URL - BlackMisc::Network::CUrl getBaseUrl() const; + static const BlackMisc::Network::CUrl &getBaseUrl(); }; } // ns } // ns diff --git a/src/blackcore/db/modeldatareader.h b/src/blackcore/db/modeldatareader.h index a36a02933..c0504ed4e 100644 --- a/src/blackcore/db/modeldatareader.h +++ b/src/blackcore/db/modeldatareader.h @@ -119,10 +119,6 @@ namespace BlackCore //! Write to JSON file bool writeToJsonFiles(const QString &dir) const; - signals: - //! Combined read signal - void dataRead(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState state, int number); - protected: //! \name cache handling for base class //! @{ diff --git a/src/blackcore/webdataservices.cpp b/src/blackcore/webdataservices.cpp index 9f15a6b55..b9c9859b6 100644 --- a/src/blackcore/webdataservices.cpp +++ b/src/blackcore/webdataservices.cpp @@ -48,24 +48,39 @@ using namespace BlackMisc::Weather; namespace BlackCore { - CWebDataServices::CWebDataServices(CWebReaderFlags::WebReader readerFlags, const CDatabaseReaderConfigList &dbReaderConfig, BlackMisc::Restricted, QObject *parent) : - QObject(parent), m_readerFlags(readerFlags), m_dbReaderConfig(dbReaderConfig) + CWebDataServices::CWebDataServices(CWebReaderFlags::WebReader readers, const CDatabaseReaderConfigList &dbReaderConfig, BlackMisc::Restricted, QObject *parent) : + QObject(parent), m_readers(readers), m_dbReaderConfig(dbReaderConfig) { if (!sApp) { return; } // shutting down Q_ASSERT_X(QSslSocket::supportsSsl(), Q_FUNC_INFO, "missing SSL support"); Q_ASSERT_X(sApp->isSetupAvailable(), Q_FUNC_INFO, "Setup not syncronized"); this->setObjectName("CWebDataReader"); - this->initReaders(readerFlags); - this->initWriters(); - const bool withInfoData = m_readerFlags.testFlag(CWebReaderFlags::WebReaderFlag::InfoDataReader); - CEntityFlags::Entity entities = CEntityFlags::AllEntities; - entities ^= CEntityFlags::InfoObjectEntity; // 2 liner because of gcc error: invalid conversion from 'int' to 'BlackMisc::Network::CEntityFlags::EntityFlag' - if (withInfoData) { CLogMessage(this).info("Using info objects for swift DB objects"); } + // check if I need info objects + const bool readFromSwiftDb = dbReaderConfig.possiblyReadsFromSwiftDb(); // only cached? + if (!readFromSwiftDb && readers.testFlag(CWebReaderFlags::InfoDataReader)) + { + // will remove info reader becaue not needed + readers &= ~CWebReaderFlags::InfoDataReader; + this->m_readers = readers; + CLogMessage(this).info("Remove info object reader because not needed"); + } + + // get entities to be read + CEntityFlags::Entity entities = CWebReaderFlags::allEntitiesForReaders(readers); + if (entities.testFlag(CEntityFlags::InfoObjectEntity)) + { + Q_ASSERT_X(readers.testFlag(CWebReaderFlags::InfoDataReader), Q_FUNC_INFO, "info object but no reader"); + CLogMessage(this).info("Using info objects for swift DB objects"); + } + + this->initReaders(readers); // reads info object if required + this->initWriters(); // make sure this is called in event queue, so pending tasks cam be performed // important so info objects can be read + entities &= ~CEntityFlags::InfoObjectEntity; this->singleShotReadInBackground(entities, 1000); } @@ -394,6 +409,7 @@ namespace BlackCore if (this->m_vatsimStatusReader) { this->m_vatsimStatusReader->gracefulShutdown(); } if (this->m_vatsimBookingReader) { this->m_vatsimBookingReader->gracefulShutdown(); } if (this->m_vatsimDataFileReader) { this->m_vatsimDataFileReader->gracefulShutdown(); } + if (this->m_vatsimStatusReader) { this->m_vatsimStatusReader->gracefulShutdown(); } if (this->m_vatsimMetarReader) { this->m_vatsimMetarReader->gracefulShutdown(); } if (this->m_modelDataReader) { this->m_modelDataReader->gracefulShutdown(); } if (this->m_icaoDataReader) { this->m_icaoDataReader->gracefulShutdown(); } @@ -432,7 +448,7 @@ namespace BlackCore } // 2. Status file, updating the VATSIM related caches - if (flags.testFlag(CWebReaderFlags::WebReaderFlag::VatsimDataReader) || flags.testFlag(CWebReaderFlags::WebReaderFlag::VatsimMetarReader)) + if (flags.testFlag(CWebReaderFlags::VatsimStatusReader) || flags.testFlag(CWebReaderFlags::VatsimDataReader) || flags.testFlag(CWebReaderFlags::VatsimMetarReader)) { this->m_vatsimStatusReader = new CVatsimStatusFileReader(this); this->m_vatsimStatusReader->start(QThread::LowPriority); diff --git a/src/blackcore/webdataservices.h b/src/blackcore/webdataservices.h index 8336e6624..61bac923d 100644 --- a/src/blackcore/webdataservices.h +++ b/src/blackcore/webdataservices.h @@ -108,7 +108,7 @@ namespace BlackCore Db::CDatabaseWriter *getDatabaseWriter() const { return m_databaseWriter; } //! Reader flags - CWebReaderFlags::WebReader getReaderFlags() const { return m_readerFlags; } + CWebReaderFlags::WebReader getReaderFlags() const { return m_readers; } //! FSD servers //! \threadsafe @@ -319,10 +319,10 @@ namespace BlackCore //! Call CWebDataServices::readInBackground by single shot void singleShotReadInBackground(BlackMisc::Network::CEntityFlags::Entity entities, int delayMs); - CWebReaderFlags::WebReader m_readerFlags = CWebReaderFlags::WebReaderFlag::None; //!< which readers are available - BlackCore::Db::CDatabaseReaderConfigList m_dbReaderConfig; //!< how to read DB data - bool m_initialRead = false; //!< Initial read started - int m_infoObjectTrials = 0; //!< Tried to read info objects + CWebReaderFlags::WebReader m_readers = CWebReaderFlags::WebReaderFlag::None; //!< which readers are available + BlackCore::Db::CDatabaseReaderConfigList m_dbReaderConfig; //!< how to read DB data + bool m_initialRead = false; //!< Initial read started + int m_infoObjectTrials = 0; //!< Tried to read info objects // for reading XML and VATSIM data files CVatsimStatusFileReader *m_vatsimStatusReader = nullptr; diff --git a/src/blackcore/webreaderflags.cpp b/src/blackcore/webreaderflags.cpp index d87777619..47c4da687 100644 --- a/src/blackcore/webreaderflags.cpp +++ b/src/blackcore/webreaderflags.cpp @@ -16,42 +16,43 @@ namespace BlackCore CWebReaderFlags::WebReader CWebReaderFlags::entityToReader(CEntityFlags::Entity entity) { WebReader f = None; - if (entity.testFlag(CEntityFlags::AircraftIcaoEntity) || - entity.testFlag(CEntityFlags::AirlineIcaoEntity) || - entity.testFlag(CEntityFlags::CountryEntity)) + if (entity.testFlag(CEntityFlags::AircraftIcaoEntity) || entity.testFlag(CEntityFlags::AirlineIcaoEntity) || entity.testFlag(CEntityFlags::CountryEntity)) { f |= IcaoDataReader; } - if (entity.testFlag(CEntityFlags::ModelEntity) || - entity.testFlag(CEntityFlags::DistributorEntity) || - entity.testFlag(CEntityFlags::LiveryEntity)) + if (entity.testFlag(CEntityFlags::ModelEntity) || entity.testFlag(CEntityFlags::DistributorEntity) || entity.testFlag(CEntityFlags::LiveryEntity)) { f |= ModelReader; } - if (entity.testFlag(CEntityFlags::InfoObjectEntity)) - { - f |= InfoDataReader; - } + if (entity.testFlag(CEntityFlags::InfoObjectEntity)) { f |= InfoDataReader; } + if (entity.testFlag(CEntityFlags::BookingEntity)) { f |= VatsimBookingReader; } + if (entity.testFlag(CEntityFlags::VatsimDataFile)) { f |= VatsimDataReader; } + if (entity.testFlag(CEntityFlags::VatsimStatusFile)) { f |= VatsimStatusReader; } + if (entity.testFlag(CEntityFlags::MetarEntity)) { f |= VatsimMetarReader; } - if (entity.testFlag(CEntityFlags::BookingEntity)) - { - f |= VatsimBookingReader; - } - - if (entity.testFlag(CEntityFlags::VatsimDataFile)) - { - f |= VatsimDataReader; - } - - if (entity.testFlag(CEntityFlags::MetarEntity)) - { - f |= VatsimMetarReader; - } return f; } + CWebReaderFlags::WebReader CWebReaderFlags::webReaderFlagToWebReader(CWebReaderFlags::WebReaderFlag flag) + { + return static_cast(flag); + } + + CEntityFlags::Entity CWebReaderFlags::allEntitiesForReaders(WebReader readers) + { + CEntityFlags::Entity entities = CEntityFlags::NoEntity; + if (readers.testFlag(IcaoDataReader)) { entities |= CEntityFlags::AllIcaoAndCountries; } + if (readers.testFlag(ModelReader)) { entities |= CEntityFlags::DistributorLiveryModel; } + if (readers.testFlag(InfoDataReader)) { entities |= CEntityFlags::InfoObjectEntity; } + if (readers.testFlag(VatsimBookingReader)) { entities |= CEntityFlags::BookingEntity; } + if (readers.testFlag(VatsimMetarReader)) { entities |= CEntityFlags::MetarEntity; } + if (readers.testFlag(VatsimDataReader)) { entities |= CEntityFlags::VatsimDataFile; } + if (readers.testFlag(VatsimStatusReader)) { entities |= CEntityFlags::VatsimStatusFile; } + return entities; + } + bool CWebReaderFlags::isFromSwiftDb(BlackMisc::Network::CEntityFlags::Entity entity) { return isFromSwiftDb(entityToReader(entity)); diff --git a/src/blackcore/webreaderflags.h b/src/blackcore/webreaderflags.h index 46a5dbc82..3cc2326c6 100644 --- a/src/blackcore/webreaderflags.h +++ b/src/blackcore/webreaderflags.h @@ -33,18 +33,25 @@ namespace BlackCore VatsimBookingReader = 1 << 0, //!< reader for VATSIM booking data VatsimDataReader = 1 << 1, //!< reader for VATSIM data VatsimMetarReader = 1 << 2, //!< reader for VATSIM metar data - IcaoDataReader = 1 << 3, //!< reader for ICAO data - ModelReader = 1 << 4, //!< reader for model data such as liveries, models, etc - InfoDataReader = 1 << 5, //!< DB info data (metdata, how many data, when updated) - AllVatsimReaders = VatsimBookingReader | VatsimDataReader | VatsimMetarReader, //!< all readers - AllSwiftDbReaders = IcaoDataReader | ModelReader | InfoDataReader, //!< all swift data - AllReaders = AllSwiftDbReaders | AllVatsimReaders //!< everything + VatsimStatusReader = 1 << 3, //!< reader for VATSIM status file + IcaoDataReader = 1 << 4, //!< reader for ICAO data + ModelReader = 1 << 5, //!< reader for model data such as liveries, models, etc + InfoDataReader = 1 << 6, //!< DB info data (metdata, how many data, when updated) + AllVatsimReaders = VatsimBookingReader | VatsimDataReader | VatsimMetarReader | VatsimStatusReader, //!< all VATSIM readers + AllSwiftDbReaders = IcaoDataReader | ModelReader | InfoDataReader, //!< all swift data + AllReaders = AllSwiftDbReaders | AllVatsimReaders //!< everything }; Q_DECLARE_FLAGS(WebReader, WebReaderFlag) //! Relationship between reader and entity static WebReader entityToReader(BlackMisc::Network::CEntityFlags::Entity entity); + //! Cast + static WebReader webReaderFlagToWebReader(WebReaderFlag flag); + + //! All entities readers can read + static BlackMisc::Network::CEntityFlags::Entity allEntitiesForReaders(WebReader readers); + //! Reads from swift DB? static bool isFromSwiftDb(BlackMisc::Network::CEntityFlags::Entity entity); diff --git a/src/blackmisc/db/dbflags.cpp b/src/blackmisc/db/dbflags.cpp index 127a32d52..105d44f96 100644 --- a/src/blackmisc/db/dbflags.cpp +++ b/src/blackmisc/db/dbflags.cpp @@ -17,6 +17,11 @@ namespace BlackMisc { namespace Db { + bool CDbFlags::readsFromWeb(CDbFlags::DataRetrievalMode mode) + { + return mode.testFlag(DbDirect) || mode.testFlag(Shared); + } + QString CDbFlags::flagToString(CDbFlags::DataRetrievalModeFlag flag) { switch (flag) @@ -31,13 +36,13 @@ namespace BlackMisc } } - QString CDbFlags::flagToString(BlackMisc::Db::CDbFlags::DataRetrievalMode flag) + QString CDbFlags::flagToString(CDbFlags::DataRetrievalMode mode) { QStringList list; - if (flag.testFlag(Unspecified)) list << "Unspecified"; - if (flag.testFlag(DbDirect)) list << "Direct DB access"; - if (flag.testFlag(Shared)) list << "Shared data"; - if (flag.testFlag(Cached)) list << "Cached data"; + if (mode.testFlag(Unspecified)) list << "Unspecified"; + if (mode.testFlag(DbDirect)) list << "Direct DB access"; + if (mode.testFlag(Shared)) list << "Shared data"; + if (mode.testFlag(Cached)) list << "Cached data"; return list.join(','); } diff --git a/src/blackmisc/db/dbflags.h b/src/blackmisc/db/dbflags.h index 9d5fec049..874d82b7c 100644 --- a/src/blackmisc/db/dbflags.h +++ b/src/blackmisc/db/dbflags.h @@ -31,20 +31,25 @@ namespace BlackMisc //! Which data to read, requires corresponding readers enum DataRetrievalModeFlag { - Unspecified = 0, //!< Unspecified - DbDirect = 1 << 0, //!< directly from DB - Shared = 1 << 1, //!< shared directory - Cached = 1 << 2, //!< from cache - DbCached = DbDirect | Cached, //!< from DB, but cache when possible - SharedCached = Shared | Cached //!< from shared files, but cache when possible + Unspecified = 0, //!< Unspecified + DbDirect = 1 << 0, //!< directly from DB + Shared = 1 << 1, //!< shared directory + Cached = 1 << 2, //!< from cache + DbFailover = 1 << 3, //!< read from DB if cache (and only if) cache is empty + SharedFailover = 1 << 4, //!< read shared if cache (and only if) cache is empty + CacheThenDb = DbDirect | Cached, //!< Cache when possible, otherwise DB + CacheThenShared = Shared | Cached //!< Cache when possible, otherwise shared }; Q_DECLARE_FLAGS(DataRetrievalMode, DataRetrievalModeFlag) + //! Reads from web (or just cached) + static bool readsFromWeb(CDbFlags::DataRetrievalMode mode); + //! Convert to string static QString flagToString(DataRetrievalModeFlag flag); //! Convert to string - static QString flagToString(BlackMisc::Db::CDbFlags::DataRetrievalMode flag); + static QString flagToString(CDbFlags::DataRetrievalMode mode); //! Register metadata static void registerMetadata();