From e485824bfc57b0f4fa2bd58f596231e624d23220 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 8 Oct 2019 03:00:02 +0200 Subject: [PATCH] Ref T730, allow to update voice server URL --- src/blackcore/afv/clients/afvclient.cpp | 6 ++++++ src/blackcore/afv/clients/afvclient.h | 3 +++ .../afv/connection/apiserverconnection.cpp | 16 ++++++++++++---- .../afv/connection/apiserverconnection.h | 10 +++++++--- .../afv/connection/clientconnection.cpp | 6 ++++++ src/blackcore/afv/connection/clientconnection.h | 5 ++++- 6 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/blackcore/afv/clients/afvclient.cpp b/src/blackcore/afv/clients/afvclient.cpp index 7c2229951..814559420 100644 --- a/src/blackcore/afv/clients/afvclient.cpp +++ b/src/blackcore/afv/clients/afvclient.cpp @@ -650,6 +650,12 @@ namespace BlackCore return {}; } + bool CAfvClient::updateVoiceServerUrl(const QString &url) + { + if (m_connection) { return false; } + return m_connection->updateVoiceServerUrl(url); + } + void CAfvClient::initialize() { CLogMessage(this).info(u"Initialize AFV client in thread: %1") << CThreadUtils::threadInfo(this->thread()); diff --git a/src/blackcore/afv/clients/afvclient.h b/src/blackcore/afv/clients/afvclient.h index c964af745..67e51e559 100644 --- a/src/blackcore/afv/clients/afvclient.h +++ b/src/blackcore/afv/clients/afvclient.h @@ -199,6 +199,9 @@ namespace BlackCore QString getReceivingCallsignsCom2(); //! @} + //! Update the voice server URL + bool updateVoiceServerUrl(const QString &url); + signals: //! Receiving callsigns have been changed //! \remark callsigns I do receive diff --git a/src/blackcore/afv/connection/apiserverconnection.cpp b/src/blackcore/afv/connection/apiserverconnection.cpp index c25b40c13..37de83314 100644 --- a/src/blackcore/afv/connection/apiserverconnection.cpp +++ b/src/blackcore/afv/connection/apiserverconnection.cpp @@ -11,6 +11,7 @@ #include "blackmisc/network/networkutils.h" #include "blackmisc/network/external/qjsonwebtoken.h" #include "blackmisc/logmessage.h" +#include "blackmisc/stringutils.h" #include #include @@ -37,7 +38,7 @@ namespace BlackCore CApiServerConnection::CApiServerConnection(const QString &address, QObject *parent) : QObject(parent), - m_address(address) + m_addressUrl(address) { CLogMessage(this).debug(u"ApiServerConnection instantiated"); } @@ -51,7 +52,7 @@ namespace BlackCore m_networkVersion = networkVersion; m_isAuthenticated = false; - QUrl url(m_address); + QUrl url(m_addressUrl); url.setPath("/api/v1/auth"); QJsonObject obj @@ -157,6 +158,13 @@ namespace BlackCore return {}; } + bool CApiServerConnection::setUrl(const QString &url) + { + if (stringCompare(m_addressUrl, url, Qt::CaseInsensitive)) { return false; } + m_addressUrl = url; + return true; + } + QByteArray CApiServerConnection::getWithResponse(const QNetworkRequest &request) { if (isShuttingDown()) { return {}; } @@ -240,7 +248,7 @@ namespace BlackCore this->checkExpiry(); - QUrl url(m_address); + QUrl url(m_addressUrl); url.setPath(resource); QNetworkRequest request(url); request.setRawHeader("Authorization", "Bearer " + m_jwt); @@ -268,7 +276,7 @@ namespace BlackCore if (isShuttingDown()) { return; } if (!m_isAuthenticated) { return; } - QUrl url(m_address); + QUrl url(m_addressUrl); url.setPath(resource); QNetworkRequest request(url); diff --git a/src/blackcore/afv/connection/apiserverconnection.h b/src/blackcore/afv/connection/apiserverconnection.h index ae3c7ab94..404781aa5 100644 --- a/src/blackcore/afv/connection/apiserverconnection.h +++ b/src/blackcore/afv/connection/apiserverconnection.h @@ -13,6 +13,7 @@ #include "blackcore/afv/dto.h" #include "blackcore/application.h" +#include "blackmisc/logmessage.h" #include "blackmisc/logcategorylist.h" #include @@ -71,6 +72,9 @@ namespace BlackCore //! All aliased stations QVector getAllAliasedStations(); + //! Set the URL + bool setUrl(const QString &url); + private: //! Post to resource template @@ -84,7 +88,7 @@ namespace BlackCore this->checkExpiry(); - QUrl url(m_address); + QUrl url(m_addressUrl); url.setPath(resource); QNetworkRequest request(url); request.setRawHeader("Authorization", "Bearer " + m_jwt); @@ -107,7 +111,7 @@ namespace BlackCore this->checkExpiry(); - QUrl url(m_address); + QUrl url(m_addressUrl); url.setPath(resource); QNetworkRequest request(url); request.setRawHeader("Authorization", "Bearer " + m_jwt); @@ -155,7 +159,7 @@ namespace BlackCore //! Application shutting down static bool isShuttingDown(); - const QString m_address; + QString m_addressUrl; QByteArray m_jwt; QString m_username; QString m_password; diff --git a/src/blackcore/afv/connection/clientconnection.cpp b/src/blackcore/afv/connection/clientconnection.cpp index af15c0fd9..ec174d3e7 100644 --- a/src/blackcore/afv/connection/clientconnection.cpp +++ b/src/blackcore/afv/connection/clientconnection.cpp @@ -96,6 +96,12 @@ namespace BlackCore return m_apiServerConnection->getAllAliasedStations(); } + bool CClientConnection::updateVoiceServerUrl(const QString &url) + { + if (!m_apiServerConnection) { return false; } + return m_apiServerConnection->setUrl(url); + } + void CClientConnection::connectToVoiceServer() { QHostAddress localAddress(QHostAddress::AnyIPv4); diff --git a/src/blackcore/afv/connection/clientconnection.h b/src/blackcore/afv/connection/clientconnection.h index a01ab48b3..9335a734b 100644 --- a/src/blackcore/afv/connection/clientconnection.h +++ b/src/blackcore/afv/connection/clientconnection.h @@ -60,7 +60,7 @@ namespace BlackCore } //! @} - //! Send voiceDTO to server + //! Send voice DTO to server template void sendToVoiceServer(const T &dto) { @@ -75,6 +75,9 @@ namespace BlackCore //! All aliased stations QVector getAllAliasedStations(); + //! Update the voice server URL + bool updateVoiceServerUrl(const QString &url); + signals: //! Audio has been received void audioReceived(const AudioRxOnTransceiversDto &dto);