mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-25 18:25:42 +08:00
Ref T161, network watchdog calls ping service
This commit is contained in:
@@ -690,6 +690,12 @@ namespace BlackCore
|
|||||||
return m_networkWatchDog.data();
|
return m_networkWatchDog.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CApplication::setSwiftDbAccessibility(bool accessible)
|
||||||
|
{
|
||||||
|
if (!m_networkWatchDog) { return; }
|
||||||
|
m_networkWatchDog->setDbAccessibility(accessible);
|
||||||
|
}
|
||||||
|
|
||||||
int CApplication::triggerNetworkChecks()
|
int CApplication::triggerNetworkChecks()
|
||||||
{
|
{
|
||||||
if (!m_networkWatchDog) { return -1; }
|
if (!m_networkWatchDog) { return -1; }
|
||||||
@@ -889,6 +895,14 @@ namespace BlackCore
|
|||||||
void CApplication::gracefulShutdown()
|
void CApplication::gracefulShutdown()
|
||||||
{
|
{
|
||||||
if (m_shutdown) { return; }
|
if (m_shutdown) { return; }
|
||||||
|
|
||||||
|
// before marked as shutdown
|
||||||
|
if (m_networkWatchDog)
|
||||||
|
{
|
||||||
|
m_networkWatchDog->gracefulShutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
// mark as shutdown
|
||||||
m_shutdown = true;
|
m_shutdown = true;
|
||||||
|
|
||||||
// save settings (but only when application was really alive)
|
// save settings (but only when application was really alive)
|
||||||
|
|||||||
@@ -162,6 +162,10 @@ namespace BlackCore
|
|||||||
//! \remark mostly for UNIT tests etc, normally not meant to be used directly
|
//! \remark mostly for UNIT tests etc, normally not meant to be used directly
|
||||||
Db::CNetworkWatchdog *getNetworkWatchdog() const;
|
Db::CNetworkWatchdog *getNetworkWatchdog() const;
|
||||||
|
|
||||||
|
//! Allows to mark the DB as "up" or "down"
|
||||||
|
//! \see BlackCore::Db::CNetworkWatchdog::setDbAccessibility
|
||||||
|
void setSwiftDbAccessibility(bool accessible);
|
||||||
|
|
||||||
//! \copydoc BlackCore::Db::CNetworkWatchdog::triggerCheck
|
//! \copydoc BlackCore::Db::CNetworkWatchdog::triggerCheck
|
||||||
int triggerNetworkChecks();
|
int triggerNetworkChecks();
|
||||||
|
|
||||||
|
|||||||
@@ -9,10 +9,13 @@
|
|||||||
|
|
||||||
#include "networkwatchdog.h"
|
#include "networkwatchdog.h"
|
||||||
#include "application.h"
|
#include "application.h"
|
||||||
|
#include "blackcore/data/globalsetup.h"
|
||||||
#include "blackmisc/network/networkutils.h"
|
#include "blackmisc/network/networkutils.h"
|
||||||
|
#include <QNetworkReply>
|
||||||
|
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
using namespace BlackMisc::Network;
|
using namespace BlackMisc::Network;
|
||||||
|
using namespace BlackCore::Data;
|
||||||
|
|
||||||
namespace BlackCore
|
namespace BlackCore
|
||||||
{
|
{
|
||||||
@@ -168,6 +171,37 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CNetworkWatchdog::gracefulShutdown()
|
||||||
|
{
|
||||||
|
this->pingDbClientService(PingCompleteShutdown);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNetworkWatchdog::pingDbClientService(CNetworkWatchdog::PingType type)
|
||||||
|
{
|
||||||
|
if (!this->isSwiftDbAccessible()) { return; }
|
||||||
|
if (!sApp) { return; }
|
||||||
|
const CGlobalSetup gs = sApp->getGlobalSetup();
|
||||||
|
if (!gs.wasLoaded()) { return; }
|
||||||
|
CUrl pingUrl = gs.getDbClientPingServiceUrl();
|
||||||
|
if (pingUrl.isEmpty()) { return; }
|
||||||
|
|
||||||
|
pingUrl.appendQuery("uuid", this->identifier().toUuidString());
|
||||||
|
pingUrl.appendQuery("application", sApp->getApplicationNameAndVersion());
|
||||||
|
if (type.testFlag(PingLogoff)) { pingUrl.appendQuery("logoff", "true"); }
|
||||||
|
if (type.testFlag(PingShutdown)) { pingUrl.appendQuery("shutdown", "true"); }
|
||||||
|
if (type.testFlag(PingStarted)) { pingUrl.appendQuery("started", "true"); }
|
||||||
|
|
||||||
|
sApp->getFromNetwork(pingUrl, { this, &CNetworkWatchdog::replyPingClientService });
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNetworkWatchdog::replyPingClientService(QNetworkReply *nwReply)
|
||||||
|
{
|
||||||
|
QScopedPointer<QNetworkReply> nw(nwReply); // delete reply
|
||||||
|
if (!sApp || sApp->isShuttingDown()) { return; }
|
||||||
|
const bool ok = nw->error() == QNetworkReply::NoError;
|
||||||
|
this->setDbAccessibility(ok);
|
||||||
|
}
|
||||||
|
|
||||||
void CNetworkWatchdog::triggerChangedSignals(bool oldDbAccessible, bool oldInternetAccessible)
|
void CNetworkWatchdog::triggerChangedSignals(bool oldDbAccessible, bool oldInternetAccessible)
|
||||||
{
|
{
|
||||||
if (!this->doWorkCheck()) { return; }
|
if (!this->doWorkCheck()) { return; }
|
||||||
|
|||||||
@@ -79,6 +79,23 @@ namespace BlackCore
|
|||||||
//! Network status changed, use this function to inform the watchdog
|
//! Network status changed, use this function to inform the watchdog
|
||||||
void onChangedNetworkAccessibility(QNetworkAccessManager::NetworkAccessibility accessible);
|
void onChangedNetworkAccessibility(QNetworkAccessManager::NetworkAccessibility accessible);
|
||||||
|
|
||||||
|
//! Graceful shutdown
|
||||||
|
void gracefulShutdown();
|
||||||
|
|
||||||
|
//! Add info when pinging
|
||||||
|
enum PingTypeFlag
|
||||||
|
{
|
||||||
|
PingUnspecific = 0,
|
||||||
|
PingLogoff = 1 << 0,
|
||||||
|
PingStarted = 1 << 1,
|
||||||
|
PingShutdown = 1 << 2,
|
||||||
|
PingCompleteShutdown = PingLogoff | PingShutdown
|
||||||
|
};
|
||||||
|
Q_DECLARE_FLAGS(PingType, PingTypeFlag)
|
||||||
|
|
||||||
|
//! Ping the DB server, fire and forget (no feedback etc)
|
||||||
|
void pingDbClientService(PingType type = PingUnspecific);
|
||||||
|
|
||||||
//! URL referring to the DB
|
//! URL referring to the DB
|
||||||
//! \remark depends on BlackCore::Application::getGlobalSetup()
|
//! \remark depends on BlackCore::Application::getGlobalSetup()
|
||||||
static bool isDbUrl(const BlackMisc::Network::CUrl &url);
|
static bool isDbUrl(const BlackMisc::Network::CUrl &url);
|
||||||
@@ -103,6 +120,9 @@ namespace BlackCore
|
|||||||
//! Init a working shared URL
|
//! Init a working shared URL
|
||||||
void initWorkingSharedUrlFromSetup();
|
void initWorkingSharedUrlFromSetup();
|
||||||
|
|
||||||
|
//! Received reply of client service ping
|
||||||
|
void replyPingClientService(QNetworkReply *nwReply);
|
||||||
|
|
||||||
//! The URL being tested
|
//! The URL being tested
|
||||||
//! \remark depends on BlackCore::Application::getGlobalSetup()
|
//! \remark depends on BlackCore::Application::getGlobalSetup()
|
||||||
static BlackMisc::Network::CUrl dbTestUrl();
|
static BlackMisc::Network::CUrl dbTestUrl();
|
||||||
@@ -127,4 +147,9 @@ namespace BlackCore
|
|||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(BlackCore::Db::CNetworkWatchdog::PingTypeFlag)
|
||||||
|
Q_DECLARE_METATYPE(BlackCore::Db::CNetworkWatchdog::PingType)
|
||||||
|
Q_DECLARE_OPERATORS_FOR_FLAGS(BlackCore::Db::CNetworkWatchdog::PingType)
|
||||||
|
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
Reference in New Issue
Block a user