mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-16 18:35:35 +08:00
Ref T231, improved logger
* independent mutexes * utility functions * max. values
This commit is contained in:
@@ -47,17 +47,20 @@ namespace BlackMisc
|
|||||||
|
|
||||||
CWorker *CInterpolationLogger::writeLogInBackground()
|
CWorker *CInterpolationLogger::writeLogInBackground()
|
||||||
{
|
{
|
||||||
QList<SituationLog> interpolation;
|
QList<SituationLog> situations;
|
||||||
QList<PartsLog> parts;
|
QList<PartsLog> parts;
|
||||||
{
|
{
|
||||||
QReadLocker l(&m_lockLogs);
|
QReadLocker l(&m_lockSituations);
|
||||||
interpolation = m_situationLogs;
|
situations = m_situationLogs;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
QReadLocker l(&m_lockParts);
|
||||||
parts = m_partsLogs;
|
parts = m_partsLogs;
|
||||||
}
|
}
|
||||||
|
|
||||||
CWorker *worker = CWorker::fromTask(this, "WriteInterpolationLog", [interpolation, parts]()
|
CWorker *worker = CWorker::fromTask(this, "WriteInterpolationLog", [situations, parts]()
|
||||||
{
|
{
|
||||||
const CStatusMessageList msg = CInterpolationLogger::writeLogFile(interpolation, parts);
|
const CStatusMessageList msg = CInterpolationLogger::writeLogFile(situations, parts);
|
||||||
CLogMessage::preformatted(msg);
|
CLogMessage::preformatted(msg);
|
||||||
});
|
});
|
||||||
return worker;
|
return worker;
|
||||||
@@ -127,14 +130,88 @@ namespace BlackMisc
|
|||||||
|
|
||||||
void CInterpolationLogger::logInterpolation(const CInterpolationLogger::SituationLog &log)
|
void CInterpolationLogger::logInterpolation(const CInterpolationLogger::SituationLog &log)
|
||||||
{
|
{
|
||||||
QWriteLocker l(&m_lockLogs);
|
QWriteLocker l(&m_lockSituations);
|
||||||
m_situationLogs.append(log);
|
m_situationLogs.push_back(log);
|
||||||
|
if (m_situationLogs.size() > m_maxSituations)
|
||||||
|
{
|
||||||
|
m_situationLogs.removeFirst();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CInterpolationLogger::logParts(const CInterpolationLogger::PartsLog &parts)
|
void CInterpolationLogger::logParts(const CInterpolationLogger::PartsLog &log)
|
||||||
{
|
{
|
||||||
QWriteLocker l(&m_lockLogs);
|
QWriteLocker l(&m_lockParts);
|
||||||
m_partsLogs.append(parts);
|
m_partsLogs.push_back(log);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CInterpolationLogger::setMaxSituations(int max)
|
||||||
|
{
|
||||||
|
QReadLocker l(&m_lockSituations);
|
||||||
|
m_maxSituations = max;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<CInterpolationLogger::SituationLog> CInterpolationLogger::getSituationsLog() const
|
||||||
|
{
|
||||||
|
QReadLocker l(&m_lockSituations);
|
||||||
|
return m_situationLogs;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<CInterpolationLogger::PartsLog> CInterpolationLogger::getPartsLog() const
|
||||||
|
{
|
||||||
|
QReadLocker l(&m_lockParts);
|
||||||
|
return m_partsLogs;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<CInterpolationLogger::SituationLog> CInterpolationLogger::getSituationsLog(const CCallsign &cs) const
|
||||||
|
{
|
||||||
|
const QList<SituationLog> copy(this->getSituationsLog());
|
||||||
|
QList<SituationLog> logs;
|
||||||
|
for (const SituationLog &log : copy)
|
||||||
|
{
|
||||||
|
if (log.callsign != cs) { continue; }
|
||||||
|
logs.push_back(log);
|
||||||
|
}
|
||||||
|
return logs;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<CInterpolationLogger::PartsLog> CInterpolationLogger::getPartsLog(const CCallsign &cs) const
|
||||||
|
{
|
||||||
|
const QList<PartsLog> copy(this->getPartsLog());
|
||||||
|
QList<PartsLog> logs;
|
||||||
|
for (const PartsLog &log : copy)
|
||||||
|
{
|
||||||
|
if (log.callsign != cs) { continue; }
|
||||||
|
logs.push_back(log);
|
||||||
|
}
|
||||||
|
return logs;
|
||||||
|
}
|
||||||
|
|
||||||
|
CAircraftSituation CInterpolationLogger::getLastSituation() const
|
||||||
|
{
|
||||||
|
QReadLocker l(&m_lockSituations);
|
||||||
|
if (m_situationLogs.isEmpty()) { return CAircraftSituation(); }
|
||||||
|
return m_situationLogs.last().currentSituation;
|
||||||
|
}
|
||||||
|
|
||||||
|
CAircraftSituation CInterpolationLogger::getLastSituation(const CCallsign &cs) const
|
||||||
|
{
|
||||||
|
const QList<SituationLog> copy(this->getSituationsLog(cs));
|
||||||
|
if (copy.isEmpty()) { return CAircraftSituation(); }
|
||||||
|
return copy.last().currentSituation;
|
||||||
|
}
|
||||||
|
|
||||||
|
CAircraftParts CInterpolationLogger::getLastParts() const
|
||||||
|
{
|
||||||
|
QReadLocker l(&m_lockParts);
|
||||||
|
if (m_partsLogs.isEmpty()) { return CAircraftParts(); }
|
||||||
|
return m_partsLogs.last().parts;
|
||||||
|
}
|
||||||
|
|
||||||
|
CAircraftParts CInterpolationLogger::getLastParts(const CCallsign &cs) const
|
||||||
|
{
|
||||||
|
const QList<PartsLog> copy(this->getPartsLog(cs));
|
||||||
|
if (copy.isEmpty()) { return CAircraftParts(); }
|
||||||
|
return copy.last().parts;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString &CInterpolationLogger::filePatternInterpolationLog()
|
const QString &CInterpolationLogger::filePatternInterpolationLog()
|
||||||
@@ -269,9 +346,14 @@ namespace BlackMisc
|
|||||||
|
|
||||||
void CInterpolationLogger::clearLog()
|
void CInterpolationLogger::clearLog()
|
||||||
{
|
{
|
||||||
QWriteLocker l(&m_lockLogs);
|
{
|
||||||
m_partsLogs.clear();
|
QWriteLocker l(&m_lockSituations);
|
||||||
m_situationLogs.clear();
|
m_situationLogs.clear();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
QWriteLocker l(&m_lockParts);
|
||||||
|
m_partsLogs.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CInterpolationLogger::msSinceEpochToTime(qint64 ms)
|
QString CInterpolationLogger::msSinceEpochToTime(qint64 ms)
|
||||||
|
|||||||
@@ -87,7 +87,42 @@ namespace BlackMisc
|
|||||||
//! Log current parts cycle, only stores in memory, for performance reasons
|
//! Log current parts cycle, only stores in memory, for performance reasons
|
||||||
//! \remark const to allow const interpolator functions
|
//! \remark const to allow const interpolator functions
|
||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
void logParts(const PartsLog &parts);
|
void logParts(const PartsLog &log);
|
||||||
|
|
||||||
|
//! Max.situations logged
|
||||||
|
void setMaxSituations(int max);
|
||||||
|
|
||||||
|
//! All situation logs
|
||||||
|
//! \threadsafe
|
||||||
|
QList<SituationLog> getSituationsLog() const;
|
||||||
|
|
||||||
|
//! All parts logs
|
||||||
|
//! \threadsafe
|
||||||
|
QList<PartsLog> getPartsLog() const;
|
||||||
|
|
||||||
|
//! All situation logs for callsign
|
||||||
|
//! \threadsafe
|
||||||
|
QList<SituationLog> getSituationsLog(const Aviation::CCallsign &cs) const;
|
||||||
|
|
||||||
|
//! All parts logs for callsign
|
||||||
|
//! \threadsafe
|
||||||
|
QList<PartsLog> getPartsLog(const Aviation::CCallsign &cs) const;
|
||||||
|
|
||||||
|
//! Get last situation
|
||||||
|
//! \threadsafe
|
||||||
|
Aviation::CAircraftSituation getLastSituation() const;
|
||||||
|
|
||||||
|
//! Get last situation
|
||||||
|
//! \threadsafe
|
||||||
|
Aviation::CAircraftSituation getLastSituation(const Aviation::CCallsign &cs) const;
|
||||||
|
|
||||||
|
//! Get last parts
|
||||||
|
//! \threadsafe
|
||||||
|
Aviation::CAircraftParts getLastParts() const;
|
||||||
|
|
||||||
|
//! Get last parts
|
||||||
|
//! \threadsafe
|
||||||
|
Aviation::CAircraftParts getLastParts(const Aviation::CCallsign &cs) const;
|
||||||
|
|
||||||
//! File pattern for interpolation log
|
//! File pattern for interpolation log
|
||||||
static const QString &filePatternInterpolationLog();
|
static const QString &filePatternInterpolationLog();
|
||||||
@@ -100,13 +135,13 @@ namespace BlackMisc
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
//! Get log as HTML table
|
//! Get log as HTML table
|
||||||
static QString getHtmlInterpolationLog(const QList<SituationLog> &logs);
|
static QString getHtmlInterpolationLog(const QList<SituationLog> &getSituationsLog);
|
||||||
|
|
||||||
//! Get log as HTML table
|
//! Get log as HTML table
|
||||||
static QString getHtmlPartsLog(const QList<PartsLog> &logs);
|
static QString getHtmlPartsLog(const QList<PartsLog> &getSituationsLog);
|
||||||
|
|
||||||
//! Write log to file
|
//! Write log to file
|
||||||
static CStatusMessageList writeLogFile(const QList<SituationLog> &interpolation, const QList<PartsLog> &parts);
|
static CStatusMessageList writeLogFile(const QList<SituationLog> &interpolation, const QList<PartsLog> &getPartsLog);
|
||||||
|
|
||||||
//! Status of file operation
|
//! Status of file operation
|
||||||
static CStatusMessage logStatusFileWriting(bool success, const QString &fileName);
|
static CStatusMessage logStatusFileWriting(bool success, const QString &fileName);
|
||||||
@@ -117,9 +152,11 @@ namespace BlackMisc
|
|||||||
//! Create readable time
|
//! Create readable time
|
||||||
static QString msSinceEpochToTime(qint64 t1, qint64 t2, qint64 t3 = -1);
|
static QString msSinceEpochToTime(qint64 t1, qint64 t2, qint64 t3 = -1);
|
||||||
|
|
||||||
mutable QReadWriteLock m_lockLogs; //!< lock logging
|
mutable QReadWriteLock m_lockSituations; //!< lock logging
|
||||||
QList<PartsLog> m_partsLogs; //!< logs of parts
|
mutable QReadWriteLock m_lockParts; //!< lock logging
|
||||||
QList<SituationLog> m_situationLogs; //!< logs of interpolation
|
int m_maxSituations = 2500;
|
||||||
|
QList<PartsLog> m_partsLogs; //!< logs of parts
|
||||||
|
QList<SituationLog> m_situationLogs; //!< logs of interpolation
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user