mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-03 16:25:54 +08:00
refs #246 refactored isSlotLogForNetworkEnabled conditionals into CRuntime
This commit is contained in:
@@ -110,7 +110,7 @@ namespace BlackCore
|
|||||||
*/
|
*/
|
||||||
BlackMisc::Aviation::CInformationMessage CContextNetwork::getMetar(const BlackMisc::Aviation::CAirportIcao &airportIcaoCode)
|
BlackMisc::Aviation::CInformationMessage CContextNetwork::getMetar(const BlackMisc::Aviation::CAirportIcao &airportIcaoCode)
|
||||||
{
|
{
|
||||||
if (this->getRuntime()->isSlotLogForNetworkEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, airportIcaoCode.toQString());
|
this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, airportIcaoCode.toQString());
|
||||||
CInformationMessage metar;
|
CInformationMessage metar;
|
||||||
if (airportIcaoCode.isEmpty()) return metar;
|
if (airportIcaoCode.isEmpty()) return metar;
|
||||||
if (this->m_metarCache.contains(airportIcaoCode)) metar = this->m_metarCache[airportIcaoCode];
|
if (this->m_metarCache.contains(airportIcaoCode)) metar = this->m_metarCache[airportIcaoCode];
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ namespace BlackCore
|
|||||||
*/
|
*/
|
||||||
CStatusMessageList CContextNetwork::connectToNetwork(uint loginMode)
|
CStatusMessageList CContextNetwork::connectToNetwork(uint loginMode)
|
||||||
{
|
{
|
||||||
if (this->getRuntime()->isSlotLogForNetworkEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO);
|
this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO);
|
||||||
CStatusMessageList msgs;
|
CStatusMessageList msgs;
|
||||||
QString msg;
|
QString msg;
|
||||||
CServer currentServer = this->getIContextSettings()->getNetworkSettings().getCurrentTrafficNetworkServer();
|
CServer currentServer = this->getIContextSettings()->getNetworkSettings().getCurrentTrafficNetworkServer();
|
||||||
@@ -136,7 +136,7 @@ namespace BlackCore
|
|||||||
*/
|
*/
|
||||||
CStatusMessageList CContextNetwork::disconnectFromNetwork()
|
CStatusMessageList CContextNetwork::disconnectFromNetwork()
|
||||||
{
|
{
|
||||||
if (this->getRuntime()->isSlotLogForNetworkEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO);
|
this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO);
|
||||||
CStatusMessageList msgs;
|
CStatusMessageList msgs;
|
||||||
if (this->m_network->isConnected())
|
if (this->m_network->isConnected())
|
||||||
{
|
{
|
||||||
@@ -160,7 +160,7 @@ namespace BlackCore
|
|||||||
*/
|
*/
|
||||||
bool CContextNetwork::isConnected() const
|
bool CContextNetwork::isConnected() const
|
||||||
{
|
{
|
||||||
if (this->getRuntime()->isSlotLogForNetworkEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO);
|
this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO);
|
||||||
return this->m_network->isConnected();
|
return this->m_network->isConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,7 +169,7 @@ namespace BlackCore
|
|||||||
*/
|
*/
|
||||||
void CContextNetwork::sendTextMessages(const CTextMessageList &textMessages)
|
void CContextNetwork::sendTextMessages(const CTextMessageList &textMessages)
|
||||||
{
|
{
|
||||||
if (this->getRuntime()->isSlotLogForNetworkEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, textMessages.toQString());
|
this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, textMessages.toQString());
|
||||||
this->m_network->sendTextMessages(textMessages);
|
this->m_network->sendTextMessages(textMessages);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,14 +178,14 @@ namespace BlackCore
|
|||||||
*/
|
*/
|
||||||
void CContextNetwork::sendFlightPlan(const CFlightPlan &flightPlan)
|
void CContextNetwork::sendFlightPlan(const CFlightPlan &flightPlan)
|
||||||
{
|
{
|
||||||
if (this->getRuntime()->isSlotLogForNetworkEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, flightPlan.toQString());
|
this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, flightPlan.toQString());
|
||||||
this->m_network->sendFlightPlan(flightPlan);
|
this->m_network->sendFlightPlan(flightPlan);
|
||||||
this->m_network->sendFlightPlanQuery(this->ownAircraft().getCallsign());
|
this->m_network->sendFlightPlanQuery(this->ownAircraft().getCallsign());
|
||||||
}
|
}
|
||||||
|
|
||||||
CFlightPlan CContextNetwork::loadFlightPlanFromNetwork(const BlackMisc::Aviation::CCallsign &callsign) const
|
CFlightPlan CContextNetwork::loadFlightPlanFromNetwork(const BlackMisc::Aviation::CCallsign &callsign) const
|
||||||
{
|
{
|
||||||
if (this->getRuntime()->isSlotLogForNetworkEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO);
|
this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO);
|
||||||
CFlightPlan plan;
|
CFlightPlan plan;
|
||||||
|
|
||||||
// use cache, but not for own callsign (always reload)
|
// use cache, but not for own callsign (always reload)
|
||||||
@@ -331,7 +331,7 @@ namespace BlackCore
|
|||||||
*/
|
*/
|
||||||
void CContextNetwork::psFsdConnectionStatusChanged(INetwork::ConnectionStatus from, INetwork::ConnectionStatus to, const QString &message)
|
void CContextNetwork::psFsdConnectionStatusChanged(INetwork::ConnectionStatus from, INetwork::ConnectionStatus to, const QString &message)
|
||||||
{
|
{
|
||||||
if (this->getRuntime()->isSlotLogForNetworkEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, { QString::number(from), QString::number(to) });
|
this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, { QString::number(from), QString::number(to) });
|
||||||
CStatusMessageList msgs;
|
CStatusMessageList msgs;
|
||||||
// send 1st position
|
// send 1st position
|
||||||
if (to == INetwork::Connected)
|
if (to == INetwork::Connected)
|
||||||
@@ -358,7 +358,7 @@ namespace BlackCore
|
|||||||
*/
|
*/
|
||||||
void CContextNetwork::psFsdRealNameReplyReceived(const CCallsign &callsign, const QString &realname)
|
void CContextNetwork::psFsdRealNameReplyReceived(const CCallsign &callsign, const QString &realname)
|
||||||
{
|
{
|
||||||
if (this->getRuntime()->isSlotLogForNetworkEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, { callsign.toQString(), realname });
|
this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, { callsign.toQString(), realname });
|
||||||
if (realname.isEmpty()) return;
|
if (realname.isEmpty()) return;
|
||||||
CIndexVariantMap vm(CAtcStation::IndexControllerRealName, realname);
|
CIndexVariantMap vm(CAtcStation::IndexControllerRealName, realname);
|
||||||
this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm);
|
this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm);
|
||||||
@@ -376,7 +376,7 @@ namespace BlackCore
|
|||||||
*/
|
*/
|
||||||
void CContextNetwork::psDataFileRead()
|
void CContextNetwork::psDataFileRead()
|
||||||
{
|
{
|
||||||
if (this->getRuntime()->isSlotLogForNetworkEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO);
|
this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO);
|
||||||
this->getIContextApplication()->sendStatusMessage(CStatusMessage::getInfoMessage("Read VATSIM data file", CStatusMessage::TypeTrafficNetwork));
|
this->getIContextApplication()->sendStatusMessage(CStatusMessage::getInfoMessage("Read VATSIM data file", CStatusMessage::TypeTrafficNetwork));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,7 +385,7 @@ namespace BlackCore
|
|||||||
*/
|
*/
|
||||||
void CContextNetwork::psFsdTextMessageReceived(const CTextMessageList &messages)
|
void CContextNetwork::psFsdTextMessageReceived(const CTextMessageList &messages)
|
||||||
{
|
{
|
||||||
if (this->getRuntime()->isSlotLogForNetworkEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, messages.toQString());
|
this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, messages.toQString());
|
||||||
this->textMessagesReceived(messages); // relay
|
this->textMessagesReceived(messages); // relay
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,21 +43,21 @@ namespace BlackCore
|
|||||||
//! \copydoc IContextNetwork::getAtcStationsOnline()
|
//! \copydoc IContextNetwork::getAtcStationsOnline()
|
||||||
virtual const BlackMisc::Aviation::CAtcStationList getAtcStationsOnline() const override
|
virtual const BlackMisc::Aviation::CAtcStationList getAtcStationsOnline() const override
|
||||||
{
|
{
|
||||||
if (this->getRuntime()->isSlotLogForNetworkEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO);
|
this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO);
|
||||||
return m_atcStationsOnline;
|
return m_atcStationsOnline;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \copydoc IContextNetwork::getAtcStationsBooked()
|
//! \copydoc IContextNetwork::getAtcStationsBooked()
|
||||||
virtual const BlackMisc::Aviation::CAtcStationList getAtcStationsBooked() const override
|
virtual const BlackMisc::Aviation::CAtcStationList getAtcStationsBooked() const override
|
||||||
{
|
{
|
||||||
if (this->getRuntime()->isSlotLogForNetworkEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO);
|
this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO);
|
||||||
return m_atcStationsBooked;
|
return m_atcStationsBooked;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \copydoc IContextNetwork::getAircraftsInRange()
|
//! \copydoc IContextNetwork::getAircraftsInRange()
|
||||||
virtual const BlackMisc::Aviation::CAircraftList getAircraftsInRange() const override
|
virtual const BlackMisc::Aviation::CAircraftList getAircraftsInRange() const override
|
||||||
{
|
{
|
||||||
if (this->getRuntime()->isSlotLogForNetworkEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO);
|
this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO);
|
||||||
return m_aircraftsInRange;
|
return m_aircraftsInRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,6 +122,8 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static const auto c_logContext = CRuntime::LogForNetwork;
|
||||||
|
|
||||||
BlackMisc::Aviation::CAtcStationList m_atcStationsOnline;
|
BlackMisc::Aviation::CAtcStationList m_atcStationsOnline;
|
||||||
BlackMisc::Aviation::CAtcStationList m_atcStationsBooked;
|
BlackMisc::Aviation::CAtcStationList m_atcStationsBooked;
|
||||||
BlackMisc::Aviation::CAircraftList m_aircraftsInRange;
|
BlackMisc::Aviation::CAircraftList m_aircraftsInRange;
|
||||||
|
|||||||
@@ -265,6 +265,35 @@ namespace BlackCore
|
|||||||
qDebug() << func << boolValue;
|
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->m_slotLogApplication;
|
||||||
|
case LogForAudio: return this->m_slotLogAudio;
|
||||||
|
case LogForNetwork: return this->m_slotLogNetwork;
|
||||||
|
case LogForOwnAircraft: return this->m_slotLogOwnAircraft;
|
||||||
|
case LogForSettings: return this->m_slotLogSettings;
|
||||||
|
case LogForSimulator: return this->m_slotLogSimulator;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Init runtime
|
* Init runtime
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -30,6 +30,18 @@ namespace BlackCore
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
//! Tags to identify the context when logging a slot
|
||||||
|
enum LogContext
|
||||||
|
{
|
||||||
|
LogDefault = 0,
|
||||||
|
LogForApplication,
|
||||||
|
LogForAudio,
|
||||||
|
LogForNetwork,
|
||||||
|
LogForOwnAircraft,
|
||||||
|
LogForSettings,
|
||||||
|
LogForSimulator
|
||||||
|
};
|
||||||
|
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CRuntime(const CRuntimeConfig &config, QObject *parent = nullptr);
|
CRuntime(const CRuntimeConfig &config, QObject *parent = nullptr);
|
||||||
|
|
||||||
@@ -102,6 +114,9 @@ namespace BlackCore
|
|||||||
//! Slot logging for simulator context
|
//! Slot logging for simulator context
|
||||||
bool isSlotLogForSimulatorEnabled() const { return this->m_slotLogSimulator; }
|
bool isSlotLogForSimulatorEnabled() const { return this->m_slotLogSimulator; }
|
||||||
|
|
||||||
|
//! Slot logging for specified context
|
||||||
|
bool isSlotLogEnabledFor(LogContext context) const;
|
||||||
|
|
||||||
//! Slot logging
|
//! Slot logging
|
||||||
//! \deprecated Use a brace-initialized QStringList
|
//! \deprecated Use a brace-initialized QStringList
|
||||||
void logSlot(const char *func, const QString ¶m, const QString &p2, const QString &p3 = "", const QString &p4 = "") const;
|
void logSlot(const char *func, const QString ¶m, const QString &p2, const QString &p3 = "", const QString &p4 = "") const;
|
||||||
@@ -115,6 +130,15 @@ namespace BlackCore
|
|||||||
//! Slot logging for bool value
|
//! Slot logging for bool value
|
||||||
void logSlot(const char *func, bool boolValue) const;
|
void logSlot(const char *func, bool boolValue) const;
|
||||||
|
|
||||||
|
//! Slot logging from a specific context
|
||||||
|
void logSlot(LogContext ctx, const char *func, const QString ¶m = "") const;
|
||||||
|
|
||||||
|
//! Slot logging from a specific context
|
||||||
|
void logSlot(LogContext ctx, const char *func, const QStringList ¶ms) const;
|
||||||
|
|
||||||
|
//! Slot logging for bool value from a specific context
|
||||||
|
void logSlot(LogContext ctx, const char *func, bool boolValue) const;
|
||||||
|
|
||||||
//! shutdown
|
//! shutdown
|
||||||
void gracefulShutdown();
|
void gracefulShutdown();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user