Utility function to directly log warning when network not accessible

This commit is contained in:
Klaus Basan
2017-07-11 20:03:24 +02:00
committed by Mathew Sutcliffe
parent 8aed8f598e
commit 76b3b6c0b6
7 changed files with 16 additions and 33 deletions

View File

@@ -179,11 +179,7 @@ namespace BlackCore
// ps_read is implemented in the derived classes // ps_read is implemented in the derived classes
if (entities == CEntityFlags::NoEntity) { return; } if (entities == CEntityFlags::NoEntity) { return; }
if (!this->isNetworkAccessible()) if (!this->isNetworkAccessible(QString("No network, will not read %1").arg(CEntityFlags::flagToString(entities)))) { return; }
{
CLogMessage(this).warning("No network, will not read %1") << CEntityFlags::flagToString(entities);
return;
}
const bool s = QMetaObject::invokeMethod(this, "ps_read", const bool s = QMetaObject::invokeMethod(this, "ps_read",
Q_ARG(BlackMisc::Network::CEntityFlags::Entity, entities), Q_ARG(BlackMisc::Network::CEntityFlags::Entity, entities),
@@ -355,11 +351,7 @@ namespace BlackCore
bool CDatabaseReader::requestHeadersOfSharedFiles(CEntityFlags::Entity entities) bool CDatabaseReader::requestHeadersOfSharedFiles(CEntityFlags::Entity entities)
{ {
if (!this->isNetworkAccessible()) if (!this->isNetworkAccessible(QString("No network, will not read shared file headers for %1").arg(CEntityFlags::flagToString(entities)))) { return false; }
{
CLogMessage(this).warning("No network, will not read shared file headers for %1") << CEntityFlags::flagToString(entities);
return false;
}
CEntityFlags::Entity allEntities(this->maskBySupportedEntities(entities)); CEntityFlags::Entity allEntities(this->maskBySupportedEntities(entities));
CEntityFlags::Entity currentEntity = CEntityFlags::iterateDbEntities(allEntities); CEntityFlags::Entity currentEntity = CEntityFlags::iterateDbEntities(allEntities);

View File

@@ -11,6 +11,7 @@
#include "blackcore/application.h" #include "blackcore/application.h"
#include "blackmisc/network/networkutils.h" #include "blackmisc/network/networkutils.h"
#include "blackmisc/threadutils.h" #include "blackmisc/threadutils.h"
#include "blackmisc/logmessage.h"
#include <QCoreApplication> #include <QCoreApplication>
#include <QMetaObject> #include <QMetaObject>
@@ -66,9 +67,14 @@ namespace BlackCore
return delta <= timeLastMs; return delta <= timeLastMs;
} }
bool CThreadedReader::isNetworkAccessible() const bool CThreadedReader::isNetworkAccessible(const QString &logWarningMessage) const
{ {
return sApp->isNetworkAccessible(); const bool a = sApp->isNetworkAccessible();
if (!a && !logWarningMessage.isEmpty())
{
CLogMessage(this).warning(logWarningMessage);
}
return a;
} }
void CThreadedReader::startReader() void CThreadedReader::startReader()

View File

@@ -53,7 +53,8 @@ namespace BlackCore
bool updatedWithinLastMs(qint64 timeLastMs); bool updatedWithinLastMs(qint64 timeLastMs);
//! Network accessible? //! Network accessible?
bool isNetworkAccessible() const; //! \param logWarningMessage optional warning if not accessible
bool isNetworkAccessible(const QString &logWarningMessage = {}) const;
//! Is marked as read failed //! Is marked as read failed
//! \threadsafe //! \threadsafe

View File

@@ -64,11 +64,7 @@ namespace BlackCore
{ {
this->threadAssertCheck(); this->threadAssertCheck();
if (!this->doWorkCheck()) { return; } if (!this->doWorkCheck()) { return; }
if (!this->isNetworkAccessible()) if (!this->isNetworkAccessible("No network, cannot read VATSIM bookings")) { return; }
{
CLogMessage(this).warning("No network, cannot read VATSIM bookings");
return;
}
Q_ASSERT_X(sApp, Q_FUNC_INFO, "No application"); Q_ASSERT_X(sApp, Q_FUNC_INFO, "No application");
const QUrl url(sApp->getGlobalSetup().getVatsimBookingsUrl()); const QUrl url(sApp->getGlobalSetup().getVatsimBookingsUrl());

View File

@@ -183,11 +183,7 @@ namespace BlackCore
{ {
this->threadAssertCheck(); this->threadAssertCheck();
if (!this->doWorkCheck()) { return; } if (!this->doWorkCheck()) { return; }
if (!this->isNetworkAccessible()) if (!this->isNetworkAccessible("No network, cannot read VATSIM data file")) { return; }
{
CLogMessage(this).warning("No network, cannot read VATSIM data file");
return;
}
// round robin for load balancing // round robin for load balancing
// remark: Don't use QThread to run network operations in the background // remark: Don't use QThread to run network operations in the background

View File

@@ -76,11 +76,7 @@ namespace BlackCore
{ {
this->threadAssertCheck(); this->threadAssertCheck();
if (!this->doWorkCheck()) { return; } if (!this->doWorkCheck()) { return; }
if (!this->isNetworkAccessible()) if (!this->isNetworkAccessible("No network, cannot read METARs")) { return; }
{
CLogMessage(this).warning("No network, cannot read METARs");
return;
}
CFailoverUrlList urls(sApp->getVatsimMetarUrls()); CFailoverUrlList urls(sApp->getVatsimMetarUrls());
const CUrl url(urls.obtainNextWorkingUrl(true)); const CUrl url(urls.obtainNextWorkingUrl(true));

View File

@@ -66,11 +66,7 @@ namespace BlackCore
{ {
this->threadAssertCheck(); this->threadAssertCheck();
if (!this->doWorkCheck()) { return; } if (!this->doWorkCheck()) { return; }
if (!this->isNetworkAccessible()) if (!this->isNetworkAccessible("No network, cannot read VATSIM status file")) { return; }
{
CLogMessage(this).warning("No network, cannot read VATSIM status file");
return;
}
Q_ASSERT_X(sApp, Q_FUNC_INFO, "Missing application"); Q_ASSERT_X(sApp, Q_FUNC_INFO, "Missing application");
CFailoverUrlList urls(sApp->getGlobalSetup().getVatsimStatusFileUrls()); CFailoverUrlList urls(sApp->getGlobalSetup().getVatsimStatusFileUrls());