mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 15:45:46 +08:00
refs #641, moved last simulator selection to caches
* removed from component cache * kept renamed component caches as stubs for later usage refs #646, removed gui state cache as it causes build issues on Jenkins (idea was to keep the classes as stubs for later usage)
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include "blackmisc/simulation/xplane/aircraftmodelloaderxplane.h"
|
||||
#include "blackmisc/simulation/xplane/xplaneutil.h"
|
||||
|
||||
using namespace BlackMisc::Simulation::Data;
|
||||
using namespace BlackMisc::Simulation::FsCommon;
|
||||
using namespace BlackMisc::Simulation::XPlane;
|
||||
|
||||
@@ -19,10 +20,11 @@ namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
IAircraftModelLoader::IAircraftModelLoader(const CSimulatorInfo &info, const QString &rootDirectory, const QStringList &excludeDirs) :
|
||||
m_simulatorInfo(info), m_rootDirectory(rootDirectory), m_excludedDirectories(excludeDirs)
|
||||
IAircraftModelLoader::IAircraftModelLoader(const CSimulatorInfo &simulator, const QString &rootDirectory, const QStringList &excludeDirs) :
|
||||
m_rootDirectory(rootDirectory), m_excludedDirectories(excludeDirs)
|
||||
{
|
||||
Q_ASSERT_X(info.isSingleSimulator(), Q_FUNC_INFO, "Only one simulator per loader");
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Only one simulator per loader");
|
||||
this->m_caches.setCurrentSimulator(simulator);
|
||||
connect(this, &IAircraftModelLoader::loadingFinished, this, &IAircraftModelLoader::ps_loadFinished);
|
||||
}
|
||||
|
||||
@@ -41,7 +43,7 @@ namespace BlackMisc
|
||||
|
||||
CStatusMessage IAircraftModelLoader::setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
||||
{
|
||||
const CSimulatorInfo sim = simulator.isSingleSimulator() ? simulator : this->m_simulatorInfo;
|
||||
const CSimulatorInfo sim = simulator.isSingleSimulator() ? simulator : this->getSimulator();
|
||||
if (!sim.isSingleSimulator()) { return CStatusMessage(this, CStatusMessage::SeverityError, "Invalid simuataor"); }
|
||||
return this->m_caches.setCachedModels(models, sim);
|
||||
}
|
||||
@@ -49,7 +51,7 @@ namespace BlackMisc
|
||||
CStatusMessage IAircraftModelLoader::replaceOrAddCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
||||
{
|
||||
if (models.isEmpty()) { return CStatusMessage(this, CStatusMessage::SeverityInfo, "No data"); }
|
||||
const CSimulatorInfo sim = simulator.isSingleSimulator() ? simulator : this->m_simulatorInfo;
|
||||
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));
|
||||
int c = allModels.replaceOrAddModelsWithString(models, Qt::CaseInsensitive);
|
||||
@@ -80,22 +82,22 @@ namespace BlackMisc
|
||||
|
||||
CAircraftModelList IAircraftModelLoader::getAircraftModels() const
|
||||
{
|
||||
return this->m_caches.getCachedModels(this->m_simulatorInfo);
|
||||
return this->m_caches.getCurrentCachedModels();
|
||||
}
|
||||
|
||||
QDateTime IAircraftModelLoader::getCacheTimestamp() const
|
||||
{
|
||||
return this->m_caches.getCacheTimestamp(this->m_simulatorInfo);
|
||||
return this->m_caches.getCurrentCacheTimestamp();
|
||||
}
|
||||
|
||||
void IAircraftModelLoader::syncronizeCache()
|
||||
bool IAircraftModelLoader::syncronizeCache()
|
||||
{
|
||||
return this->m_caches.syncronizeCache(this->m_simulatorInfo);
|
||||
return this->m_caches.syncronizeCurrentCache();
|
||||
}
|
||||
|
||||
bool IAircraftModelLoader::hasCachedData() const
|
||||
{
|
||||
return !this->m_caches.getCachedModels(this->m_simulatorInfo).isEmpty();
|
||||
return !this->m_caches.getCurrentCachedModels().isEmpty();
|
||||
}
|
||||
|
||||
CStatusMessage IAircraftModelLoader::clearCache()
|
||||
@@ -110,7 +112,7 @@ namespace BlackMisc
|
||||
const bool useCachedData = !mode.testFlag(CacheSkipped) && this->hasCachedData();
|
||||
if (useCachedData && (mode.testFlag(CacheFirst) || mode.testFlag(CacheOnly)))
|
||||
{
|
||||
emit loadingFinished(true, this->m_simulatorInfo);
|
||||
emit loadingFinished(true, this->getSimulator());
|
||||
return;
|
||||
}
|
||||
else if (useCachedData && mode.testFlag(CacheUntilNewer))
|
||||
@@ -118,27 +120,27 @@ namespace BlackMisc
|
||||
//! \todo currently too slow, does not make sense with that overhead
|
||||
if (!this->areModelFilesUpdated())
|
||||
{
|
||||
emit loadingFinished(true, this->m_simulatorInfo);
|
||||
emit loadingFinished(true, this->getSimulator());
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (mode.testFlag(CacheOnly))
|
||||
{
|
||||
// only cache, but we did not find any data
|
||||
emit loadingFinished(false, this->m_simulatorInfo);
|
||||
emit loadingFinished(false, this->getSimulator());
|
||||
return;
|
||||
}
|
||||
this->startLoadingFromDisk(mode, dbModels);
|
||||
}
|
||||
|
||||
const CSimulatorInfo &IAircraftModelLoader::getSimulator() const
|
||||
const CSimulatorInfo IAircraftModelLoader::getSimulator() const
|
||||
{
|
||||
return m_simulatorInfo;
|
||||
return this->m_caches.getCurrentSimulator();
|
||||
}
|
||||
|
||||
QString IAircraftModelLoader::getSimulatorAsString() const
|
||||
{
|
||||
return m_simulatorInfo.toQString();
|
||||
return this->getSimulator().toQString();
|
||||
}
|
||||
|
||||
bool IAircraftModelLoader::supportsSimulator(const CSimulatorInfo &info)
|
||||
@@ -157,10 +159,11 @@ namespace BlackMisc
|
||||
this->cancelLoading();
|
||||
}
|
||||
|
||||
std::unique_ptr<IAircraftModelLoader> IAircraftModelLoader::createModelLoader(const CSimulatorInfo &simInfo)
|
||||
std::unique_ptr<IAircraftModelLoader> IAircraftModelLoader::createModelLoader(const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Single simulator");
|
||||
std::unique_ptr<IAircraftModelLoader> loader;
|
||||
if (simInfo.xplane())
|
||||
if (simulator.xplane())
|
||||
{
|
||||
loader = std::make_unique<CAircraftModelLoaderXPlane>(
|
||||
CSimulatorInfo(CSimulatorInfo::XPLANE),
|
||||
@@ -168,10 +171,16 @@ namespace BlackMisc
|
||||
}
|
||||
else
|
||||
{
|
||||
loader = CAircraftCfgParser::createModelLoader(simInfo);
|
||||
loader = CAircraftCfgParser::createModelLoader(simulator);
|
||||
}
|
||||
|
||||
if (!loader) { return loader; }
|
||||
|
||||
// make sure the cache is really available, normally this happens in the constructor
|
||||
if (loader->getSimulator() != simulator)
|
||||
{
|
||||
loader->m_caches.setCurrentSimulator(simulator); // mark current simulator and sync caches
|
||||
}
|
||||
// make sure the cache is really available
|
||||
loader->syncronizeCache();
|
||||
return loader;
|
||||
}
|
||||
} // ns
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace BlackMisc
|
||||
virtual bool areModelFilesUpdated() const = 0;
|
||||
|
||||
//! Which simulator is supported by that very loader
|
||||
const BlackMisc::Simulation::CSimulatorInfo &getSimulator() const;
|
||||
const CSimulatorInfo getSimulator() const;
|
||||
|
||||
//! Supported simulators as string
|
||||
QString getSimulatorAsString() const;
|
||||
@@ -100,14 +100,14 @@ namespace BlackMisc
|
||||
|
||||
//! \name Implementations of the model interfaces (allows to set models modified in utility functions)
|
||||
//! @{
|
||||
virtual void setModels(const CAircraftModelList &models) override { this->setCachedModels(models, this->m_simulatorInfo); }
|
||||
virtual void updateModels(const CAircraftModelList &models) override { this->replaceOrAddCachedModels(models, this->m_simulatorInfo); }
|
||||
virtual void setModels(const CAircraftModelList &models) override { this->setCachedModels(models, this->getSimulator()); }
|
||||
virtual void updateModels(const CAircraftModelList &models) override { this->replaceOrAddCachedModels(models, this->getSimulator()); }
|
||||
virtual void setModels(const CAircraftModelList &models, const CSimulatorInfo &simulator) override { this->setCachedModels(models, simulator); }
|
||||
virtual void updateModels(const CAircraftModelList &models, const CSimulatorInfo &simulator) override { this->replaceOrAddCachedModels(models, simulator); }
|
||||
//! @}
|
||||
|
||||
//! Create a loader and syncronize caches
|
||||
static std::unique_ptr<IAircraftModelLoader> createModelLoader(const BlackMisc::Simulation::CSimulatorInfo &simInfo);
|
||||
static std::unique_ptr<IAircraftModelLoader> createModelLoader(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
public slots:
|
||||
//! Set cache from outside, this should only be used in special cases.
|
||||
@@ -124,13 +124,13 @@ namespace BlackMisc
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
IAircraftModelLoader(const CSimulatorInfo &info, const QString &rootDirectory, const QStringList &excludeDirs = {});
|
||||
IAircraftModelLoader(const CSimulatorInfo &simulator, const QString &rootDirectory, const QStringList &excludeDirs = {});
|
||||
|
||||
//! Cache timestamp
|
||||
QDateTime getCacheTimestamp() const;
|
||||
|
||||
//! Make sure cache is syncronized
|
||||
void syncronizeCache();
|
||||
bool syncronizeCache();
|
||||
|
||||
//! Any cached data?
|
||||
bool hasCachedData() const;
|
||||
@@ -144,7 +144,6 @@ namespace BlackMisc
|
||||
//! Start the loading process from disk
|
||||
virtual void startLoadingFromDisk(LoadMode mode, const BlackMisc::Simulation::CAircraftModelList &dbModels) = 0;
|
||||
|
||||
BlackMisc::Simulation::CSimulatorInfo m_simulatorInfo; //!< Corresponding simulator
|
||||
std::atomic<bool> m_cancelLoading { false }; //!< flag
|
||||
std::atomic<bool> m_loadingInProgress { false }; //!< Loading in progress
|
||||
QString m_rootDirectory; //!< root directory parsing aircraft.cfg files
|
||||
|
||||
@@ -15,11 +15,11 @@ namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
CAircraftModelSetLoader::CAircraftModelSetLoader(const CSimulatorInfo &info, QObject *parent) :
|
||||
QObject(parent),
|
||||
m_simulatorInfo(info)
|
||||
CAircraftModelSetLoader::CAircraftModelSetLoader(const CSimulatorInfo &simulator, QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
Q_ASSERT_X(info.isSingleSimulator(), Q_FUNC_INFO, "Only one simulator per loader");
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Only one simulator per loader");
|
||||
this->syncronizeCache();
|
||||
connect(&this->m_caches, &CModelSetCaches::cacheChanged, this, &CAircraftModelSetLoader::cacheChanged);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace BlackMisc
|
||||
|
||||
CStatusMessage CAircraftModelSetLoader::setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
||||
{
|
||||
const CSimulatorInfo sim = simulator.isSingleSimulator() ? simulator : this->m_simulatorInfo;
|
||||
const CSimulatorInfo sim = simulator.isSingleSimulator() ? simulator : this->m_caches.getCurrentSimulator();
|
||||
if (!sim.isSingleSimulator()) { return CStatusMessage(this, CStatusMessage::SeverityError, "Invalid simulator"); }
|
||||
const CStatusMessage m(this->m_caches.setCachedModels(models, sim));
|
||||
return m;
|
||||
@@ -39,7 +39,7 @@ namespace BlackMisc
|
||||
CStatusMessage CAircraftModelSetLoader::replaceOrAddCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
||||
{
|
||||
if (models.isEmpty()) { return CStatusMessage(this, CStatusMessage::SeverityInfo, "No data"); }
|
||||
const CSimulatorInfo sim = simulator.isSingleSimulator() ? simulator : this->m_simulatorInfo;
|
||||
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);
|
||||
@@ -56,14 +56,13 @@ namespace BlackMisc
|
||||
void CAircraftModelSetLoader::changeSimulator(const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Only one simulator per loader");
|
||||
this->m_simulatorInfo = simulator;
|
||||
this->m_caches.syncronizeCache(simulator);
|
||||
emit simulatorChanged(simulator);
|
||||
}
|
||||
|
||||
CAircraftModelList CAircraftModelSetLoader::getAircraftModels() const
|
||||
{
|
||||
return this->m_caches.getCachedModels(this->m_simulatorInfo);
|
||||
return this->m_caches.getCurrentCachedModels();
|
||||
}
|
||||
|
||||
CAircraftModelList CAircraftModelSetLoader::getAircraftModels(const CSimulatorInfo &simulator) const
|
||||
@@ -80,17 +79,17 @@ namespace BlackMisc
|
||||
|
||||
QDateTime CAircraftModelSetLoader::getCacheTimestamp() const
|
||||
{
|
||||
return this->m_caches.getCacheTimestamp(this->m_simulatorInfo);
|
||||
return this->m_caches.getCurrentCacheTimestamp();
|
||||
}
|
||||
|
||||
void CAircraftModelSetLoader::syncronizeCache()
|
||||
bool CAircraftModelSetLoader::syncronizeCache()
|
||||
{
|
||||
return this->m_caches.syncronizeCache(this->m_simulatorInfo);
|
||||
return this->m_caches.syncronizeCurrentCache();
|
||||
}
|
||||
|
||||
bool CAircraftModelSetLoader::hasCachedData() const
|
||||
{
|
||||
return !this->m_caches.getCachedModels(this->m_simulatorInfo).isEmpty();
|
||||
return !this->m_caches.getCurrentCachedModels().isEmpty();
|
||||
}
|
||||
|
||||
CStatusMessage CAircraftModelSetLoader::clearCache()
|
||||
@@ -98,14 +97,14 @@ namespace BlackMisc
|
||||
return this->setCachedModels(CAircraftModelList());
|
||||
}
|
||||
|
||||
const CSimulatorInfo &CAircraftModelSetLoader::getSimulator() const
|
||||
CSimulatorInfo CAircraftModelSetLoader::getSimulator() const
|
||||
{
|
||||
return m_simulatorInfo;
|
||||
return this->m_caches.getCurrentSimulator();
|
||||
}
|
||||
|
||||
QString CAircraftModelSetLoader::getSimulatorAsString() const
|
||||
{
|
||||
return m_simulatorInfo.toQString();
|
||||
return this->getSimulator().toQString();
|
||||
}
|
||||
|
||||
bool CAircraftModelSetLoader::supportsSimulator(const CSimulatorInfo &info)
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace BlackMisc
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
CAircraftModelSetLoader(const CSimulatorInfo &info, QObject *parent = nullptr);
|
||||
CAircraftModelSetLoader(const CSimulatorInfo &simulator, QObject *parent = nullptr);
|
||||
|
||||
//! Destructor
|
||||
virtual ~CAircraftModelSetLoader();
|
||||
@@ -62,7 +62,7 @@ namespace BlackMisc
|
||||
BlackMisc::Simulation::CAircraftModel getModelForModelString(const QString &modelString) const;
|
||||
|
||||
//! Which simulator is supported by that very loader
|
||||
const BlackMisc::Simulation::CSimulatorInfo &getSimulator() const;
|
||||
CSimulatorInfo getSimulator() const;
|
||||
|
||||
//! Supported simulators as string
|
||||
QString getSimulatorAsString() const;
|
||||
@@ -75,8 +75,8 @@ namespace BlackMisc
|
||||
|
||||
//! \name Implementations of the models interfaces
|
||||
//! @{
|
||||
virtual void setModels(const BlackMisc::Simulation::CAircraftModelList &models) override { this->setCachedModels(models, this->m_simulatorInfo); }
|
||||
virtual void updateModels(const BlackMisc::Simulation::CAircraftModelList &models) override { this->replaceOrAddCachedModels(models, this->m_simulatorInfo); }
|
||||
virtual void setModels(const BlackMisc::Simulation::CAircraftModelList &models) override { this->setCachedModels(models, this->getSimulator()); }
|
||||
virtual void updateModels(const BlackMisc::Simulation::CAircraftModelList &models) override { this->replaceOrAddCachedModels(models, this->getSimulator()); }
|
||||
virtual void setModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override { this->setCachedModels(models, simulator); }
|
||||
virtual void updateModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override { this->replaceOrAddCachedModels(models, simulator); }
|
||||
//! @}
|
||||
@@ -105,7 +105,7 @@ namespace BlackMisc
|
||||
QDateTime getCacheTimestamp() const;
|
||||
|
||||
//! Make sure cache is syncronized
|
||||
void syncronizeCache();
|
||||
bool syncronizeCache();
|
||||
|
||||
//! Any cached data?
|
||||
bool hasCachedData() const;
|
||||
@@ -113,7 +113,6 @@ namespace BlackMisc
|
||||
//! Clear cache
|
||||
BlackMisc::CStatusMessage clearCache();
|
||||
|
||||
BlackMisc::Simulation::CSimulatorInfo m_simulatorInfo; //!< Corresponding simulator
|
||||
BlackMisc::Simulation::Data::CModelSetCaches m_caches { this }; //!< caches
|
||||
};
|
||||
} // namespace
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
*/
|
||||
|
||||
#include "modelcaches.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -15,8 +18,30 @@ namespace BlackMisc
|
||||
{
|
||||
namespace Data
|
||||
{
|
||||
void IMultiSimulatorModelCaches::setModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
||||
{
|
||||
this->setCachedModels(models, simulator);
|
||||
}
|
||||
|
||||
CAircraftModelList IMultiSimulatorModelCaches::getCurrentCachedModels() const
|
||||
{
|
||||
const CSimulatorInfo sim(this->getCurrentSimulator());
|
||||
if (!sim.isSingleSimulator()) { return CAircraftModelList(); }
|
||||
return this->getCachedModels(sim);
|
||||
}
|
||||
|
||||
bool IMultiSimulatorModelCaches::syncronizeCurrentCache()
|
||||
{
|
||||
const CSimulatorInfo sim(this->getCurrentSimulator());
|
||||
if (!sim.isSingleSimulator()) { return false; }
|
||||
this->syncronizeCache(sim);
|
||||
return true;
|
||||
}
|
||||
|
||||
CModelCaches::CModelCaches(QObject *parent) : IMultiSimulatorModelCaches(parent)
|
||||
{ }
|
||||
{
|
||||
this->m_currentSimulator.synchronize();
|
||||
}
|
||||
|
||||
CAircraftModelList CModelCaches::getCachedModels(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
@@ -36,6 +61,8 @@ namespace BlackMisc
|
||||
CStatusMessage CModelCaches::setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
const CStatusMessage m = this->m_currentSimulator.set(simulator);
|
||||
if (m.isFailure()) { return m; }
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.set(models);
|
||||
@@ -48,6 +75,13 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
QDateTime IMultiSimulatorModelCaches::getCurrentCacheTimestamp() const
|
||||
{
|
||||
const CSimulatorInfo sim(this->getCurrentSimulator());
|
||||
if (!sim.isSingleSimulator()) { return QDateTime(); }
|
||||
return this->getCacheTimestamp(sim);
|
||||
}
|
||||
|
||||
QDateTime CModelCaches::getCacheTimestamp(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
@@ -66,6 +100,8 @@ namespace BlackMisc
|
||||
void CModelCaches::syncronizeCache(const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
const CStatusMessage m = this->m_currentSimulator.set(simulator);
|
||||
if (m.isFailure()) { CLogMessage::preformatted(m); }
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.synchronize(); break;
|
||||
@@ -77,8 +113,15 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
void CModelCaches::setCurrentSimulator(const CSimulatorInfo &simulator)
|
||||
{
|
||||
this->syncronizeCache(simulator);
|
||||
}
|
||||
|
||||
CModelSetCaches::CModelSetCaches(QObject *parent) : IMultiSimulatorModelCaches(parent)
|
||||
{ }
|
||||
{
|
||||
this->m_currentSimulator.synchronize();
|
||||
}
|
||||
|
||||
CAircraftModelList CModelSetCaches::getCachedModels(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
@@ -98,24 +141,24 @@ namespace BlackMisc
|
||||
CStatusMessage CModelSetCaches::setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
CAircraftModelList m(models);
|
||||
|
||||
// make sure we have a proper order
|
||||
if (m.needsOrder())
|
||||
const CStatusMessage m = this->m_currentSimulator.set(simulator);
|
||||
if (m.isFailure()) { return m; }
|
||||
CAircraftModelList orderedModels(models);
|
||||
if (orderedModels.needsOrder())
|
||||
{
|
||||
m.resetOrder();
|
||||
orderedModels.resetOrder();
|
||||
}
|
||||
else
|
||||
{
|
||||
m.sortAscendingByOrder();
|
||||
orderedModels.sortAscendingByOrder();
|
||||
}
|
||||
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.set(m);
|
||||
case CSimulatorInfo::FSX: return this->m_modelCacheFsx.set(m);
|
||||
case CSimulatorInfo::P3D: return this->m_modelCacheP3D.set(m);
|
||||
case CSimulatorInfo::XPLANE: return this->m_modelCacheXP.set(m);
|
||||
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.set(orderedModels);
|
||||
case CSimulatorInfo::FSX: return this->m_modelCacheFsx.set(orderedModels);
|
||||
case CSimulatorInfo::P3D: return this->m_modelCacheP3D.set(orderedModels);
|
||||
case CSimulatorInfo::XPLANE: return this->m_modelCacheXP.set(orderedModels);
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
return CStatusMessage();
|
||||
@@ -140,6 +183,8 @@ namespace BlackMisc
|
||||
void CModelSetCaches::syncronizeCache(const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
const CStatusMessage m = this->m_currentSimulator.set(simulator);
|
||||
if (m.isFailure()) { CLogMessage::preformatted(m); }
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.synchronize(); break;
|
||||
@@ -151,6 +196,11 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
void CModelSetCaches::setCurrentSimulator(const CSimulatorInfo &simulator)
|
||||
{
|
||||
this->syncronizeCache(simulator);
|
||||
}
|
||||
|
||||
} // ns
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -63,8 +63,14 @@ namespace BlackMisc
|
||||
//! Key in data cache
|
||||
static const char *key() { return "modelcachep3d"; }
|
||||
};
|
||||
//! @}
|
||||
|
||||
//! Last selection
|
||||
struct ModelCacheLastSelection : public BlackMisc::CDataTrait<BlackMisc::Simulation::CSimulatorInfo>
|
||||
{
|
||||
//! Key
|
||||
static const char *key() { return "modelcachelastselection"; }
|
||||
};
|
||||
//! @}
|
||||
|
||||
//! \name Caches for choosen model sets
|
||||
//! @{
|
||||
@@ -96,8 +102,14 @@ namespace BlackMisc
|
||||
//! Key in data cache
|
||||
static const char *key() { return "modelsetp3d"; }
|
||||
};
|
||||
//! @}
|
||||
|
||||
//! Last selection
|
||||
struct ModelSetLastSelection : public BlackMisc::CDataTrait<BlackMisc::Simulation::CSimulatorInfo>
|
||||
{
|
||||
//! Key
|
||||
static const char *key() { return "modelsetlastselection"; }
|
||||
};
|
||||
//! @}
|
||||
|
||||
//! Trait for vPilot derived models
|
||||
struct VPilotAircraftModels : public ModelCache
|
||||
@@ -122,30 +134,51 @@ namespace BlackMisc
|
||||
//! \threadsafe
|
||||
virtual CAircraftModelList getCachedModels(const BlackMisc::Simulation::CSimulatorInfo &simulator) const = 0;
|
||||
|
||||
//! Models
|
||||
//! \threadsafe
|
||||
CAircraftModelList getCurrentCachedModels() const;
|
||||
|
||||
//! Cache timestamp
|
||||
//! \threadsafe
|
||||
virtual QDateTime getCacheTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator) const = 0;
|
||||
|
||||
//! Last selection`s timestamp
|
||||
QDateTime getCurrentCacheTimestamp() const;
|
||||
|
||||
//! 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;
|
||||
|
||||
//! Last cache
|
||||
bool syncronizeCurrentCache();
|
||||
|
||||
//! Selected simulator
|
||||
//! \threadsafe
|
||||
virtual BlackMisc::Simulation::CSimulatorInfo getCurrentSimulator() const = 0;
|
||||
|
||||
//!Selected simulator
|
||||
virtual void setCurrentSimulator(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);
|
||||
}
|
||||
virtual void setModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
|
||||
|
||||
protected:
|
||||
//! \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)); }
|
||||
//! @}
|
||||
|
||||
signals:
|
||||
//! Cache has been changed
|
||||
void cacheChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
};
|
||||
|
||||
|
||||
//! Bundle of caches for all simulators
|
||||
//! \remark Temp. workaround
|
||||
class CModelCaches : public IMultiSimulatorModelCaches
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -160,22 +193,16 @@ namespace BlackMisc
|
||||
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;
|
||||
virtual BlackMisc::Simulation::CSimulatorInfo getCurrentSimulator() const override { return this->m_currentSimulator.getCopy(); }
|
||||
virtual void setCurrentSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
|
||||
//! @}
|
||||
|
||||
private:
|
||||
//! \todo Why can`t I keep the changed functions in IMultiSimulatorModelCaches -> C2039 not a member
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheFsx> m_modelCacheFsx {this, &CModelCaches::changedFsx }; //!< FSX cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheFs9> m_modelCacheFs9 {this, &CModelCaches::changedFs9 }; //!< FS9 cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheP3D> m_modelCacheP3D {this, &CModelCaches::changedP3D }; //!< P3D cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheFs9> m_modelCacheFs9 {this, &CModelCaches::changedFs9 }; //!< FS9 cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheP3D> m_modelCacheP3D {this, &CModelCaches::changedP3D }; //!< P3D cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheXP> 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)); }
|
||||
//! @}
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheLastSelection> m_currentSimulator {this }; //!< surrent simulator
|
||||
};
|
||||
|
||||
//! Bundle of caches for model sets of all simulators
|
||||
@@ -194,6 +221,8 @@ namespace BlackMisc
|
||||
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;
|
||||
virtual BlackMisc::Simulation::CSimulatorInfo getCurrentSimulator() const override { return this->m_currentSimulator.getCopy(); }
|
||||
virtual void setCurrentSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
|
||||
//! @}
|
||||
|
||||
private:
|
||||
@@ -202,14 +231,7 @@ namespace BlackMisc
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelSetCacheFs9> m_modelCacheFs9 {this, &CModelSetCaches::changedFs9}; //!< FS9 cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelSetCacheP3D> m_modelCacheP3D {this, &CModelSetCaches::changedP3D }; //!< P3D cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelSetCacheXP> 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)); }
|
||||
//! @}
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelSetLastSelection> m_currentSimulator { this }; //!< current simulator
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -100,11 +100,11 @@ namespace BlackMisc
|
||||
this->setCachedModels(models); // not thread safe
|
||||
}
|
||||
// currently I treat no data as error
|
||||
emit this->loadingFinished(hasData, this->m_simulatorInfo);
|
||||
emit this->loadingFinished(hasData, this->getSimulator());
|
||||
}
|
||||
else
|
||||
{
|
||||
emit this->loadingFinished(false, this->m_simulatorInfo);
|
||||
emit this->loadingFinished(false, this->getSimulator());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -120,7 +120,7 @@ namespace BlackMisc
|
||||
this->setCachedModels(models); // not thread safe
|
||||
}
|
||||
// currently I treat no data as error
|
||||
emit this->loadingFinished(hasData, this->m_simulatorInfo);
|
||||
emit this->loadingFinished(hasData, this->getSimulator());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ namespace BlackMisc
|
||||
{
|
||||
if (this->hasCachedData())
|
||||
{
|
||||
emit this->loadingFinished(true, this->m_simulatorInfo);
|
||||
emit this->loadingFinished(true, this->getSimulator());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace BlackMisc
|
||||
if (m_rootDirectory.isEmpty())
|
||||
{
|
||||
this->clearCache();
|
||||
emit loadingFinished(false, this->m_simulatorInfo);
|
||||
emit loadingFinished(false, this->getSimulator());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ namespace BlackMisc
|
||||
void CAircraftModelLoaderXPlane::updateInstalledModels(const CAircraftModelList &models)
|
||||
{
|
||||
this->setCachedModels(models);
|
||||
emit loadingFinished(true, this->m_simulatorInfo);
|
||||
emit loadingFinished(true, this->getSimulator());
|
||||
}
|
||||
|
||||
QString CAircraftModelLoaderXPlane::CSLPlane::getModelName() const
|
||||
@@ -155,7 +155,7 @@ namespace BlackMisc
|
||||
|
||||
CAircraftModel model;
|
||||
model.setModelType(CAircraftModel::TypeOwnSimulatorModel);
|
||||
model.setSimulator(m_simulatorInfo);
|
||||
model.setSimulator(this->getSimulator());
|
||||
model.setFileName(aircraftIt.filePath());
|
||||
model.setModelString(modelString);
|
||||
|
||||
@@ -208,9 +208,9 @@ namespace BlackMisc
|
||||
while (it.hasNext())
|
||||
{
|
||||
QString packageFile = it.next();
|
||||
//! \todo KB I would consider exclude dirs here CFileUtils::matchesExcludeDirectory()
|
||||
if (CFileUtils::isExcludedDirectory(it.filePath(), excludeDirectories)) { continue; }
|
||||
|
||||
QString packageFilePath = it.fileInfo().absolutePath();
|
||||
const QString packageFilePath = it.fileInfo().absolutePath();
|
||||
QFile file(packageFile);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
QString content;
|
||||
@@ -219,7 +219,7 @@ namespace BlackMisc
|
||||
content.append(ts.readAll());
|
||||
file.close();
|
||||
|
||||
auto package = parsePackageHeader(packageFilePath, content);
|
||||
const auto package = parsePackageHeader(packageFilePath, content);
|
||||
if (package.hasValidHeader()) m_cslPackages.push_back(package);
|
||||
}
|
||||
|
||||
@@ -262,7 +262,7 @@ namespace BlackMisc
|
||||
CDistributor distributor(package.name);
|
||||
model.setDistributor(distributor);
|
||||
|
||||
model.setSimulator(m_simulatorInfo);
|
||||
model.setSimulator(this->getSimulator());
|
||||
installedModels.push_back(model);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user