mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 08:36:52 +08:00
refs #316 Removed old logging mechanism in contexts.
This commit is contained in:
@@ -20,278 +20,12 @@ namespace BlackCore
|
||||
*/
|
||||
CRuntime::CRuntime(const CRuntimeConfig &config, QObject *parent) :
|
||||
QObject(parent), m_init(false), m_dbusServer(nullptr), m_initDBusConnection(false),
|
||||
m_signalLogApplication(false), m_signalLogAudio(false), m_signalLogNetwork(false), m_signalLogOwnAircraft(false), m_signalLogSettings(false), m_signalLogSimulator(false),
|
||||
m_slotLogApplication(false), m_slotLogAudio(false), m_slotLogNetwork(false), m_slotLogOwnAircraft(false), m_slotLogSettings(false), m_slotLogSimulator(false),
|
||||
m_dbusConnection(QDBusConnection("default")),
|
||||
m_contextApplication(nullptr), m_contextAudio(nullptr), m_contextNetwork(nullptr), m_contextSettings(nullptr), m_contextSimulator(nullptr)
|
||||
{
|
||||
this->init(config);
|
||||
}
|
||||
|
||||
/*
|
||||
* Signal logging
|
||||
*/
|
||||
void CRuntime::signalLog(bool enabled)
|
||||
{
|
||||
this->signalLogForApplication(enabled);
|
||||
this->signalLogForAudio(enabled);
|
||||
this->signalLogForNetwork(enabled);
|
||||
this->signalLogForOwnAircraft(enabled);
|
||||
this->signalLogForSettings(enabled);
|
||||
this->signalLogForSimulator(enabled);
|
||||
}
|
||||
|
||||
/*
|
||||
* Signal logging
|
||||
*/
|
||||
void CRuntime::slotLog(bool enabled)
|
||||
{
|
||||
this->slotLogForApplication(enabled);
|
||||
this->slotLogForAudio(enabled);
|
||||
this->slotLogForNetwork(enabled);
|
||||
this->slotLogForOwnAircraft(enabled);
|
||||
this->slotLogForSettings(enabled);
|
||||
this->slotLogForSimulator(enabled);
|
||||
}
|
||||
|
||||
/*
|
||||
* Enable signal logging
|
||||
*/
|
||||
bool CRuntime::signalLogForApplication(bool enabled)
|
||||
{
|
||||
QWriteLocker wl(&m_lock);
|
||||
if (enabled == this->m_signalLogApplication) return enabled;
|
||||
if (!this->getIContextApplication())
|
||||
{
|
||||
this->m_signalLogApplication = false;
|
||||
return false;
|
||||
}
|
||||
this->m_signalLogApplication = enabled;
|
||||
if (enabled)
|
||||
{
|
||||
// connect signal / slots when enabled
|
||||
QMetaObject::Connection con;
|
||||
con = QObject::connect(this->getIContextApplication(), &IContextApplication::componentChanged,
|
||||
[this](uint component, uint action) { QStringList l; l << "componentChanged" << QString::number(component) << QString::number(action); this->logSignal(this->getIContextApplication(), l);});
|
||||
this->m_logSignalConnections.insert("application", con);
|
||||
con = QObject::connect(this->getIContextApplication(), &IContextApplication::statusMessage,
|
||||
[this](const BlackMisc::CStatusMessage & msg) { QStringList l; l << "statusMessage" << msg.toQString() ; this->logSignal(this->getIContextApplication(), l);});
|
||||
this->m_logSignalConnections.insert("application", con);
|
||||
con = QObject::connect(this->getIContextApplication(), &IContextApplication::statusMessages,
|
||||
[this](const BlackMisc::CStatusMessageList & msgs) { QStringList l; l << "statusMessages" << msgs.toQString(); this->logSignal(this->getIContextApplication(), l);});
|
||||
this->m_logSignalConnections.insert("application", con);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->disconnectLogSignals("application");
|
||||
}
|
||||
return enabled;
|
||||
}
|
||||
|
||||
bool CRuntime::signalLogForAudio(bool enabled)
|
||||
{
|
||||
QWriteLocker wl(&m_lock);
|
||||
if (enabled == this->m_signalLogAudio) return enabled;
|
||||
if (!this->getIContextNetwork())
|
||||
{
|
||||
this->m_signalLogAudio = false;
|
||||
return false;
|
||||
}
|
||||
this->m_signalLogAudio = enabled;
|
||||
if (enabled)
|
||||
{
|
||||
QMetaObject::Connection con;
|
||||
con = QObject::connect(this->getIContextAudio(), &IContextAudio::audioTestCompleted,
|
||||
[this]() { QStringList l; l << "audioTestCompleted"; this->logSignal(this->getIContextAudio(), l);});
|
||||
this->m_logSignalConnections.insert("audio", con);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->disconnectLogSignals("audio");
|
||||
}
|
||||
return enabled;
|
||||
}
|
||||
|
||||
/*
|
||||
* Enable signal logging
|
||||
*/
|
||||
bool CRuntime::signalLogForNetwork(bool enabled)
|
||||
{
|
||||
QWriteLocker wl(&m_lock);
|
||||
if (enabled == this->m_signalLogNetwork) return enabled;
|
||||
if (!this->getIContextNetwork())
|
||||
{
|
||||
this->m_signalLogNetwork = false;
|
||||
return false;
|
||||
}
|
||||
this->m_signalLogNetwork = enabled;
|
||||
if (enabled)
|
||||
{
|
||||
QMetaObject::Connection con;
|
||||
con = QObject::connect(this->getIContextNetwork(), &IContextNetwork::changedAircraftsInRange,
|
||||
[this]() { QStringList l; l << "changedAircraftsInRange"; this->logSignal(this->getIContextNetwork(), l);});
|
||||
this->m_logSignalConnections.insert("network", con);
|
||||
con = QObject::connect(this->getIContextNetwork(), &IContextNetwork::changedAtcStationsBooked,
|
||||
[this]() { QStringList l; l << "changedAtcStationsBooked"; this->logSignal(this->getIContextNetwork(), l);});
|
||||
this->m_logSignalConnections.insert("network", con);
|
||||
con = QObject::connect(this->getIContextNetwork(), &IContextNetwork::changedAtcStationsOnline,
|
||||
[this]() { QStringList l; l << "changedAtcStationsOnline"; this->logSignal(this->getIContextNetwork(), l);});
|
||||
this->m_logSignalConnections.insert("network", con);
|
||||
con = QObject::connect(this->getIContextNetwork(), &IContextNetwork::changedAircraftSituation,
|
||||
[this](const BlackMisc::Aviation::CCallsign & callsign, const BlackMisc::Aviation::CAircraftSituation & situation) { QStringList l; l << "changedAircraftSituation" << callsign.toQString() << situation.toQString(); this->logSignal(this->getIContextNetwork(), l);});
|
||||
this->m_logSignalConnections.insert("network", con);
|
||||
con = QObject::connect(this->getIContextNetwork(), &IContextNetwork::connectionStatusChanged,
|
||||
[this](uint from, uint to) { QStringList l; l << "connectionStatusChanged" << QString::number(from) << QString::number(to); this->logSignal(this->getIContextNetwork(), l);});
|
||||
this->m_logSignalConnections.insert("network", con);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->disconnectLogSignals("network");
|
||||
}
|
||||
return enabled;
|
||||
}
|
||||
|
||||
/*
|
||||
* Enable signal logging
|
||||
*/
|
||||
bool CRuntime::signalLogForOwnAircraft(bool enabled)
|
||||
{
|
||||
QWriteLocker wl(&m_lock);
|
||||
if (enabled == this->m_signalLogOwnAircraft) return enabled;
|
||||
if (!this->getIContextOwnAircraft())
|
||||
{
|
||||
this->m_signalLogOwnAircraft = false;
|
||||
return false;
|
||||
}
|
||||
this->m_signalLogOwnAircraft = enabled;
|
||||
if (enabled)
|
||||
{
|
||||
// connect signal / slots when enabled
|
||||
QMetaObject::Connection con;
|
||||
con = QObject::connect(this->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftSituation,
|
||||
[this](const BlackMisc::Aviation::CAircraft & aircraft, const QString & originator) { QStringList l; l << "changedAircraftSituation" << aircraft.toQString() << originator; this->logSignal(this->getIContextOwnAircraft(), l);});
|
||||
this->m_logSignalConnections.insert("ownaircraft", con);
|
||||
|
||||
con = QObject::connect(this->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit,
|
||||
[this](const BlackMisc::Aviation::CAircraft & aircraft, const QString & originator) { QStringList l; l << "changedAircraftCockpit" << aircraft.toQString() << originator; this->logSignal(this->getIContextOwnAircraft(), l);});
|
||||
this->m_logSignalConnections.insert("ownaircraft", con);
|
||||
|
||||
con = QObject::connect(this->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftPosition,
|
||||
[this](const BlackMisc::Aviation::CAircraft & aircraft, const QString & originator) { QStringList l; l << "changedAircraftPosition" << aircraft.toQString() << originator; this->logSignal(this->getIContextOwnAircraft(), l);});
|
||||
this->m_logSignalConnections.insert("ownaircraft", con);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->disconnectLogSignals("ownaircraft");
|
||||
}
|
||||
return enabled;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Enable signal logging
|
||||
*/
|
||||
bool CRuntime::signalLogForSettings(bool enabled)
|
||||
{
|
||||
QWriteLocker wl(&m_lock);
|
||||
if (enabled == this->m_signalLogSettings) return enabled;
|
||||
if (!this->getIContextSettings())
|
||||
{
|
||||
this->m_signalLogSettings = false;
|
||||
return false;
|
||||
}
|
||||
this->m_signalLogSettings = enabled;
|
||||
if (enabled)
|
||||
{
|
||||
QMetaObject::Connection con;
|
||||
con = QObject::connect(this->getIContextSettings(), &IContextSettings::changedSettings,
|
||||
[this]() { QStringList l; l << "changedSettings"; this->logSignal(this->getIContextSettings(), l);});
|
||||
this->m_logSignalConnections.insert("settings", con);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->disconnectLogSignals("settings");
|
||||
}
|
||||
return enabled;
|
||||
}
|
||||
|
||||
/*
|
||||
* Enable signal logging
|
||||
*/
|
||||
bool CRuntime::signalLogForSimulator(bool enabled)
|
||||
{
|
||||
QWriteLocker wl(&m_lock);
|
||||
if (enabled == this->m_signalLogSimulator) return enabled;
|
||||
if (!this->getIContextSimulator())
|
||||
{
|
||||
this->m_signalLogSimulator = false;
|
||||
return false;
|
||||
}
|
||||
this->m_signalLogSimulator = enabled;
|
||||
if (enabled)
|
||||
{
|
||||
QMetaObject::Connection con;
|
||||
con = QObject::connect(this->getIContextSimulator(), &IContextSimulator::connectionChanged,
|
||||
[this]() { QStringList l; l << "connectionChanged"; this->logSignal(this->getIContextSimulator(), l);});
|
||||
this->m_logSignalConnections.insert("simulator", con);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->disconnectLogSignals("simulator");
|
||||
}
|
||||
return enabled;
|
||||
}
|
||||
|
||||
void CRuntime::logSignal(QObject *sender, const QStringList &values)
|
||||
{
|
||||
QString s = (sender) ? sender->metaObject()->className() : "";
|
||||
qDebug() << "signal" << s << values;
|
||||
}
|
||||
|
||||
void CRuntime::logSlot(const char *func, const QString ¶m) const
|
||||
{
|
||||
qDebug() << func << param;
|
||||
}
|
||||
|
||||
void CRuntime::logSlot(const char *func, const QStringList ¶ms) const
|
||||
{
|
||||
qDebug() << func << params;
|
||||
}
|
||||
|
||||
void CRuntime::logSlot(const char *func, bool boolValue) const
|
||||
{
|
||||
qDebug() << func << boolValue;
|
||||
}
|
||||
|
||||
void CRuntime::logSlot(CRuntime::LogContext context, const char *func, const QString ¶m) const
|
||||
{
|
||||
if (this->isSlotLogEnabledFor(context)) qDebug() << func << param;
|
||||
}
|
||||
|
||||
void CRuntime::logSlot(CRuntime::LogContext context, const char *func, const QStringList ¶ms) const
|
||||
{
|
||||
if (this->isSlotLogEnabledFor(context)) qDebug() << func << params;
|
||||
}
|
||||
|
||||
void CRuntime::logSlot(CRuntime::LogContext context, const char *func, bool boolValue) const
|
||||
{
|
||||
if (this->isSlotLogEnabledFor(context)) qDebug() << func << boolValue;
|
||||
}
|
||||
|
||||
bool CRuntime::isSlotLogEnabledFor(CRuntime::LogContext context) const
|
||||
{
|
||||
switch (context)
|
||||
{
|
||||
default: return true;
|
||||
case LogForApplication: return this->isSlotLogForApplicationEnabled();
|
||||
case LogForAudio: return this->isSlotLogForAudioEnabled();
|
||||
case LogForNetwork: return this->isSlotLogForNetworkEnabled();
|
||||
case LogForOwnAircraft: return this->isSlotLogForOwnAircraftEnabled();
|
||||
case LogForSettings: return this->isSlotLogForSettingsEnabled();
|
||||
case LogForSimulator: return this->isSlotLogForSimulatorEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Init runtime
|
||||
*/
|
||||
@@ -467,8 +201,7 @@ namespace BlackCore
|
||||
if (!this->m_init) return;
|
||||
this->m_init = false;
|
||||
|
||||
// disable all logging and all signals towards runtime
|
||||
this->signalLog(false);
|
||||
// disable all signals towards runtime
|
||||
disconnect(this);
|
||||
|
||||
// unregister all from DBus
|
||||
@@ -520,9 +253,6 @@ namespace BlackCore
|
||||
if (this->getIContextApplication())
|
||||
{
|
||||
disconnect(this->getIContextApplication());
|
||||
this->getIContextApplication()->setOutputRedirectionLevel(IContextApplication::RedirectNone);
|
||||
this->getIContextApplication()->setStreamingForRedirectedOutputLevel(IContextApplication::RedirectNone);
|
||||
IContextApplication::resetOutputRedirection();
|
||||
this->getIContextApplication()->deleteLater();
|
||||
this->m_contextApplication = nullptr;
|
||||
}
|
||||
@@ -540,16 +270,6 @@ namespace BlackCore
|
||||
this->getIContextApplication()->sendStatusMessages(messages);
|
||||
}
|
||||
|
||||
void CRuntime::disconnectLogSignals(const QString &name)
|
||||
{
|
||||
if (!this->m_logSignalConnections.contains(name)) return;
|
||||
for (auto i = this->m_logSignalConnections.lowerBound(name), end = this->m_logSignalConnections.upperBound(name); i != end; ++i)
|
||||
{
|
||||
disconnect(i.value());
|
||||
}
|
||||
this->m_logSignalConnections.remove(name);
|
||||
}
|
||||
|
||||
void CRuntime::initDBusConnection(const QString &address)
|
||||
{
|
||||
if (this->m_initDBusConnection) return;
|
||||
|
||||
Reference in New Issue
Block a user