From 75ee43c0e1832d73ab1b5128c29579627610742a Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 24 Jul 2018 16:51:20 +0200 Subject: [PATCH] Ref T292, Ref T285 removed model set loader The model set loader is actually no loader (unlike the model loader which really loads the models from disk) but only a cache and will be replaced by CCentralMultiSimulatorModelSetCachesProvider --- .../simulation/aircraftmodelsetloader.cpp | 151 ----------------- .../simulation/aircraftmodelsetloader.h | 155 ------------------ 2 files changed, 306 deletions(-) delete mode 100644 src/blackmisc/simulation/aircraftmodelsetloader.cpp delete mode 100644 src/blackmisc/simulation/aircraftmodelsetloader.h diff --git a/src/blackmisc/simulation/aircraftmodelsetloader.cpp b/src/blackmisc/simulation/aircraftmodelsetloader.cpp deleted file mode 100644 index 76847d99a..000000000 --- a/src/blackmisc/simulation/aircraftmodelsetloader.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* Copyright (C) 2015 - * 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 - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "blackmisc/simulation/aircraftmodelsetloader.h" - -#include -#include - -using namespace BlackMisc::Simulation::Data; - -namespace BlackMisc -{ - namespace Simulation - { - CAircraftModelSetLoader::CAircraftModelSetLoader(QObject *parent) : QObject(parent) - { - connect(&m_caches, &CModelSetCaches::cacheChanged, this, &CAircraftModelSetLoader::onModelsCacheChanged); - } - - CAircraftModelSetLoader::~CAircraftModelSetLoader() - { - this->gracefulShutdown(); - } - - CStatusMessage CAircraftModelSetLoader::setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator) - { - Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator"); - const CStatusMessage m(m_caches.setCachedModels(models, simulator)); - return m; - } - - void CAircraftModelSetLoader::changeSimulator(const CSimulatorInfo &simulator) - { - if (m_currentSimulator == simulator) { return; } - m_currentSimulator = simulator; - m_caches.synchronizeCache(simulator); - emit this->simulatorChanged(simulator); - } - - CAircraftModelList CAircraftModelSetLoader::getAircraftModels() const - { - return m_caches.getCachedModels(m_currentSimulator); - } - - CAircraftModelList CAircraftModelSetLoader::getAircraftModels(const CSimulatorInfo &simulator) - { - Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator"); - return m_caches.getSynchronizedCachedModels(simulator); - } - - int CAircraftModelSetLoader::getAircraftModelsCount() const - { - return this->getAircraftModels().size(); - } - - CAircraftModel CAircraftModelSetLoader::getModelForModelString(const QString &modelString) const - { - if (modelString.isEmpty()) { return CAircraftModel(); } - return this->getAircraftModels().findFirstByModelStringOrDefault(modelString); - } - - CAircraftModelList CAircraftModelSetLoader::getCachedModels(const CSimulatorInfo &simulator) const - { - return m_caches.getCachedModels(simulator); - } - - QDateTime CAircraftModelSetLoader::getCacheTimestamp() const - { - return m_caches.getCacheTimestamp(m_currentSimulator); - } - - void CAircraftModelSetLoader::synchronizeCache() - { - m_caches.synchronizeCache(m_currentSimulator); - } - - void CAircraftModelSetLoader::admitCache() - { - m_caches.admitCache(m_currentSimulator); - } - - bool CAircraftModelSetLoader::hasCachedData() const - { - return !m_caches.getCachedModels(m_currentSimulator).isEmpty(); - } - - CStatusMessage CAircraftModelSetLoader::clearCache() - { - return m_caches.clearCachedModels(this->getSimulator()); - } - - void CAircraftModelSetLoader::onModelsCacheChanged(const CSimulatorInfo &simulator) - { - this->changeSimulator(simulator); - emit this->cacheChanged(simulator); - } - - QString CAircraftModelSetLoader::getSimulatorAsString() const - { - return this->getSimulator().toQString(); - } - - void CAircraftModelSetLoader::setSimulator(const CSimulatorInfo &simulator) - { - Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Only one simulator per loader"); - if (this->getSimulator() == simulator) { return; } - this->changeSimulator(simulator); - } - - bool CAircraftModelSetLoader::supportsSimulator(const CSimulatorInfo &info) - { - return this->getSimulator().matchesAny(info); - } - - CSimulatorInfo CAircraftModelSetLoader::simulatorsWithInitializedModelSet() const - { - return m_caches.simulatorsWithInitializedCache(); - } - - void CAircraftModelSetLoader::gracefulShutdown() - { - // void - } - - QString CAircraftModelSetLoader::getInfoString() const - { - return m_caches.getInfoString(); - } - - QString CAircraftModelSetLoader::getInfoStringFsFamily() const - { - return m_caches.getInfoStringFsFamily(); - } - - QString CAircraftModelSetLoader::getModelCacheCountAndTimestamp() const - { - return m_caches.getCacheCountAndTimestamp(this->getSimulator()); - } - - QString CAircraftModelSetLoader::getModelCacheCountAndTimestamp(const CSimulatorInfo &simulator) const - { - return m_caches.getCacheCountAndTimestamp(simulator); - } - } // ns -} // ns diff --git a/src/blackmisc/simulation/aircraftmodelsetloader.h b/src/blackmisc/simulation/aircraftmodelsetloader.h deleted file mode 100644 index 0a9f060e8..000000000 --- a/src/blackmisc/simulation/aircraftmodelsetloader.h +++ /dev/null @@ -1,155 +0,0 @@ -/* 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 - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKMISC_SIMULATION_AIRCRAFTMODELSETLOADER_H -#define BLACKMISC_SIMULATION_AIRCRAFTMODELSETLOADER_H - -#include "blackmisc/blackmiscexport.h" -#include "blackmisc/simulation/aircraftmodel.h" -#include "blackmisc/simulation/aircraftmodelinterfaces.h" -#include "blackmisc/simulation/aircraftmodellist.h" -#include "blackmisc/simulation/data/modelcaches.h" -#include "blackmisc/simulation/simulatorinfo.h" -#include "blackmisc/statusmessage.h" - -#include -#include -#include - -namespace BlackMisc -{ - namespace Simulation - { - /*! - * Handling of current set for simulator - */ - class BLACKMISC_EXPORT CAircraftModelSetLoader : - public QObject, - public IModelsSetable, - public IModelsUpdatable, - public IModelsForSimulatorSetable, - public IModelsForSimulatorUpdatable - { - Q_OBJECT - Q_INTERFACES(BlackMisc::Simulation::IModelsSetable) - Q_INTERFACES(BlackMisc::Simulation::IModelsUpdatable) - Q_INTERFACES(BlackMisc::Simulation::IModelsForSimulatorSetable) - Q_INTERFACES(BlackMisc::Simulation::IModelsForSimulatorUpdatable) - - public: - //! Constructor - CAircraftModelSetLoader(QObject *parent = nullptr); - - //! Destructor - virtual ~CAircraftModelSetLoader(); - - //! Make sure cache is synchronized - void synchronizeCache(); - - //! Admit current cache - void admitCache(); - - //! The loaded models - //! \threadsafe - CAircraftModelList getAircraftModels() const; - - //! The loaded models for given simulator - //! \threadsafe - //! \remark non-const because it synchronizes cache - CAircraftModelList getAircraftModels(const CSimulatorInfo &simulator); - - //! Count of loaded models - //! \threadsafe - int getAircraftModelsCount() const; - - //! Model for given model string - //! \threadsafe - CAircraftModel getModelForModelString(const QString &modelString) const; - - //! Models from cache - //! \threadsafe - CAircraftModelList getCachedModels(const CSimulatorInfo &simulator) const; - - //! Current simulator - //! \threadsafe - CSimulatorInfo getSimulator() const { return m_currentSimulator; } - - //! Supported simulators as string - QString getSimulatorAsString() const; - - //! Set simulator - //! \remark checked version, does nothing if simulator is alread set - void setSimulator(const CSimulatorInfo &simulator); - - //! Is the given simulator supported? - bool supportsSimulator(const CSimulatorInfo &info); - - //! Simulators with initialized caches - CSimulatorInfo simulatorsWithInitializedModelSet() const; - - //! Shutdown - void gracefulShutdown(); - - //! \copydoc Data::CModelCaches::getInfoString - QString getInfoString() const; - - //! \copydoc Data::CModelCaches::getInfoStringFsFamily - QString getInfoStringFsFamily() const; - - //! \copydoc Data::CModelCaches::getCacheCountAndTimestamp - QString getModelCacheCountAndTimestamp() const; - - //! \copydoc Data::CModelCaches::getCacheCountAndTimestamp - QString getModelCacheCountAndTimestamp(const CSimulatorInfo &simulator) const; - - //! \name Implementations of the models interfaces - //! @{ - virtual void setModels(const CAircraftModelList &models) override { this->setCachedModels(models, this->getSimulator()); } - virtual int updateModels(const CAircraftModelList &models) override { return m_caches.updateModelsForSimulator(models, this->getSimulator()); } - virtual void setModelsForSimulator(const CAircraftModelList &models, const CSimulatorInfo &simulator) override { this->setCachedModels(models, simulator); } - virtual int updateModelsForSimulator(const CAircraftModelList &models, const CSimulatorInfo &simulator) override { return m_caches.updateModelsForSimulator(models, simulator); } - //! @} - - //! Set cached models - CStatusMessage setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator); - - signals: - //! Simulator has been changed - void simulatorChanged(const CSimulatorInfo &simulator); - - //! Cache changed - void cacheChanged(const CSimulatorInfo &simulator); - - protected: - Data::CModelSetCaches m_caches { true, this }; //!< caches - CSimulatorInfo m_currentSimulator = CSimulatorInfo::guessDefaultSimulator(); - - private: - //! Change the simulator - //! \remark unckecked, does not check if simulator is the same - void changeSimulator(const CSimulatorInfo &simulator); - - //! Model cache has changed - void onModelsCacheChanged(const CSimulatorInfo &simulator); - - //! Any cached data? - bool hasCachedData() const; - - //! Cache timestamp - QDateTime getCacheTimestamp() const; - - //! Clear cache - BlackMisc::CStatusMessage clearCache(); - }; - } // namespace -} // namespace - -#endif // guard