refs #246 refactored isSlotLogForNetworkEnabled conditionals into CRuntime

This commit is contained in:
Mathew Sutcliffe
2014-06-11 20:14:47 +01:00
parent 26c270c9a6
commit 81c6805822
5 changed files with 69 additions and 14 deletions

View File

@@ -110,7 +110,7 @@ namespace BlackCore
*/
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;
if (airportIcaoCode.isEmpty()) return metar;
if (this->m_metarCache.contains(airportIcaoCode)) metar = this->m_metarCache[airportIcaoCode];

View File

@@ -92,7 +92,7 @@ namespace BlackCore
*/
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;
QString msg;
CServer currentServer = this->getIContextSettings()->getNetworkSettings().getCurrentTrafficNetworkServer();
@@ -136,7 +136,7 @@ namespace BlackCore
*/
CStatusMessageList CContextNetwork::disconnectFromNetwork()
{
if (this->getRuntime()->isSlotLogForNetworkEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO);
this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO);
CStatusMessageList msgs;
if (this->m_network->isConnected())
{
@@ -160,7 +160,7 @@ namespace BlackCore
*/
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();
}
@@ -169,7 +169,7 @@ namespace BlackCore
*/
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);
}
@@ -178,14 +178,14 @@ namespace BlackCore
*/
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->sendFlightPlanQuery(this->ownAircraft().getCallsign());
}
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;
// 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)
{
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;
// send 1st position
if (to == INetwork::Connected)
@@ -358,7 +358,7 @@ namespace BlackCore
*/
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;
CIndexVariantMap vm(CAtcStation::IndexControllerRealName, realname);
this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm);
@@ -376,7 +376,7 @@ namespace BlackCore
*/
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));
}
@@ -385,7 +385,7 @@ namespace BlackCore
*/
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
}

View File

@@ -43,21 +43,21 @@ namespace BlackCore
//! \copydoc IContextNetwork::getAtcStationsOnline()
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;
}
//! \copydoc IContextNetwork::getAtcStationsBooked()
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;
}
//! \copydoc IContextNetwork::getAircraftsInRange()
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;
}
@@ -122,6 +122,8 @@ namespace BlackCore
}
private:
static const auto c_logContext = CRuntime::LogForNetwork;
BlackMisc::Aviation::CAtcStationList m_atcStationsOnline;
BlackMisc::Aviation::CAtcStationList m_atcStationsBooked;
BlackMisc::Aviation::CAircraftList m_aircraftsInRange;

View File

@@ -265,6 +265,35 @@ namespace BlackCore
qDebug() << func << boolValue;
}
void CRuntime::logSlot(CRuntime::LogContext context, const char *func, const QString &param) const
{
if (this->isSlotLogEnabledFor(context)) qDebug() << func << param;
}
void CRuntime::logSlot(CRuntime::LogContext context, const char *func, const QStringList &params) 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
*/

View File

@@ -30,6 +30,18 @@ namespace BlackCore
Q_OBJECT
public:
//! Tags to identify the context when logging a slot
enum LogContext
{
LogDefault = 0,
LogForApplication,
LogForAudio,
LogForNetwork,
LogForOwnAircraft,
LogForSettings,
LogForSimulator
};
//! Constructor
CRuntime(const CRuntimeConfig &config, QObject *parent = nullptr);
@@ -102,6 +114,9 @@ namespace BlackCore
//! Slot logging for simulator context
bool isSlotLogForSimulatorEnabled() const { return this->m_slotLogSimulator; }
//! Slot logging for specified context
bool isSlotLogEnabledFor(LogContext context) const;
//! Slot logging
//! \deprecated Use a brace-initialized QStringList
void logSlot(const char *func, const QString &param, const QString &p2, const QString &p3 = "", const QString &p4 = "") const;
@@ -115,6 +130,15 @@ namespace BlackCore
//! Slot logging for bool value
void logSlot(const char *func, bool boolValue) const;
//! Slot logging from a specific context
void logSlot(LogContext ctx, const char *func, const QString &param = "") const;
//! Slot logging from a specific context
void logSlot(LogContext ctx, const char *func, const QStringList &params) const;
//! Slot logging for bool value from a specific context
void logSlot(LogContext ctx, const char *func, bool boolValue) const;
//! shutdown
void gracefulShutdown();