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:
Klaus Basan
2016-04-25 01:08:10 +02:00
parent 48bcb105cd
commit 43f9515eaa
20 changed files with 320 additions and 392 deletions

View File

@@ -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

View File

@@ -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