diff --git a/src/blackmisc/simulation/aircraftmodelloader.cpp b/src/blackmisc/simulation/aircraftmodelloader.cpp index 6e40c37f9..67dc638e6 100644 --- a/src/blackmisc/simulation/aircraftmodelloader.cpp +++ b/src/blackmisc/simulation/aircraftmodelloader.cpp @@ -58,7 +58,7 @@ namespace BlackMisc if (models.isEmpty()) { return CStatusMessage(this, CStatusMessage::SeverityInfo, "No data"); } const CSimulatorInfo sim = simulator.isSingleSimulator() ? simulator : this->getSimulator(); if (!sim.isSingleSimulator()) { return CStatusMessage(this, CStatusMessage::SeverityError, "Invalid simuataor"); } - CAircraftModelList allModels(this->m_caches.getCachedModels(sim)); + CAircraftModelList allModels(this->m_caches.getSyncronizedCachedModels(sim)); int c = allModels.replaceOrAddModelsWithString(models, Qt::CaseInsensitive); if (c > 0) { diff --git a/src/blackmisc/simulation/aircraftmodelsetloader.cpp b/src/blackmisc/simulation/aircraftmodelsetloader.cpp index 65724505f..60aa3280f 100644 --- a/src/blackmisc/simulation/aircraftmodelsetloader.cpp +++ b/src/blackmisc/simulation/aircraftmodelsetloader.cpp @@ -42,8 +42,9 @@ namespace BlackMisc if (models.isEmpty()) { return CStatusMessage(this, CStatusMessage::SeverityInfo, "No data"); } const CSimulatorInfo sim = simulator.isSingleSimulator() ? simulator : this->m_caches.getCurrentSimulator(); if (!sim.isSingleSimulator()) { return CStatusMessage(this, CStatusMessage::SeverityError, "Invalid simuataor"); } - CAircraftModelList allModels(this->m_caches.getCachedModels(sim)); - int c = allModels.replaceOrAddModelsWithString(models, Qt::CaseInsensitive); + this->m_caches.syncronizeCache(sim); + CAircraftModelList allModels(this->m_caches.getSyncronizedCachedModels(sim)); + const int c = allModels.replaceOrAddModelsWithString(models, Qt::CaseInsensitive); if (c > 0) { return this->setCachedModels(models, sim); @@ -67,10 +68,10 @@ namespace BlackMisc return this->m_caches.getCurrentCachedModels(); } - CAircraftModelList CAircraftModelSetLoader::getAircraftModels(const CSimulatorInfo &simulator) const + CAircraftModelList CAircraftModelSetLoader::getAircraftModels(const CSimulatorInfo &simulator) { Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator"); - return this->m_caches.getCachedModels(simulator); + return this->m_caches.getSyncronizedCachedModels(simulator); } int CAircraftModelSetLoader::getAircraftModelsCount() const diff --git a/src/blackmisc/simulation/aircraftmodelsetloader.h b/src/blackmisc/simulation/aircraftmodelsetloader.h index f07303dfb..11dfdd8a8 100644 --- a/src/blackmisc/simulation/aircraftmodelsetloader.h +++ b/src/blackmisc/simulation/aircraftmodelsetloader.h @@ -60,7 +60,8 @@ namespace BlackMisc //! The loaded models for given simulator //! \threadsafe - BlackMisc::Simulation::CAircraftModelList getAircraftModels(const BlackMisc::Simulation::CSimulatorInfo &simulator) const; + //! \remark non-const because it syncronizes cache + BlackMisc::Simulation::CAircraftModelList getAircraftModels(const BlackMisc::Simulation::CSimulatorInfo &simulator); //! Count of loaded models //! \threadsafe diff --git a/src/blackmisc/simulation/data/modelcaches.cpp b/src/blackmisc/simulation/data/modelcaches.cpp index fb09617d4..322caaf77 100644 --- a/src/blackmisc/simulation/data/modelcaches.cpp +++ b/src/blackmisc/simulation/data/modelcaches.cpp @@ -26,6 +26,13 @@ namespace BlackMisc this->setCachedModels(models, simulator); } + CAircraftModelList IMultiSimulatorModelCaches::getSyncronizedCachedModels(const CSimulatorInfo &simulator) + { + BLACK_VERIFY_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "need single simulator"); + this->syncronizeCache(simulator); + return this->getCachedModels(simulator); + } + CAircraftModelList IMultiSimulatorModelCaches::getCurrentCachedModels() const { const CSimulatorInfo sim(this->getCurrentSimulator()); @@ -34,6 +41,13 @@ namespace BlackMisc return this->getCachedModels(sim); } + QDateTime IMultiSimulatorModelCaches::getSyncronizedTimestamp(const CSimulatorInfo &simulator) + { + BLACK_VERIFY_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "need single simulator"); + this->syncronizeCache(simulator); + return this->getCacheTimestamp(simulator); + } + bool IMultiSimulatorModelCaches::syncronizeCurrentCache() { const CSimulatorInfo sim(this->getCurrentSimulator()); diff --git a/src/blackmisc/simulation/data/modelcaches.h b/src/blackmisc/simulation/data/modelcaches.h index d0cc3c922..e71bd2ad9 100644 --- a/src/blackmisc/simulation/data/modelcaches.h +++ b/src/blackmisc/simulation/data/modelcaches.h @@ -162,6 +162,10 @@ namespace BlackMisc //! \threadsafe virtual CAircraftModelList getCachedModels(const BlackMisc::Simulation::CSimulatorInfo &simulator) const = 0; + //! Models + //! \todo is that threadsafe? + CAircraftModelList getSyncronizedCachedModels(const BlackMisc::Simulation::CSimulatorInfo &simulator); + //! Models //! \threadsafe CAircraftModelList getCurrentCachedModels() const; @@ -170,13 +174,19 @@ namespace BlackMisc //! \threadsafe virtual QDateTime getCacheTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator) const = 0; + //! Timestamp + //! \todo is that threadsafe? + QDateTime getSyncronizedTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator); + //! Last selection`s timestamp + //! \threadsafe QDateTime getCurrentCacheTimestamp() const; //! Set cache virtual BlackMisc::CStatusMessage setCachedModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0; //! Syncronize + //! \todo is that threadsafe? virtual void syncronizeCache(const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0; //! Last cache