Ref T730, Ref T739 update from own aircraft in one step

* update all values from own aircraft in "one step"
* rational: avoid "single property" updates and numerous round trips (signals, transceiver updates)
* also allow updates of not yet connect, as "a kind of preset"
* do NOT send to network if not authenticated
This commit is contained in:
Klaus Basan
2019-10-09 22:58:11 +02:00
committed by Mat Sutcliffe
parent caa78395a9
commit ef9e7b0bf1
4 changed files with 171 additions and 87 deletions

View File

@@ -138,6 +138,7 @@ namespace BlackCore
void CApiServerConnection::updateTransceivers(const QString &callsign, const QVector<TransceiverDto> &transceivers)
{
if (!this->sendToNetworkIfAuthenticated()) { return; }
QJsonArray array;
for (const TransceiverDto &tx : transceivers)
{
@@ -239,13 +240,7 @@ namespace BlackCore
void CApiServerConnection::postNoResponse(const QString &resource, const QJsonDocument &json)
{
if (isShuttingDown()) { return; } // avoid crash
if (!m_isAuthenticated)
{
CLogMessage(this).debug(u"AFV not authenticated");
return;
}
if (isShuttingDown()) { return; }
this->checkExpiry();
QUrl url(m_addressUrl);
@@ -273,8 +268,7 @@ namespace BlackCore
void CApiServerConnection::deleteResource(const QString &resource)
{
if (isShuttingDown()) { return; }
if (!m_isAuthenticated) { return; }
if (isShuttingDown()) { return; }
QUrl url(m_addressUrl);
url.setPath(resource);
@@ -345,6 +339,11 @@ namespace BlackCore
return loop;
}
bool CApiServerConnection::sendToNetworkIfAuthenticated() const
{
return m_isAuthenticated && !isShuttingDown();
}
bool CApiServerConnection::isShuttingDown()
{
return !sApp || sApp->isShuttingDown();

View File

@@ -80,9 +80,9 @@ namespace BlackCore
template<typename TResponse>
TResponse postNoRequest(const QString &resource)
{
if (!m_isAuthenticated)
if (!this->sendToNetworkIfAuthenticated())
{
BlackMisc::CLogMessage(this).debug(u"AFV not authenticated");
// BlackMisc::CLogMessage(this).debug(u"AFV not authenticated");
return {};
}
@@ -103,9 +103,9 @@ namespace BlackCore
template<typename TResponse>
QVector<TResponse> getAsVector(const QString &resource)
{
if (! m_isAuthenticated)
if (!this->sendToNetworkIfAuthenticated())
{
BlackMisc::CLogMessage(this).debug(u"AFV not authenticated");
// BlackMisc::CLogMessage(this).debug(u"AFV not authenticated");
return {};
}
@@ -156,6 +156,9 @@ namespace BlackCore
//! Get QLoop for network access, using class must delete the loop
QEventLoop *newEventLoop();
//! Send to network
bool sendToNetworkIfAuthenticated() const;
//! Application shutting down
static bool isShuttingDown();