mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25:35 +08:00
refs #781, added admit functions for model caches
* interface constructor protected * flag for synchronize in ctor
This commit is contained in:
@@ -130,7 +130,7 @@ namespace BlackMisc
|
|||||||
//! Clear cache
|
//! Clear cache
|
||||||
BlackMisc::CStatusMessage clearCache();
|
BlackMisc::CStatusMessage clearCache();
|
||||||
|
|
||||||
BlackMisc::Simulation::Data::CModelSetCaches m_caches { this }; //!< caches
|
BlackMisc::Simulation::Data::CModelSetCaches m_caches { true, this }; //!< caches
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -79,7 +79,16 @@ namespace BlackMisc
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CModelCaches::CModelCaches(QObject *parent) : IMultiSimulatorModelCaches(parent)
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
CModelCaches::CModelCaches(bool synchronizeCache, QObject *parent) : IMultiSimulatorModelCaches(parent)
|
||||||
{
|
{
|
||||||
this->m_currentSimulator.synchronize();
|
this->m_currentSimulator.synchronize();
|
||||||
CSimulatorInfo sim(this->m_currentSimulator.get());
|
CSimulatorInfo sim(this->m_currentSimulator.get());
|
||||||
@@ -89,9 +98,17 @@ namespace BlackMisc
|
|||||||
this->m_currentSimulator.set(sim);
|
this->m_currentSimulator.set(sim);
|
||||||
CLogMessage(this).warning("Invalid simulator, reseting");
|
CLogMessage(this).warning("Invalid simulator, reseting");
|
||||||
}
|
}
|
||||||
this->synchronizeCacheImpl(sim);
|
|
||||||
const QString simStr(sim.toQString(true));
|
const QString simStr(sim.toQString(true));
|
||||||
CLogMessage(this).info("Initialized model caches to %1") << simStr;
|
if (synchronizeCache)
|
||||||
|
{
|
||||||
|
this->synchronizeCacheImpl(sim);
|
||||||
|
CLogMessage(this).info("Initialized model caches to %1") << simStr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->admitCacheImpl(sim);
|
||||||
|
CLogMessage(this).info("Admit model caches to %1") << simStr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CAircraftModelList CModelCaches::getCachedModels(const CSimulatorInfo &simulator) const
|
CAircraftModelList CModelCaches::getCachedModels(const CSimulatorInfo &simulator) const
|
||||||
@@ -152,6 +169,11 @@ namespace BlackMisc
|
|||||||
this->synchronizeCacheImpl(simulator);
|
this->synchronizeCacheImpl(simulator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CModelCaches::admitCache(const CSimulatorInfo &simulator)
|
||||||
|
{
|
||||||
|
this->admitCacheImpl(simulator);
|
||||||
|
}
|
||||||
|
|
||||||
CStatusMessage CModelCaches::setCurrentSimulator(const CSimulatorInfo &simulator)
|
CStatusMessage CModelCaches::setCurrentSimulator(const CSimulatorInfo &simulator)
|
||||||
{
|
{
|
||||||
static const CStatusMessage sameSimMsg = CStatusMessage(this).info("Same simulator");
|
static const CStatusMessage sameSimMsg = CStatusMessage(this).info("Same simulator");
|
||||||
@@ -177,7 +199,22 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CModelSetCaches::CModelSetCaches(QObject *parent) : IMultiSimulatorModelCaches(parent)
|
void CModelCaches::admitCacheImpl(const CSimulatorInfo &simulator)
|
||||||
|
{
|
||||||
|
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||||
|
switch (simulator.getSimulator())
|
||||||
|
{
|
||||||
|
case CSimulatorInfo::FS9: this->m_modelCacheFs9.admit(); break;
|
||||||
|
case CSimulatorInfo::FSX: this->m_modelCacheFsx.admit(); break;
|
||||||
|
case CSimulatorInfo::P3D: this->m_modelCacheP3D.admit(); break;
|
||||||
|
case CSimulatorInfo::XPLANE: this->m_modelCacheXP.admit(); break;
|
||||||
|
default:
|
||||||
|
Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CModelSetCaches::CModelSetCaches(bool synchronizeCache, QObject *parent) : IMultiSimulatorModelCaches(parent)
|
||||||
{
|
{
|
||||||
this->m_currentSimulator.synchronize();
|
this->m_currentSimulator.synchronize();
|
||||||
CSimulatorInfo sim(this->m_currentSimulator.get());
|
CSimulatorInfo sim(this->m_currentSimulator.get());
|
||||||
@@ -187,9 +224,18 @@ namespace BlackMisc
|
|||||||
this->m_currentSimulator.set(sim);
|
this->m_currentSimulator.set(sim);
|
||||||
CLogMessage(this).warning("Invalid simulator, reseting");
|
CLogMessage(this).warning("Invalid simulator, reseting");
|
||||||
}
|
}
|
||||||
this->synchronizeCacheImpl(sim);
|
|
||||||
const QString simStr(sim.toQString(true));
|
const QString simStr(sim.toQString(true));
|
||||||
CLogMessage(this).info("Initialized model caches to %1") << simStr;
|
if (synchronizeCache)
|
||||||
|
{
|
||||||
|
this->synchronizeCacheImpl(sim);
|
||||||
|
CLogMessage(this).info("Initialized model caches to %1") << simStr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->admitCacheImpl(sim);
|
||||||
|
CLogMessage(this).info("Admit model caches to %1") << simStr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CAircraftModelList CModelSetCaches::getCachedModels(const CSimulatorInfo &simulator) const
|
CAircraftModelList CModelSetCaches::getCachedModels(const CSimulatorInfo &simulator) const
|
||||||
@@ -252,6 +298,11 @@ namespace BlackMisc
|
|||||||
this->synchronizeCacheImpl(simulator);
|
this->synchronizeCacheImpl(simulator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CModelSetCaches::admitCache(const CSimulatorInfo &simulator)
|
||||||
|
{
|
||||||
|
this->admitCacheImpl(simulator);
|
||||||
|
}
|
||||||
|
|
||||||
CStatusMessage CModelSetCaches::setCurrentSimulator(const CSimulatorInfo &simulator)
|
CStatusMessage CModelSetCaches::setCurrentSimulator(const CSimulatorInfo &simulator)
|
||||||
{
|
{
|
||||||
static const CStatusMessage sameSimMsg = CStatusMessage(this).info("Same simulator");
|
static const CStatusMessage sameSimMsg = CStatusMessage(this).info("Same simulator");
|
||||||
@@ -276,6 +327,21 @@ namespace BlackMisc
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CModelSetCaches::admitCacheImpl(const CSimulatorInfo &simulator)
|
||||||
|
{
|
||||||
|
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||||
|
switch (simulator.getSimulator())
|
||||||
|
{
|
||||||
|
case CSimulatorInfo::FS9: this->m_modelCacheFs9.admit(); break;
|
||||||
|
case CSimulatorInfo::FSX: this->m_modelCacheFsx.admit(); break;
|
||||||
|
case CSimulatorInfo::P3D: this->m_modelCacheP3D.admit(); break;
|
||||||
|
case CSimulatorInfo::XPLANE: this->m_modelCacheXP.admit(); break;
|
||||||
|
default:
|
||||||
|
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -148,10 +148,6 @@ namespace BlackMisc
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! Construtor
|
|
||||||
IMultiSimulatorModelCaches(QObject *parent = nullptr) : QObject(parent)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
//! Models for simulator
|
//! Models for simulator
|
||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
virtual CAircraftModelList getCachedModels(const BlackMisc::Simulation::CSimulatorInfo &simulator) const = 0;
|
virtual CAircraftModelList getCachedModels(const BlackMisc::Simulation::CSimulatorInfo &simulator) const = 0;
|
||||||
@@ -160,7 +156,6 @@ namespace BlackMisc
|
|||||||
int getCachedModelsCount(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
|
int getCachedModelsCount(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
|
||||||
|
|
||||||
//! Models
|
//! Models
|
||||||
//! \todo is that threadsafe?
|
|
||||||
CAircraftModelList getSynchronizedCachedModels(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
CAircraftModelList getSynchronizedCachedModels(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||||
|
|
||||||
//! Models
|
//! Models
|
||||||
@@ -172,7 +167,6 @@ namespace BlackMisc
|
|||||||
virtual QDateTime getCacheTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator) const = 0;
|
virtual QDateTime getCacheTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator) const = 0;
|
||||||
|
|
||||||
//! Timestamp
|
//! Timestamp
|
||||||
//! \todo is that threadsafe?
|
|
||||||
QDateTime getSynchronizedTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
QDateTime getSynchronizedTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||||
|
|
||||||
//! Last selection`s timestamp
|
//! Last selection`s timestamp
|
||||||
@@ -182,13 +176,20 @@ namespace BlackMisc
|
|||||||
//! Set cache
|
//! Set cache
|
||||||
virtual BlackMisc::CStatusMessage setCachedModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0;
|
virtual BlackMisc::CStatusMessage setCachedModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0;
|
||||||
|
|
||||||
//! Synchronize
|
//! Synchronize for given simulator
|
||||||
//! \todo is that threadsafe?
|
|
||||||
virtual void synchronizeCache(const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0;
|
virtual void synchronizeCache(const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0;
|
||||||
|
|
||||||
//! Last cache
|
//! Synchronize the current
|
||||||
bool synchronizeCurrentCache();
|
bool synchronizeCurrentCache();
|
||||||
|
|
||||||
|
//! Admit the cache for given simulator
|
||||||
|
//! \threadsafe
|
||||||
|
virtual void admitCache(const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0;
|
||||||
|
|
||||||
|
//! Admit the current cache
|
||||||
|
//! \threadsafe
|
||||||
|
virtual bool admitCurrentCache();
|
||||||
|
|
||||||
//! Selected simulator
|
//! Selected simulator
|
||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
virtual BlackMisc::Simulation::CSimulatorInfo getCurrentSimulator() const = 0;
|
virtual BlackMisc::Simulation::CSimulatorInfo getCurrentSimulator() const = 0;
|
||||||
@@ -210,6 +211,10 @@ namespace BlackMisc
|
|||||||
void cacheChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
void cacheChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
//! Construtor
|
||||||
|
IMultiSimulatorModelCaches(QObject *parent = nullptr) : QObject(parent)
|
||||||
|
{ }
|
||||||
|
|
||||||
//! \name Cache has been changed
|
//! \name Cache has been changed
|
||||||
//! @{
|
//! @{
|
||||||
void changedFsx() { emitCacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FSX)); }
|
void changedFsx() { emitCacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FSX)); }
|
||||||
@@ -231,7 +236,7 @@ namespace BlackMisc
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
//! Construtor
|
//! Construtor
|
||||||
CModelCaches(QObject *parent = nullptr);
|
CModelCaches(bool synchronizeCache, QObject *parent = nullptr);
|
||||||
|
|
||||||
//! \name Interface implementations
|
//! \name Interface implementations
|
||||||
//! @{
|
//! @{
|
||||||
@@ -239,6 +244,7 @@ namespace BlackMisc
|
|||||||
virtual BlackMisc::CStatusMessage setCachedModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) 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 QDateTime getCacheTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator) const override;
|
||||||
virtual void synchronizeCache(const BlackMisc::Simulation::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 this->m_currentSimulator.get(); }
|
virtual BlackMisc::Simulation::CSimulatorInfo getCurrentSimulator() const override { return this->m_currentSimulator.get(); }
|
||||||
virtual BlackMisc::CStatusMessage setCurrentSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
|
virtual BlackMisc::CStatusMessage setCurrentSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
|
||||||
//! @}
|
//! @}
|
||||||
@@ -250,8 +256,12 @@ namespace BlackMisc
|
|||||||
BlackMisc::CData<BlackMisc::Simulation::Data::TModelCacheXP> m_modelCacheXP {this, &CModelCaches::changedXP }; //!< XP cache
|
BlackMisc::CData<BlackMisc::Simulation::Data::TModelCacheXP> m_modelCacheXP {this, &CModelCaches::changedXP }; //!< XP cache
|
||||||
BlackMisc::CData<BlackMisc::Simulation::Data::TModelCacheLastSelection> m_currentSimulator { this }; //!< current simulator
|
BlackMisc::CData<BlackMisc::Simulation::Data::TModelCacheLastSelection> m_currentSimulator { this }; //!< current simulator
|
||||||
|
|
||||||
//! Non virtaul version (used in ctor)
|
//! Non virtual version (can be used in ctor)
|
||||||
void synchronizeCacheImpl(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
void synchronizeCacheImpl(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||||
|
|
||||||
|
//! Non virtual version (can be used in ctor)
|
||||||
|
//! \threadsafe
|
||||||
|
void admitCacheImpl(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Bundle of caches for model sets of all simulators
|
//! Bundle of caches for model sets of all simulators
|
||||||
@@ -262,7 +272,7 @@ namespace BlackMisc
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
//! Construtor
|
//! Construtor
|
||||||
CModelSetCaches(QObject *parent = nullptr);
|
CModelSetCaches(bool synchronizeCache, QObject *parent = nullptr);
|
||||||
|
|
||||||
//! \name Interface implementations
|
//! \name Interface implementations
|
||||||
//! @{
|
//! @{
|
||||||
@@ -270,6 +280,7 @@ namespace BlackMisc
|
|||||||
virtual BlackMisc::CStatusMessage setCachedModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) 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 QDateTime getCacheTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator) const override;
|
||||||
virtual void synchronizeCache(const BlackMisc::Simulation::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 this->m_currentSimulator.get(); }
|
virtual BlackMisc::Simulation::CSimulatorInfo getCurrentSimulator() const override { return this->m_currentSimulator.get(); }
|
||||||
virtual BlackMisc::CStatusMessage setCurrentSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
|
virtual BlackMisc::CStatusMessage setCurrentSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
|
||||||
//! @}
|
//! @}
|
||||||
@@ -281,8 +292,12 @@ namespace BlackMisc
|
|||||||
BlackMisc::CData<BlackMisc::Simulation::Data::TModelSetCacheXP> m_modelCacheXP {this, &CModelSetCaches::changedXP }; //!< XP cache
|
BlackMisc::CData<BlackMisc::Simulation::Data::TModelSetCacheXP> m_modelCacheXP {this, &CModelSetCaches::changedXP }; //!< XP cache
|
||||||
BlackMisc::CData<BlackMisc::Simulation::Data::TModelSetLastSelection> m_currentSimulator { this }; //!< current simulator
|
BlackMisc::CData<BlackMisc::Simulation::Data::TModelSetLastSelection> m_currentSimulator { this }; //!< current simulator
|
||||||
|
|
||||||
//! Non virtaul version (used in ctor)
|
//! Non virtaul version (can be used in ctor)
|
||||||
void synchronizeCacheImpl(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
void synchronizeCacheImpl(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||||
|
|
||||||
|
//! Non virtual version (can be used in ctor)
|
||||||
|
//! \threadsafe
|
||||||
|
void admitCacheImpl(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
Reference in New Issue
Block a user