From 314c005ff2b266fbb24b57003dd5ec241d615902 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 8 Apr 2016 14:09:14 +0200 Subject: [PATCH] refs #614, a generic interface to modify / update models so I can write generic functions for that purpose and use them * interface for the caches * generic model interfaces --- .../simulation/aircraftmodelinterfaces.h | 61 +++++++++ src/blackmisc/simulation/data/modelcaches.cpp | 16 +-- src/blackmisc/simulation/data/modelcaches.h | 129 +++++++++++------- 3 files changed, 150 insertions(+), 56 deletions(-) create mode 100644 src/blackmisc/simulation/aircraftmodelinterfaces.h diff --git a/src/blackmisc/simulation/aircraftmodelinterfaces.h b/src/blackmisc/simulation/aircraftmodelinterfaces.h new file mode 100644 index 000000000..58c67aeae --- /dev/null +++ b/src/blackmisc/simulation/aircraftmodelinterfaces.h @@ -0,0 +1,61 @@ +/* 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_AIRCRAFTMODELINTERFACES_H +#define BLACKMISC_SIMULATION_AIRCRAFTMODELINTERFACES_H + +#include "blackmisc/simulation/aircraftmodellist.h" +#include "blackmisc/blackmiscexport.h" + +namespace BlackMisc +{ + namespace Simulation + { + //! Interface to "something" backing models, which can be set + class BLACKMISC_EXPORT IModelsSetable + { + public: + //! Set models + virtual void setModels(const CAircraftModelList &models) = 0; + }; + + //! Interface to "something" backing models, which can be modified (updated) + class BLACKMISC_EXPORT IModelsUpdatable + { + public: + //! Update models + virtual void updateModels(const CAircraftModelList &models) = 0; + }; + + //! Interface to "something" backing models, which can be set + class BLACKMISC_EXPORT IModelsPerSimulatorSetable + { + public: + //! Set models + virtual void setModels(const CAircraftModelList &models, const CSimulatorInfo &simulator) = 0; + }; + + //! Interface to "something" backing models, which can be modified (updated) + class BLACKMISC_EXPORT IModelsPerSimulatorUpdatable + { + public: + //! Set models + virtual void updateModels(const CAircraftModelList &models, const CSimulatorInfo &simulator) = 0; + }; + } // namespace +} // namespace + +Q_DECLARE_INTERFACE(BlackMisc::Simulation::IModelsSetable, "org.swift-project.blackmisc.simulation.imodelssetable") +Q_DECLARE_INTERFACE(BlackMisc::Simulation::IModelsUpdatable, "org.swift-project.blackmisc.simulation.imodelsupdateable") +Q_DECLARE_INTERFACE(BlackMisc::Simulation::IModelsPerSimulatorSetable, "org.swift-project.blackmisc.simulation.imodelspersimulatorsetable") +Q_DECLARE_INTERFACE(BlackMisc::Simulation::IModelsPerSimulatorUpdatable, "org.swift-project.blackmisc.simulation.imodelspersimulatorupdatabale") + +#endif // guard diff --git a/src/blackmisc/simulation/data/modelcaches.cpp b/src/blackmisc/simulation/data/modelcaches.cpp index 892e646bf..4ce806a36 100644 --- a/src/blackmisc/simulation/data/modelcaches.cpp +++ b/src/blackmisc/simulation/data/modelcaches.cpp @@ -15,10 +15,10 @@ namespace BlackMisc { namespace Data { - CModelCaches::CModelCaches(QObject *parent) : QObject(parent) + CModelCaches::CModelCaches(QObject *parent) : IMultiSimulatorModelCaches(parent) { } - CAircraftModelList CModelCaches::getModels(const CSimulatorInfo &simulator) const + CAircraftModelList CModelCaches::getCachedModels(const CSimulatorInfo &simulator) const { Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator"); switch (simulator.getSimulator()) @@ -33,7 +33,7 @@ namespace BlackMisc } } - CStatusMessage CModelCaches::setModels(const CAircraftModelList &models, const CSimulatorInfo &simulator) + CStatusMessage CModelCaches::setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator) { Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator"); switch (simulator.getSimulator()) @@ -63,7 +63,7 @@ namespace BlackMisc } } - void CModelCaches::syncronize(const CSimulatorInfo &simulator) + void CModelCaches::syncronizeCache(const CSimulatorInfo &simulator) { Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator"); switch (simulator.getSimulator()) @@ -77,10 +77,10 @@ namespace BlackMisc } } - CModelSetCaches::CModelSetCaches(QObject *parent) : QObject(parent) + CModelSetCaches::CModelSetCaches(QObject *parent) : IMultiSimulatorModelCaches(parent) { } - CAircraftModelList CModelSetCaches::getModels(const CSimulatorInfo &simulator) const + CAircraftModelList CModelSetCaches::getCachedModels(const CSimulatorInfo &simulator) const { Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator"); switch (simulator.getSimulator()) @@ -95,7 +95,7 @@ namespace BlackMisc } } - CStatusMessage CModelSetCaches::setModels(const CAircraftModelList &models, const CSimulatorInfo &simulator) + CStatusMessage CModelSetCaches::setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator) { Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator"); switch (simulator.getSimulator()) @@ -125,7 +125,7 @@ namespace BlackMisc } } - void CModelSetCaches::syncronize(const CSimulatorInfo &simulator) + void CModelSetCaches::syncronizeCache(const CSimulatorInfo &simulator) { Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator"); switch (simulator.getSimulator()) diff --git a/src/blackmisc/simulation/data/modelcaches.h b/src/blackmisc/simulation/data/modelcaches.h index 0986cfa91..13fab9006 100644 --- a/src/blackmisc/simulation/data/modelcaches.h +++ b/src/blackmisc/simulation/data/modelcaches.h @@ -14,6 +14,7 @@ #include "blackmisc/datacache.h" #include "blackmisc/simulation/aircraftmodellist.h" +#include "blackmisc/simulation/aircraftmodelinterfaces.h" namespace BlackMisc { @@ -105,9 +106,47 @@ namespace BlackMisc static const char *key() { return "vpilot/models"; } }; + //! Cache for multiple simulators specified by BlackMisc::Simulation::CSimulatorInfo + class IMultiSimulatorModelCaches : + public QObject, + public IModelsPerSimulatorSetable + { + Q_OBJECT + + public: + //! Construtor + IMultiSimulatorModelCaches(QObject *parent = nullptr) : QObject(parent) + { } + + //! Models + //! \threadsafe + virtual CAircraftModelList getCachedModels(const BlackMisc::Simulation::CSimulatorInfo &simulator) const = 0; + + //! Cache timestamp + //! \threadsafe + virtual QDateTime getCacheTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator) const = 0; + + //! Set cache + virtual BlackMisc::CStatusMessage setCachedModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0; + + //! Syncronize + virtual void syncronizeCache(const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0; + + //! \copydoc IModelsPerSimulatorSetable::setModels + virtual void setModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override + { + this->setCachedModels(models, simulator); + } + + signals: + //! Cache has been changed + void cacheChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator); + }; + + //! Bundle of caches for all simulators //! \remark Temp. workaround - class CModelCaches : public QObject + class CModelCaches : public IMultiSimulatorModelCaches { Q_OBJECT @@ -115,31 +154,33 @@ namespace BlackMisc //! Construtor CModelCaches(QObject *parent = nullptr); - //! Models - //! \threadsafe - CAircraftModelList getModels(const BlackMisc::Simulation::CSimulatorInfo &simulator) const; - - //! Set models - BlackMisc::CStatusMessage setModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator); - - //! Cache timestamp - //! \threadsafe - QDateTime getCacheTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator) const; - - //! Syncronize - void syncronize(const BlackMisc::Simulation::CSimulatorInfo &simulator); + //! \name Interface implementations + //! @{ + virtual CAircraftModelList getCachedModels(const BlackMisc::Simulation::CSimulatorInfo &simulator) const override; + virtual BlackMisc::CStatusMessage setCachedModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override; + virtual QDateTime getCacheTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator) const override; + virtual void syncronizeCache(const BlackMisc::Simulation::CSimulatorInfo &simulator) override; + //! @} private: - BlackMisc::CData m_modelCacheFsx {this }; //!< FSX cache - BlackMisc::CData m_modelCacheFs9 {this }; //!< FS9 cache - BlackMisc::CData m_modelCacheP3D {this }; //!< P3D cache - BlackMisc::CData m_modelCacheXP {this }; //!< XP cache - }; + //! \todo Why can`t I keep the changed functions in IMultiSimulatorModelCaches -> C2039 not a member + BlackMisc::CData m_modelCacheFsx {this, &CModelCaches::changedFsx }; //!< FSX cache + BlackMisc::CData m_modelCacheFs9 {this, &CModelCaches::changedFs9 }; //!< FS9 cache + BlackMisc::CData m_modelCacheP3D {this, &CModelCaches::changedP3D }; //!< P3D cache + BlackMisc::CData m_modelCacheXP {this, &CModelCaches::changedXP }; //!< XP cache + //! \name Cache has been changed + //! @{ + void changedFsx() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FSX)); } + void changedFs9() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FS9)); } + void changedP3D() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::P3D)); } + void changedXP() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::XPLANE)); } + //! @} + }; //! Bundle of caches for model sets of all simulators //! \remark Temp. workaround - class CModelSetCaches : public QObject + class CModelSetCaches : public IMultiSimulatorModelCaches { Q_OBJECT @@ -147,37 +188,29 @@ namespace BlackMisc //! Construtor CModelSetCaches(QObject *parent = nullptr); - //! Models - //! \threadsafe - CAircraftModelList getModels(const BlackMisc::Simulation::CSimulatorInfo &simulator) const; - - //! Set models - BlackMisc::CStatusMessage setModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator); - - //! Cache timestamp - //! \threadsafe - QDateTime getCacheTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator) const; - - //! Syncronize - void syncronize(const BlackMisc::Simulation::CSimulatorInfo &simulator); - - signals: - //! Cache has been changed - void cacheChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator); - - private slots: - void ps_changedFsx() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FSX)); } - void ps_changedFs9() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FS9)); } - void ps_changedP3D() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::P3D)); } - void ps_changedXP() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::XPLANE)); } + //! \name Interface implementations + //! @{ + virtual CAircraftModelList getCachedModels(const BlackMisc::Simulation::CSimulatorInfo &simulator) const override; + virtual BlackMisc::CStatusMessage setCachedModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override; + virtual QDateTime getCacheTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator) const override; + virtual void syncronizeCache(const BlackMisc::Simulation::CSimulatorInfo &simulator) override; + //! @} private: - BlackMisc::CData m_modelCacheFsx {this, &CModelSetCaches::ps_changedFsx }; //!< FSX cache - BlackMisc::CData m_modelCacheFs9 {this, &CModelSetCaches::ps_changedFs9}; //!< FS9 cache - BlackMisc::CData m_modelCacheP3D {this, &CModelSetCaches::ps_changedP3D }; //!< P3D cache - BlackMisc::CData m_modelCacheXP {this, &CModelSetCaches::ps_changedXP }; //!< XP cache - }; + //! \todo Why can`t I keep the changed functions in IMultiSimulatorModelCaches -> C2039 not a member + BlackMisc::CData m_modelCacheFsx {this, &CModelSetCaches::changedFsx }; //!< FSX cache + BlackMisc::CData m_modelCacheFs9 {this, &CModelSetCaches::changedFs9}; //!< FS9 cache + BlackMisc::CData m_modelCacheP3D {this, &CModelSetCaches::changedP3D }; //!< P3D cache + BlackMisc::CData m_modelCacheXP {this, &CModelSetCaches::changedXP }; //!< XP cache + //! \name Cache has been changed + //! @{ + void changedFsx() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FSX)); } + void changedFs9() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FS9)); } + void changedP3D() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::P3D)); } + void changedXP() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::XPLANE)); } + //! @} + }; } // ns } // ns } // ns