From 31b03fe2e14d1311f515d19fdcda92b3b19edbab Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 19 Jul 2016 04:28:43 +0200 Subject: [PATCH] refs #712, signals when all DB data are read / the web services are started (useful for GUI as it can be used to init only when data are available) --- src/blackcore/application.cpp | 2 ++ src/blackcore/application.h | 3 ++- src/blackcore/db/databasereader.h | 2 +- src/blackcore/webdataservices.cpp | 10 +++++++++- src/blackcore/webdataservices.h | 4 ++++ src/blackmisc/network/entityflags.h | 9 +++++---- 6 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/blackcore/application.cpp b/src/blackcore/application.cpp index ee014c8d6..20329a9c3 100644 --- a/src/blackcore/application.cpp +++ b/src/blackcore/application.cpp @@ -561,6 +561,8 @@ namespace BlackCore new CWebDataServices(this->m_webReadersUsed, this->m_dbReaderConfig, {}, this) ); } + + emit webDataServicesStarted(true); return true; } diff --git a/src/blackcore/application.h b/src/blackcore/application.h index 8f68b9654..a50f92187 100644 --- a/src/blackcore/application.h +++ b/src/blackcore/application.h @@ -322,13 +322,14 @@ namespace BlackCore void updateInfoAvailable(bool success); //! Startup has been completed + //! \remark needs to be triggered by application when it think it is done void startUpCompleted(bool success); //! Facade started void coreFacadeStarted(); //! Web data services started - void webDataServicesStarted(); + void webDataServicesStarted(bool success); protected slots: //! Setup read/syncronized diff --git a/src/blackcore/db/databasereader.h b/src/blackcore/db/databasereader.h index dd60a8470..89cd49c8f 100644 --- a/src/blackcore/db/databasereader.h +++ b/src/blackcore/db/databasereader.h @@ -48,7 +48,7 @@ namespace BlackCore { QJsonArray m_jsonArray; //!< JSON array data QDateTime m_updated; //!< when was the latest updated? - int m_arraySize = -1; //!< size of array, if applicable (copied to member for debugging purposes) + int m_arraySize = -1; //!< size of array, if applicable (copied to member for debugging purposes) bool m_restricted = false; //!< restricted reponse, only changed data BlackMisc::CStatusMessage m_message; //!< last error or warning diff --git a/src/blackcore/webdataservices.cpp b/src/blackcore/webdataservices.cpp index 2dd677bd4..8273e3f6e 100644 --- a/src/blackcore/webdataservices.cpp +++ b/src/blackcore/webdataservices.cpp @@ -668,9 +668,11 @@ namespace BlackCore void CWebDataServices::ps_readFromSwiftDb(CEntityFlags::Entity entity, CEntityFlags::ReadState state, int number) { static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::webservice()})); + + if (state == CEntityFlags::StartRead) { return; } // just started if (CEntityFlags::isWarningOrAbove(state)) { - CStatusMessage::StatusSeverity severity = CEntityFlags::flagToSeverity(state); + const CStatusMessage::StatusSeverity severity = CEntityFlags::flagToSeverity(state); if (severity == CStatusMessage::SeverityWarning) { CLogMessage(cats).warning("Read data %1 entries: %2 state: %3") << CEntityFlags::flagToString(entity) << number << CEntityFlags::flagToString(state); @@ -684,6 +686,12 @@ namespace BlackCore { CLogMessage(cats).info("Read data %1 entries: %2 state: %3") << CEntityFlags::flagToString(entity) << number << CEntityFlags::flagToString(state); } + + this->m_swiftDbEntitiesReaad |= entity; + if (this->m_swiftDbEntitiesReaad == CEntityFlags::AllDbEntitiesNoInfoObjects || this->m_swiftDbEntitiesReaad == CEntityFlags::AllDbEntities) + { + emit allSwiftDbDataRead(); + } } void CWebDataServices::ps_setupChanged() diff --git a/src/blackcore/webdataservices.h b/src/blackcore/webdataservices.h index 407619925..384f61d2e 100644 --- a/src/blackcore/webdataservices.h +++ b/src/blackcore/webdataservices.h @@ -320,6 +320,9 @@ namespace BlackCore //! Combined read signal void dataRead(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState state, int number); + //! All swift DB data have been read + void allSwiftDbDataRead(); + public slots: //! Call CWebDataServices::readInBackground by single shot void readDeferredInBackground(BlackMisc::Network::CEntityFlags::Entity entities, int delayMs); @@ -356,6 +359,7 @@ namespace BlackCore CWebReaderFlags::WebReader m_readers = CWebReaderFlags::WebReaderFlag::None; //!< which readers are available BlackCore::Db::CDatabaseReaderConfigList m_dbReaderConfig; //!< how to read DB data BlackMisc::Network::CEntityFlags::Entity m_entitiesPeriodicallyRead = BlackMisc::Network::CEntityFlags::NoEntity; //!< those entities which are permanently updated by timers + BlackMisc::Network::CEntityFlags::Entity m_swiftDbEntitiesReaad = BlackMisc::Network::CEntityFlags::NoEntity; //!< entities read bool m_initialRead = false; //!< Initial read started int m_infoObjectTrials = 0; //!< Tried to read info objects diff --git a/src/blackmisc/network/entityflags.h b/src/blackmisc/network/entityflags.h index abb0bf84d..d1ce47b7c 100644 --- a/src/blackmisc/network/entityflags.h +++ b/src/blackmisc/network/entityflags.h @@ -45,10 +45,11 @@ namespace BlackMisc VatsimDataFile = 1 << 9, //!< the VATSIM data file (multiple data entities) VatsimStatusFile = 1 << 10, //!< the VATSIM status file (URLs for data files etc.) AllEntities = ((1 << 11) - 1), //!< everything - AllIcaoEntities = AircraftIcaoEntity | AirlineIcaoEntity, //!< all ICAO codes - AllIcaoAndCountries = AircraftIcaoEntity | AirlineIcaoEntity | CountryEntity, //!< all ICAO codes and countries - DistributorLiveryModel = DistributorEntity | LiveryEntity | ModelEntity, //!< Combinded - AllDbEntities = AllIcaoEntities | DistributorLiveryModel | InfoObjectEntity //!< All DB stuff + AllIcaoEntities = AircraftIcaoEntity | AirlineIcaoEntity, //!< all ICAO codes + AllIcaoAndCountries = AircraftIcaoEntity | AirlineIcaoEntity | CountryEntity, //!< all ICAO codes and countries + DistributorLiveryModel = DistributorEntity | LiveryEntity | ModelEntity, //!< Combinded + AllDbEntities = AllIcaoAndCountries | DistributorLiveryModel | InfoObjectEntity, //!< All DB stuff + AllDbEntitiesNoInfoObjects = AllIcaoAndCountries | DistributorLiveryModel //!< All DB entities, no info objects }; Q_DECLARE_FLAGS(Entity, EntityFlag)