mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 15:45:46 +08:00
Ref T292, model caches changes
* no longer track "current" simulator, as this resulted in too many signals * CCentralMultiSimulatorModelCachesProvider keeping all model caches "in one memory location" * style changes
This commit is contained in:
@@ -21,11 +21,21 @@ namespace BlackMisc
|
||||
{
|
||||
namespace Data
|
||||
{
|
||||
void IMultiSimulatorModelCaches::setModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
||||
void IMultiSimulatorModelCaches::setModelsForSimulator(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
||||
{
|
||||
this->setCachedModels(models, simulator);
|
||||
}
|
||||
|
||||
int IMultiSimulatorModelCaches::updateModelsForSimulator(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
||||
{
|
||||
if (models.isEmpty()) { return 0; }
|
||||
CAircraftModelList allModels(this->getSynchronizedCachedModels(simulator));
|
||||
const int c = allModels.replaceOrAddModelsWithString(models, Qt::CaseInsensitive);
|
||||
if (c < 1) { return 0; }
|
||||
this->setCachedModels(allModels, simulator);
|
||||
return allModels.size();
|
||||
}
|
||||
|
||||
QString IMultiSimulatorModelCaches::getInfoString() const
|
||||
{
|
||||
static const QString is("FSX: %1 P3D: %2 FS9: %3 XP: %4");
|
||||
@@ -44,10 +54,9 @@ namespace BlackMisc
|
||||
return s.arg(this->getCachedModelsCount(simulator)).arg(this->getCacheTimestamp(simulator).toString("yyyy-MM-dd HH:mm:ss"));
|
||||
}
|
||||
|
||||
void IMultiSimulatorModelCaches::onLastSelectionChanged()
|
||||
void IMultiSimulatorModelCaches::gracefulShutdown()
|
||||
{
|
||||
this->synchronizeCurrentCache();
|
||||
this->emitCacheChanged(this->getCurrentSimulator());
|
||||
// void
|
||||
}
|
||||
|
||||
void IMultiSimulatorModelCaches::emitCacheChanged(const CSimulatorInfo &simulator)
|
||||
@@ -113,14 +122,6 @@ namespace BlackMisc
|
||||
return this->getCachedModels(simulator);
|
||||
}
|
||||
|
||||
CAircraftModelList IMultiSimulatorModelCaches::getCurrentCachedModels() const
|
||||
{
|
||||
const CSimulatorInfo sim(this->getCurrentSimulator());
|
||||
BLACK_VERIFY_X(sim.isSingleSimulator(), Q_FUNC_INFO, "need single simulator");
|
||||
if (!sim.isSingleSimulator()) { return CAircraftModelList(); }
|
||||
return this->getCachedModels(sim);
|
||||
}
|
||||
|
||||
QDateTime IMultiSimulatorModelCaches::getSynchronizedTimestamp(const CSimulatorInfo &simulator)
|
||||
{
|
||||
BLACK_VERIFY_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "need single simulator");
|
||||
@@ -128,24 +129,6 @@ namespace BlackMisc
|
||||
return this->getCacheTimestamp(simulator);
|
||||
}
|
||||
|
||||
bool IMultiSimulatorModelCaches::synchronizeCurrentCache()
|
||||
{
|
||||
const CSimulatorInfo sim(this->getCurrentSimulator());
|
||||
BLACK_VERIFY_X(sim.isSingleSimulator(), Q_FUNC_INFO, "need single simulator");
|
||||
if (!sim.isSingleSimulator()) { return false; }
|
||||
this->synchronizeCache(sim);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IMultiSimulatorModelCaches::admitCurrentCache()
|
||||
{
|
||||
const CSimulatorInfo sim(this->getCurrentSimulator());
|
||||
BLACK_VERIFY_X(sim.isSingleSimulator(), Q_FUNC_INFO, "need single simulator");
|
||||
if (!sim.isSingleSimulator()) { return false; }
|
||||
this->admitCache(sim);
|
||||
return true;
|
||||
}
|
||||
|
||||
CSimulatorInfo IMultiSimulatorModelCaches::simulatorsWithInitializedCache() const
|
||||
{
|
||||
static const QDateTime outdated = QDateTime::currentDateTimeUtc().addDays(-365 * 5);
|
||||
@@ -163,14 +146,7 @@ namespace BlackMisc
|
||||
|
||||
CModelCaches::CModelCaches(bool synchronizeCache, QObject *parent) : IMultiSimulatorModelCaches(parent)
|
||||
{
|
||||
m_currentSimulator.synchronize();
|
||||
CSimulatorInfo sim(m_currentSimulator.get());
|
||||
if (!sim.isSingleSimulator())
|
||||
{
|
||||
sim = BlackMisc::Simulation::CSimulatorInfo::guessDefaultSimulator();
|
||||
m_currentSimulator.set(sim);
|
||||
CLogMessage(this).warning("Invalid simulator, reseting");
|
||||
}
|
||||
const CSimulatorInfo sim = BlackMisc::Simulation::CSimulatorInfo::guessDefaultSimulator();
|
||||
const QString simStr(sim.toQString(true));
|
||||
if (synchronizeCache)
|
||||
{
|
||||
@@ -222,14 +198,6 @@ namespace BlackMisc
|
||||
this->emitCacheChanged(simulator);
|
||||
}
|
||||
|
||||
QDateTime IMultiSimulatorModelCaches::getCurrentCacheTimestamp() const
|
||||
{
|
||||
const CSimulatorInfo sim(this->getCurrentSimulator());
|
||||
BLACK_VERIFY_X(sim.isSingleSimulator(), Q_FUNC_INFO, "need single simulator");
|
||||
if (!sim.isSingleSimulator()) { return QDateTime(); }
|
||||
return this->getCacheTimestamp(sim);
|
||||
}
|
||||
|
||||
CStatusMessage IMultiSimulatorModelCaches::clearCachedModels(const CSimulatorInfo &simulator)
|
||||
{
|
||||
static const CAircraftModelList models;
|
||||
@@ -278,7 +246,7 @@ namespace BlackMisc
|
||||
case CSimulatorInfo::P3D: return m_modelCacheP3D.set(m_modelCacheP3D.get(), ts.toMSecsSinceEpoch());
|
||||
case CSimulatorInfo::XPLANE: return m_modelCacheXP.set(m_modelCacheXP.get(), ts.toMSecsSinceEpoch());
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong simulator");
|
||||
break;
|
||||
}
|
||||
return CStatusMessage();
|
||||
@@ -294,16 +262,6 @@ namespace BlackMisc
|
||||
this->admitCacheImpl(simulator);
|
||||
}
|
||||
|
||||
CStatusMessage CModelCaches::setCurrentSimulator(const CSimulatorInfo &simulator)
|
||||
{
|
||||
static const CStatusMessage sameSimMsg = CStatusMessage(this).info("Same simulator");
|
||||
const CSimulatorInfo s = m_currentSimulator.get();
|
||||
if (s == simulator) { return sameSimMsg; }
|
||||
const BlackMisc::CStatusMessage m = m_currentSimulator.set(simulator);
|
||||
this->synchronizeCache(simulator);
|
||||
return m;
|
||||
}
|
||||
|
||||
QString CModelCaches::getFilename(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
@@ -368,24 +326,17 @@ namespace BlackMisc
|
||||
|
||||
CModelSetCaches::CModelSetCaches(bool synchronizeCache, QObject *parent) : IMultiSimulatorModelCaches(parent)
|
||||
{
|
||||
m_currentSimulator.synchronize();
|
||||
CSimulatorInfo sim(m_currentSimulator.get());
|
||||
if (!sim.isSingleSimulator())
|
||||
{
|
||||
sim = BlackMisc::Simulation::CSimulatorInfo::guessDefaultSimulator();
|
||||
m_currentSimulator.set(sim);
|
||||
CLogMessage(this).warning("Invalid simulator, reseting");
|
||||
}
|
||||
CSimulatorInfo simulator = BlackMisc::Simulation::CSimulatorInfo::guessDefaultSimulator();
|
||||
const QString simStr(simulator.toQString(true));
|
||||
|
||||
const QString simStr(sim.toQString(true));
|
||||
if (synchronizeCache)
|
||||
{
|
||||
this->synchronizeCacheImpl(sim);
|
||||
this->synchronizeCacheImpl(simulator);
|
||||
CLogMessage(this).info("Initialized model caches (%1) for %2") << this->getDescription() << simStr;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->admitCacheImpl(sim);
|
||||
this->admitCacheImpl(simulator);
|
||||
CLogMessage(this).info("Admit model (%1) caches for %2") << this->getDescription() << simStr;
|
||||
}
|
||||
}
|
||||
@@ -448,7 +399,7 @@ namespace BlackMisc
|
||||
case CSimulatorInfo::P3D: return m_modelCacheP3D.getAvailableTimestamp();
|
||||
case CSimulatorInfo::XPLANE: return m_modelCacheXP.getAvailableTimestamp();
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong simulator");
|
||||
return QDateTime();
|
||||
}
|
||||
}
|
||||
@@ -464,7 +415,7 @@ namespace BlackMisc
|
||||
case CSimulatorInfo::P3D: return m_modelCacheP3D.set(m_modelCacheP3D.get(), ts.toMSecsSinceEpoch());
|
||||
case CSimulatorInfo::XPLANE: return m_modelCacheXP.set(m_modelCacheXP.get(), ts.toMSecsSinceEpoch());
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong simulator");
|
||||
break;
|
||||
}
|
||||
return CStatusMessage();
|
||||
@@ -480,16 +431,6 @@ namespace BlackMisc
|
||||
this->admitCacheImpl(simulator);
|
||||
}
|
||||
|
||||
CStatusMessage CModelSetCaches::setCurrentSimulator(const CSimulatorInfo &simulator)
|
||||
{
|
||||
static const CStatusMessage sameSimMsg = CStatusMessage(this).info("Same simulator");
|
||||
const CSimulatorInfo s = m_currentSimulator.get();
|
||||
if (s == simulator) { return sameSimMsg; }
|
||||
const BlackMisc::CStatusMessage m = m_currentSimulator.set(simulator);
|
||||
this->synchronizeCache(simulator);
|
||||
return m;
|
||||
}
|
||||
|
||||
QString CModelSetCaches::getFilename(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
@@ -500,7 +441,7 @@ namespace BlackMisc
|
||||
case CSimulatorInfo::P3D: return m_modelCacheP3D.getFilename();
|
||||
case CSimulatorInfo::XPLANE: return m_modelCacheXP.getFilename();
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong simulator");
|
||||
break;
|
||||
}
|
||||
return {};
|
||||
@@ -516,7 +457,7 @@ namespace BlackMisc
|
||||
case CSimulatorInfo::P3D: return m_modelCacheP3D.isSaved();
|
||||
case CSimulatorInfo::XPLANE: return m_modelCacheXP.isSaved();
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong simulator");
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
@@ -532,7 +473,7 @@ namespace BlackMisc
|
||||
case CSimulatorInfo::P3D: m_modelCacheP3D.synchronize(); break;
|
||||
case CSimulatorInfo::XPLANE: m_modelCacheXP.synchronize(); break;
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong simulator");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -547,10 +488,64 @@ namespace BlackMisc
|
||||
case CSimulatorInfo::P3D: m_modelCacheP3D.admit(); break;
|
||||
case CSimulatorInfo::XPLANE: m_modelCacheXP.admit(); break;
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong simulator");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CCentralMultiSimulatorModelCachesProvider &CCentralMultiSimulatorModelCachesProvider::modelCachesInstance()
|
||||
{
|
||||
static CCentralMultiSimulatorModelCachesProvider c;
|
||||
return c;
|
||||
}
|
||||
|
||||
CAircraftModelList CCentralMultiSimulatorModelCachesProvider::getCachedModels(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
return instanceCaches().getCachedModels(simulator);
|
||||
}
|
||||
|
||||
CStatusMessage CCentralMultiSimulatorModelCachesProvider::setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
||||
{
|
||||
return instanceCaches().setCachedModels(models, simulator);
|
||||
}
|
||||
|
||||
QDateTime CCentralMultiSimulatorModelCachesProvider::getCacheTimestamp(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
return instanceCaches().getCacheTimestamp(simulator);
|
||||
}
|
||||
|
||||
CStatusMessage CCentralMultiSimulatorModelCachesProvider::setCacheTimestamp(const QDateTime &ts, const CSimulatorInfo &simulator)
|
||||
{
|
||||
return instanceCaches().setCacheTimestamp(ts, simulator);
|
||||
}
|
||||
|
||||
void CCentralMultiSimulatorModelCachesProvider::synchronizeCache(const CSimulatorInfo &simulator)
|
||||
{
|
||||
return instanceCaches().synchronizeCache(simulator);
|
||||
}
|
||||
|
||||
void CCentralMultiSimulatorModelCachesProvider::admitCache(const CSimulatorInfo &simulator)
|
||||
{
|
||||
return instanceCaches().admitCache(simulator);
|
||||
}
|
||||
|
||||
QString CCentralMultiSimulatorModelCachesProvider::getFilename(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
return instanceCaches().getFilename(simulator);
|
||||
}
|
||||
|
||||
bool CCentralMultiSimulatorModelCachesProvider::isSaved(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
return instanceCaches().isSaved(simulator);
|
||||
}
|
||||
|
||||
QString CCentralMultiSimulatorModelCachesProvider::getDescription() const
|
||||
{
|
||||
return instanceCaches().getDescription();
|
||||
}
|
||||
|
||||
CCentralMultiSimulatorModelCachesProvider::CCentralMultiSimulatorModelCachesProvider(QObject *parent) : IMultiSimulatorModelCaches(parent)
|
||||
{ }
|
||||
} // ns
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace BlackMisc
|
||||
static constexpr bool isDeferred() { return true; }
|
||||
};
|
||||
|
||||
//! \name Caches for own models on disk, loaded by BlackMisc::Simulation::IAircraftModelLoader
|
||||
//! \name Caches for own models on disk, loaded by IAircraftModelLoader
|
||||
//! @{
|
||||
|
||||
//! XPlane
|
||||
@@ -68,13 +68,13 @@ namespace BlackMisc
|
||||
};
|
||||
|
||||
//! Last selection
|
||||
struct TModelCacheLastSelection : public BlackMisc::TDataTrait<BlackMisc::Simulation::CSimulatorInfo>
|
||||
struct TModelCacheLastSelection : public TDataTrait<CSimulatorInfo>
|
||||
{
|
||||
//! First load is synchronous
|
||||
static constexpr bool isPinned() { return true; }
|
||||
|
||||
//! Default simulator
|
||||
static const BlackMisc::Simulation::CSimulatorInfo &defaultValue() { return CSimulatorInfo::guessDefaultSimulator(); }
|
||||
static const CSimulatorInfo &defaultValue() { return CSimulatorInfo::guessDefaultSimulator(); }
|
||||
|
||||
//! Key
|
||||
static const char *key() { return "modelcachelastselection"; }
|
||||
@@ -113,26 +113,26 @@ namespace BlackMisc
|
||||
};
|
||||
|
||||
//! Last selection
|
||||
struct TSimulatorLastSelection : public BlackMisc::TDataTrait<BlackMisc::Simulation::CSimulatorInfo>
|
||||
struct TSimulatorLastSelection : public BlackMisc::TDataTrait<CSimulatorInfo>
|
||||
{
|
||||
//! First load is synchronous
|
||||
static constexpr bool isPinned() { return true; }
|
||||
|
||||
//! Default simulator
|
||||
static const BlackMisc::Simulation::CSimulatorInfo &defaultValue() { return CSimulatorInfo::guessDefaultSimulator(); }
|
||||
static const CSimulatorInfo &defaultValue() { return CSimulatorInfo::guessDefaultSimulator(); }
|
||||
|
||||
//! Key
|
||||
static const char *key() { return "simulatorlastselection"; }
|
||||
};
|
||||
|
||||
//! Last selections
|
||||
struct TSimulatorLastSelections : public BlackMisc::TDataTrait<BlackMisc::Simulation::CSimulatorInfo>
|
||||
struct TSimulatorLastSelections : public BlackMisc::TDataTrait<CSimulatorInfo>
|
||||
{
|
||||
//! First load is synchronous
|
||||
static constexpr bool isPinned() { return true; }
|
||||
|
||||
//! Default simulator
|
||||
static const BlackMisc::Simulation::CSimulatorInfo &defaultValue() { return CSimulatorInfo::guessDefaultSimulator(); }
|
||||
static const CSimulatorInfo &defaultValue() { return CSimulatorInfo::guessDefaultSimulator(); }
|
||||
|
||||
//! Key
|
||||
static const char *key() { return "simulatorlastselections"; }
|
||||
@@ -146,96 +146,80 @@ namespace BlackMisc
|
||||
static const char *key() { return "vpilot/models"; }
|
||||
};
|
||||
|
||||
//! Cache for multiple simulators specified by BlackMisc::Simulation::CSimulatorInfo
|
||||
//! Cache for multiple simulators specified by CSimulatorInfo
|
||||
class BLACKMISC_EXPORT IMultiSimulatorModelCaches :
|
||||
public QObject,
|
||||
public IModelsPerSimulatorSetable
|
||||
public IModelsForSimulatorSetable,
|
||||
public IModelsForSimulatorUpdatable
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(BlackMisc::Simulation::IModelsForSimulatorSetable)
|
||||
Q_INTERFACES(BlackMisc::Simulation::IModelsForSimulatorUpdatable)
|
||||
|
||||
public:
|
||||
//! Models for simulator
|
||||
//! \threadsafe
|
||||
virtual CAircraftModelList getCachedModels(const BlackMisc::Simulation::CSimulatorInfo &simulator) const = 0;
|
||||
virtual CAircraftModelList getCachedModels(const CSimulatorInfo &simulator) const = 0;
|
||||
|
||||
//! Models
|
||||
CAircraftModelList getSynchronizedCachedModels(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
//! Models
|
||||
//! \threadsafe
|
||||
CAircraftModelList getCurrentCachedModels() const;
|
||||
CAircraftModelList getSynchronizedCachedModels(const CSimulatorInfo &simulator);
|
||||
|
||||
//! Count of models for simulator
|
||||
int getCachedModelsCount(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
|
||||
int getCachedModelsCount(const CSimulatorInfo &simulator) const;
|
||||
|
||||
//! Get filename for simulator cache file
|
||||
virtual QString getFilename(const BlackMisc::Simulation::CSimulatorInfo &simulator) const = 0;
|
||||
virtual QString getFilename(const CSimulatorInfo &simulator) const = 0;
|
||||
|
||||
//! Has the other version the file?
|
||||
bool hasOtherVersionFile(const BlackMisc::CApplicationInfo &info, const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
|
||||
bool hasOtherVersionFile(const BlackMisc::CApplicationInfo &info, const CSimulatorInfo &simulator) const;
|
||||
|
||||
//! Simulators of given other versionwhich have a cache file
|
||||
BlackMisc::Simulation::CSimulatorInfo otherVersionSimulatorsWithFile(const BlackMisc::CApplicationInfo &info) const;
|
||||
CSimulatorInfo otherVersionSimulatorsWithFile(const BlackMisc::CApplicationInfo &info) const;
|
||||
|
||||
//! All file names
|
||||
virtual QStringList getAllFilenames() const;
|
||||
|
||||
//! Simulator which uses cache with filename
|
||||
BlackMisc::Simulation::CSimulatorInfo getSimulatorForFilename(const QString &filename) const;
|
||||
CSimulatorInfo getSimulatorForFilename(const QString &filename) const;
|
||||
|
||||
//! Cache timestamp
|
||||
//! \threadsafe
|
||||
virtual QDateTime getCacheTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator) const = 0;
|
||||
virtual QDateTime getCacheTimestamp(const CSimulatorInfo &simulator) const = 0;
|
||||
|
||||
//! Set cache timestamp
|
||||
virtual BlackMisc::CStatusMessage setCacheTimestamp(const QDateTime &ts, const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0;
|
||||
virtual CStatusMessage setCacheTimestamp(const QDateTime &ts, const CSimulatorInfo &simulator) = 0;
|
||||
|
||||
//! Cache saved?
|
||||
//! \threadsafe
|
||||
virtual bool isSaved(const BlackMisc::Simulation::CSimulatorInfo &simulator) const = 0;
|
||||
virtual bool isSaved(const CSimulatorInfo &simulator) const = 0;
|
||||
|
||||
//! Initialized caches for which simulator?
|
||||
//! \threadsafe
|
||||
BlackMisc::Simulation::CSimulatorInfo simulatorsWithInitializedCache() const;
|
||||
CSimulatorInfo simulatorsWithInitializedCache() const;
|
||||
|
||||
//! Timestamp
|
||||
QDateTime getSynchronizedTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
//! Last selection`s timestamp
|
||||
//! \threadsafe
|
||||
QDateTime getCurrentCacheTimestamp() const;
|
||||
QDateTime getSynchronizedTimestamp(const CSimulatorInfo &simulator);
|
||||
|
||||
//! Set cached models
|
||||
//! \threadsafe
|
||||
virtual BlackMisc::CStatusMessage setCachedModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0;
|
||||
virtual CStatusMessage setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator) = 0;
|
||||
|
||||
//! Clear cached models
|
||||
//! \threadsafe
|
||||
virtual BlackMisc::CStatusMessage clearCachedModels(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
virtual CStatusMessage clearCachedModels(const CSimulatorInfo &simulator);
|
||||
|
||||
//! Synchronize for given simulator
|
||||
virtual void synchronizeCache(const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0;
|
||||
|
||||
//! Synchronize the current
|
||||
bool synchronizeCurrentCache();
|
||||
virtual void synchronizeCache(const CSimulatorInfo &simulator) = 0;
|
||||
|
||||
//! Admit the cache for given simulator
|
||||
//! \threadsafe
|
||||
virtual void admitCache(const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0;
|
||||
virtual void admitCache(const CSimulatorInfo &simulator) = 0;
|
||||
|
||||
//! Admit the current cache
|
||||
//! \threadsafe
|
||||
virtual bool admitCurrentCache();
|
||||
//! \copydoc IModelsForSimulatorSetable::setModels
|
||||
virtual void setModelsForSimulator(const CAircraftModelList &models, const CSimulatorInfo &simulator) override;
|
||||
|
||||
//! Selected simulator
|
||||
//! \threadsafe
|
||||
virtual BlackMisc::Simulation::CSimulatorInfo getCurrentSimulator() const = 0;
|
||||
|
||||
//! Selected simulator
|
||||
virtual BlackMisc::CStatusMessage setCurrentSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0;
|
||||
|
||||
//! \copydoc IModelsPerSimulatorSetable::setModels
|
||||
virtual void setModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
|
||||
//! \copydoc IModelsForSimulatorUpdatable::updateModels
|
||||
virtual int updateModelsForSimulator(const CAircraftModelList &models, const CSimulatorInfo &simulator) override;
|
||||
|
||||
//! Info string about models in cache
|
||||
QString getInfoString() const;
|
||||
@@ -246,12 +230,15 @@ namespace BlackMisc
|
||||
//! Cache count and timestamp
|
||||
QString getCacheCountAndTimestamp(const CSimulatorInfo &simulator) const;
|
||||
|
||||
//! Graceful shutdown
|
||||
virtual void gracefulShutdown();
|
||||
|
||||
//! Descriptive text
|
||||
virtual QString getDescription() const = 0;
|
||||
|
||||
signals:
|
||||
//! Cache has been changed
|
||||
void cacheChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
void cacheChanged(const CSimulatorInfo &simulator);
|
||||
|
||||
protected:
|
||||
//! Construtor
|
||||
@@ -260,17 +247,14 @@ namespace BlackMisc
|
||||
|
||||
//! \name Cache has been changed. This will only detect changes elsewhere, owned caches will not signal local changes
|
||||
//! @{
|
||||
void changedFsx() { emitCacheChanged(BlackMisc::Simulation::CSimulatorInfo::fsx()); }
|
||||
void changedFs9() { emitCacheChanged(BlackMisc::Simulation::CSimulatorInfo::fs9()); }
|
||||
void changedP3D() { emitCacheChanged(BlackMisc::Simulation::CSimulatorInfo::p3d()); }
|
||||
void changedXP() { emitCacheChanged(BlackMisc::Simulation::CSimulatorInfo::xplane()); }
|
||||
void changedFsx() { emitCacheChanged(CSimulatorInfo::fsx()); }
|
||||
void changedFs9() { emitCacheChanged(CSimulatorInfo::fs9()); }
|
||||
void changedP3D() { emitCacheChanged(CSimulatorInfo::p3d()); }
|
||||
void changedXP() { emitCacheChanged(CSimulatorInfo::xplane()); }
|
||||
//! @}
|
||||
|
||||
//! Void version of synchronizeCurrentCache
|
||||
void onLastSelectionChanged();
|
||||
|
||||
//! Emit cacheChanged() utility function (allows breakpoint)
|
||||
void emitCacheChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
void emitCacheChanged(const CSimulatorInfo &simulator);
|
||||
};
|
||||
|
||||
//! Bundle of caches for all simulators
|
||||
@@ -288,32 +272,29 @@ namespace BlackMisc
|
||||
|
||||
//! \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 CAircraftModelList getCachedModels(const CSimulatorInfo &simulator) const override;
|
||||
virtual CStatusMessage setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator) override;
|
||||
virtual QDateTime getCacheTimestamp(const CSimulatorInfo &simulator) const override;
|
||||
virtual CStatusMessage setCacheTimestamp(const QDateTime &ts, const CSimulatorInfo &simulator) override;
|
||||
virtual void synchronizeCache(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
|
||||
virtual void admitCache(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
|
||||
virtual BlackMisc::Simulation::CSimulatorInfo getCurrentSimulator() const override { return m_currentSimulator.get(); }
|
||||
virtual BlackMisc::CStatusMessage setCurrentSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
|
||||
virtual QString getFilename(const BlackMisc::Simulation::CSimulatorInfo &simulator) const override;
|
||||
virtual bool isSaved(const BlackMisc::Simulation::CSimulatorInfo &simulator) const override;
|
||||
virtual void synchronizeCache(const CSimulatorInfo &simulator) override;
|
||||
virtual void admitCache(const CSimulatorInfo &simulator) override;
|
||||
virtual QString getFilename(const CSimulatorInfo &simulator) const override;
|
||||
virtual bool isSaved(const CSimulatorInfo &simulator) const override;
|
||||
virtual QString getDescription() const override { return "Model caches"; }
|
||||
//! @}
|
||||
|
||||
private:
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::TModelCacheFsx> m_modelCacheFsx {this, &CModelCaches::changedFsx }; //!< FSX cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::TModelCacheFs9> m_modelCacheFs9 {this, &CModelCaches::changedFs9 }; //!< FS9 cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::TModelCacheP3D> m_modelCacheP3D {this, &CModelCaches::changedP3D }; //!< P3D cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::TModelCacheXP> m_modelCacheXP {this, &CModelCaches::changedXP }; //!< XP cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::TModelCacheLastSelection> m_currentSimulator { this, &CModelCaches::onLastSelectionChanged }; //!< current simulator
|
||||
CData<Data::TModelCacheFsx> m_modelCacheFsx {this, &CModelCaches::changedFsx }; //!< FSX cache
|
||||
CData<Data::TModelCacheFs9> m_modelCacheFs9 {this, &CModelCaches::changedFs9 }; //!< FS9 cache
|
||||
CData<Data::TModelCacheP3D> m_modelCacheP3D {this, &CModelCaches::changedP3D }; //!< P3D cache
|
||||
CData<Data::TModelCacheXP> m_modelCacheXP {this, &CModelCaches::changedXP }; //!< XP cache
|
||||
|
||||
//! Non virtual version (can be used in ctor)
|
||||
void synchronizeCacheImpl(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
void synchronizeCacheImpl(const CSimulatorInfo &simulator);
|
||||
|
||||
//! Non virtual version (can be used in ctor)
|
||||
//! \threadsafe
|
||||
void admitCacheImpl(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
void admitCacheImpl(const CSimulatorInfo &simulator);
|
||||
};
|
||||
|
||||
//! Bundle of caches for model sets of all simulators
|
||||
@@ -331,32 +312,70 @@ namespace BlackMisc
|
||||
|
||||
//! \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 CAircraftModelList getCachedModels(const CSimulatorInfo &simulator) const override;
|
||||
virtual CStatusMessage setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator) override;
|
||||
virtual QDateTime getCacheTimestamp(const CSimulatorInfo &simulator) const override;
|
||||
virtual CStatusMessage setCacheTimestamp(const QDateTime &ts, const CSimulatorInfo &simulator) override;
|
||||
virtual void synchronizeCache(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
|
||||
virtual void admitCache(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
|
||||
virtual BlackMisc::Simulation::CSimulatorInfo getCurrentSimulator() const override { return m_currentSimulator.get(); }
|
||||
virtual BlackMisc::CStatusMessage setCurrentSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
|
||||
virtual QString getFilename(const BlackMisc::Simulation::CSimulatorInfo &simulator) const override;
|
||||
virtual bool isSaved(const BlackMisc::Simulation::CSimulatorInfo &simulator) const override;
|
||||
virtual void synchronizeCache(const CSimulatorInfo &simulator) override;
|
||||
virtual void admitCache(const CSimulatorInfo &simulator) override;
|
||||
virtual QString getFilename(const CSimulatorInfo &simulator) const override;
|
||||
virtual bool isSaved(const CSimulatorInfo &simulator) const override;
|
||||
virtual QString getDescription() const override { return "Model sets"; }
|
||||
//! @}
|
||||
|
||||
private:
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::TModelSetCacheFsx> m_modelCacheFsx {this, &CModelSetCaches::changedFsx }; //!< FSX cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::TModelSetCacheFs9> m_modelCacheFs9 {this, &CModelSetCaches::changedFs9}; //!< FS9 cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::TModelSetCacheP3D> m_modelCacheP3D {this, &CModelSetCaches::changedP3D }; //!< P3D cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::TModelSetCacheXP> m_modelCacheXP {this, &CModelSetCaches::changedXP }; //!< XP cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::TModelCacheLastSelection> m_currentSimulator { this, &CModelSetCaches::onLastSelectionChanged }; //!< current simulator
|
||||
CData<Data::TModelSetCacheFsx> m_modelCacheFsx {this, &CModelSetCaches::changedFsx }; //!< FSX cache
|
||||
CData<Data::TModelSetCacheFs9> m_modelCacheFs9 {this, &CModelSetCaches::changedFs9}; //!< FS9 cache
|
||||
CData<Data::TModelSetCacheP3D> m_modelCacheP3D {this, &CModelSetCaches::changedP3D }; //!< P3D cache
|
||||
CData<Data::TModelSetCacheXP> m_modelCacheXP {this, &CModelSetCaches::changedXP }; //!< XP cache
|
||||
|
||||
//! Non virtual version (can be used in ctor)
|
||||
void synchronizeCacheImpl(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
void synchronizeCacheImpl(const CSimulatorInfo &simulator);
|
||||
|
||||
//! Non virtual version (can be used in ctor)
|
||||
//! \threadsafe
|
||||
void admitCacheImpl(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
void admitCacheImpl(const CSimulatorInfo &simulator);
|
||||
};
|
||||
|
||||
//! One central instance of the caches
|
||||
class BLACKMISC_EXPORT CCentralMultiSimulatorModelCachesProvider : public IMultiSimulatorModelCaches
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(BlackMisc::Simulation::IModelsForSimulatorSetable)
|
||||
Q_INTERFACES(BlackMisc::Simulation::IModelsForSimulatorUpdatable)
|
||||
|
||||
public:
|
||||
//! Central instance
|
||||
static CCentralMultiSimulatorModelCachesProvider &modelCachesInstance();
|
||||
|
||||
//! \name Interface implementations
|
||||
//! @{
|
||||
virtual CAircraftModelList getCachedModels(const CSimulatorInfo &simulator) const override;
|
||||
virtual CStatusMessage setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator) override;
|
||||
virtual QDateTime getCacheTimestamp(const CSimulatorInfo &simulator) const override;
|
||||
virtual CStatusMessage setCacheTimestamp(const QDateTime &ts, const CSimulatorInfo &simulator) override;
|
||||
virtual void synchronizeCache(const CSimulatorInfo &simulator) override;
|
||||
virtual void admitCache(const CSimulatorInfo &simulator) override;
|
||||
virtual QString getFilename(const CSimulatorInfo &simulator) const override;
|
||||
virtual bool isSaved(const CSimulatorInfo &simulator) const override;
|
||||
virtual QString getDescription() const override;
|
||||
//! @}
|
||||
|
||||
protected:
|
||||
//! Ctor
|
||||
CCentralMultiSimulatorModelCachesProvider(QObject *parent = nullptr);
|
||||
|
||||
private:
|
||||
CModelCaches m_caches { this }; //!< the caches
|
||||
|
||||
//! Singleton caches
|
||||
CModelCaches &instanceCaches() { return this->isInstance() ? m_caches : modelCachesInstance().m_caches; }
|
||||
|
||||
//! Singleton caches
|
||||
const CModelCaches &instanceCaches() const { return this->isInstance() ? m_caches : modelCachesInstance().m_caches; }
|
||||
|
||||
//! Is this object the central instance?
|
||||
bool isInstance() const { return this == &modelCachesInstance(); }
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Reference in New Issue
Block a user