mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 16:56:53 +08:00
refs #906, utility functions in simulator info and model caches
This commit is contained in:
committed by
Mathew Sutcliffe
parent
b0aa713a2e
commit
2b50fe1fdb
@@ -10,7 +10,6 @@
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/verify.h"
|
||||
#include "blackmisc/simulation/data/modelcaches.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
using namespace BlackMisc;
|
||||
@@ -48,6 +47,25 @@ namespace BlackMisc
|
||||
return this->getCachedModels(simulator).size();
|
||||
}
|
||||
|
||||
CSimulatorInfo IMultiSimulatorModelCaches::getSimulatorForFilename(const QString &filename) const
|
||||
{
|
||||
if (filename.isEmpty()) return CSimulatorInfo();
|
||||
CSimulatorInfo sims;
|
||||
const QString compareFileName(QFileInfo(filename).fileName());
|
||||
for (const CSimulatorInfo &singleSim : CSimulatorInfo::allSimulatorsSet())
|
||||
{
|
||||
const QString singleSimFile(getFilename(singleSim));
|
||||
if (singleSimFile.isEmpty()) continue;
|
||||
const QString singleSimFileName(QFileInfo(singleSimFile).fileName());
|
||||
if (singleSimFileName == compareFileName)
|
||||
{
|
||||
sims.add(singleSim);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return sims;
|
||||
}
|
||||
|
||||
CAircraftModelList IMultiSimulatorModelCaches::getSynchronizedCachedModels(const CSimulatorInfo &simulator)
|
||||
{
|
||||
BLACK_VERIFY_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "need single simulator");
|
||||
@@ -185,6 +203,23 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
CStatusMessage CModelCaches::setCacheTimestamp(const QDateTime &ts, const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
if (!ts.isValid()) { return CStatusMessage(this).error("Invalid timestamp for '%1'") << simulator.toQString() ; }
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.set(m_modelCacheFs9.get(), ts.toMSecsSinceEpoch());
|
||||
case CSimulatorInfo::FSX: return this->m_modelCacheFsx.set(m_modelCacheFsx.get(), ts.toMSecsSinceEpoch());
|
||||
case CSimulatorInfo::P3D: return this->m_modelCacheP3D.set(m_modelCacheP3D.get(), ts.toMSecsSinceEpoch());
|
||||
case CSimulatorInfo::XPLANE: return this->m_modelCacheXP.set(m_modelCacheXP.get(), ts.toMSecsSinceEpoch());
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
break;
|
||||
}
|
||||
return CStatusMessage();
|
||||
}
|
||||
|
||||
void CModelCaches::synchronizeCache(const CSimulatorInfo &simulator)
|
||||
{
|
||||
this->synchronizeCacheImpl(simulator);
|
||||
@@ -205,6 +240,38 @@ namespace BlackMisc
|
||||
return m;
|
||||
}
|
||||
|
||||
QString CModelCaches::getFilename(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.getFilename();
|
||||
case CSimulatorInfo::FSX: return this->m_modelCacheFsx.getFilename();
|
||||
case CSimulatorInfo::P3D: return this->m_modelCacheP3D.getFilename();
|
||||
case CSimulatorInfo::XPLANE: return this->m_modelCacheXP.getFilename();
|
||||
default:
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator");
|
||||
break;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
bool CModelCaches::isSaved(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.isSaved();
|
||||
case CSimulatorInfo::FSX: return this->m_modelCacheFsx.isSaved();
|
||||
case CSimulatorInfo::P3D: return this->m_modelCacheP3D.isSaved();
|
||||
case CSimulatorInfo::XPLANE: return this->m_modelCacheXP.isSaved();
|
||||
default:
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator");
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CModelCaches::synchronizeCacheImpl(const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
@@ -320,6 +387,23 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
CStatusMessage CModelSetCaches::setCacheTimestamp(const QDateTime &ts, const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
if (!ts.isValid()) { return CStatusMessage(this).error("Invalid timestamp for '%1'") << simulator.toQString() ; }
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.set(m_modelCacheFs9.get(), ts.toMSecsSinceEpoch());
|
||||
case CSimulatorInfo::FSX: return this->m_modelCacheFsx.set(m_modelCacheFsx.get(), ts.toMSecsSinceEpoch());
|
||||
case CSimulatorInfo::P3D: return this->m_modelCacheP3D.set(m_modelCacheP3D.get(), ts.toMSecsSinceEpoch());
|
||||
case CSimulatorInfo::XPLANE: return this->m_modelCacheXP.set(m_modelCacheXP.get(), ts.toMSecsSinceEpoch());
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
break;
|
||||
}
|
||||
return CStatusMessage();
|
||||
}
|
||||
|
||||
void CModelSetCaches::synchronizeCache(const CSimulatorInfo &simulator)
|
||||
{
|
||||
this->synchronizeCacheImpl(simulator);
|
||||
@@ -340,6 +424,38 @@ namespace BlackMisc
|
||||
return m;
|
||||
}
|
||||
|
||||
QString CModelSetCaches::getFilename(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.getFilename();
|
||||
case CSimulatorInfo::FSX: return this->m_modelCacheFsx.getFilename();
|
||||
case CSimulatorInfo::P3D: return this->m_modelCacheP3D.getFilename();
|
||||
case CSimulatorInfo::XPLANE: return this->m_modelCacheXP.getFilename();
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
break;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
bool CModelSetCaches::isSaved(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.isSaved();
|
||||
case CSimulatorInfo::FSX: return this->m_modelCacheFsx.isSaved();
|
||||
case CSimulatorInfo::P3D: return this->m_modelCacheP3D.isSaved();
|
||||
case CSimulatorInfo::XPLANE: return this->m_modelCacheXP.isSaved();
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CModelSetCaches::synchronizeCacheImpl(const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
|
||||
Reference in New Issue
Block a user