mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-21 21:05:31 +08:00
[AFV] Make sure all QObjects below AfvClient have a parent
This commit is contained in:
committed by
Mat Sutcliffe
parent
240df93406
commit
8d84dcbe08
@@ -37,19 +37,21 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
|
|
||||||
CAfvClient::CAfvClient(const QString &apiServer, QObject *parent) :
|
CAfvClient::CAfvClient(const QString &apiServer, QObject *parent) :
|
||||||
QObject(parent), CIdentifiable(this)
|
QObject(parent), CIdentifiable(this),
|
||||||
|
m_connection(new CClientConnection(apiServer, this)),
|
||||||
|
m_input(new CInput(SampleRate, this)),
|
||||||
|
m_output(new Output(this)),
|
||||||
|
m_voiceServerPositionTimer(new QTimer(this))
|
||||||
{
|
{
|
||||||
m_connection = new CClientConnection(apiServer, this);
|
|
||||||
m_connection->setReceiveAudio(false);
|
m_connection->setReceiveAudio(false);
|
||||||
|
|
||||||
m_input = new CInput(SampleRate, this);
|
|
||||||
connect(m_input, &CInput::opusDataAvailable, this, &CAfvClient::opusDataAvailable);
|
connect(m_input, &CInput::opusDataAvailable, this, &CAfvClient::opusDataAvailable);
|
||||||
connect(m_input, &CInput::inputVolumeStream, this, &CAfvClient::inputVolumeStream);
|
connect(m_input, &CInput::inputVolumeStream, this, &CAfvClient::inputVolumeStream);
|
||||||
|
|
||||||
m_output = new Output(this);
|
|
||||||
connect(m_output, &Output::outputVolumeStream, this, &CAfvClient::outputVolumeStream);
|
connect(m_output, &Output::outputVolumeStream, this, &CAfvClient::outputVolumeStream);
|
||||||
connect(m_connection, &CClientConnection::audioReceived, this, &CAfvClient::audioOutDataAvailable);
|
connect(m_connection, &CClientConnection::audioReceived, this, &CAfvClient::audioOutDataAvailable);
|
||||||
connect(&m_voiceServerPositionTimer, &QTimer::timeout, this, &CAfvClient::onPositionUpdateTimer);
|
connect(m_voiceServerPositionTimer, &QTimer::timeout, this, &CAfvClient::onPositionUpdateTimer);
|
||||||
|
|
||||||
// transceivers
|
// transceivers
|
||||||
this->initTransceivers();
|
this->initTransceivers();
|
||||||
@@ -157,7 +159,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
m_startDateTimeUtc = QDateTime::currentDateTimeUtc();
|
m_startDateTimeUtc = QDateTime::currentDateTimeUtc();
|
||||||
m_connection->setReceiveAudio(true);
|
m_connection->setReceiveAudio(true);
|
||||||
m_voiceServerPositionTimer.start(5000);
|
m_voiceServerPositionTimer->start(5000);
|
||||||
this->onSettingsChanged(); // make sure all settings are applied
|
this->onSettingsChanged(); // make sure all settings are applied
|
||||||
m_isStarted = true;
|
m_isStarted = true;
|
||||||
CLogMessage(this).info(u"Started [Input: %1] [Output: %2]") << inputDevice.deviceName() << outputDevice.deviceName();
|
CLogMessage(this).info(u"Started [Input: %1] [Output: %2]") << inputDevice.deviceName() << outputDevice.deviceName();
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ namespace BlackCore
|
|||||||
double m_outputVolume = 1.0;
|
double m_outputVolume = 1.0;
|
||||||
double m_maxDbReadingInPTTInterval = -100;
|
double m_maxDbReadingInPTTInterval = -100;
|
||||||
|
|
||||||
QTimer m_voiceServerPositionTimer;
|
QTimer *m_voiceServerPositionTimer = nullptr;
|
||||||
QVector<TransceiverDto> m_transceivers;
|
QVector<TransceiverDto> m_transceivers;
|
||||||
QSet<quint16> m_enabledTransceivers;
|
QSet<quint16> m_enabledTransceivers;
|
||||||
QVector<StationDto> m_aliasedStations;
|
QVector<StationDto> m_aliasedStations;
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
ApiServerConnection::ApiServerConnection(const QString &address, QObject *parent) :
|
ApiServerConnection::ApiServerConnection(const QString &address, QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_address(address)
|
m_address(address),
|
||||||
|
m_watch(new QElapsedTimer)
|
||||||
{
|
{
|
||||||
qDebug() << "ApiServerConnection instantiated";
|
qDebug() << "ApiServerConnection instantiated";
|
||||||
}
|
}
|
||||||
@@ -34,7 +35,7 @@ namespace BlackCore
|
|||||||
m_password = password;
|
m_password = password;
|
||||||
m_networkVersion = networkVersion;
|
m_networkVersion = networkVersion;
|
||||||
m_isAuthenticated = false;
|
m_isAuthenticated = false;
|
||||||
m_watch.start();
|
m_watch->start();
|
||||||
|
|
||||||
QUrl url(m_address);
|
QUrl url(m_address);
|
||||||
url.setPath("/api/v1/auth");
|
url.setPath("/api/v1/auth");
|
||||||
@@ -54,7 +55,7 @@ namespace BlackCore
|
|||||||
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> reply(nam->post(request, QJsonDocument(obj).toJson()));
|
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> reply(nam->post(request, QJsonDocument(obj).toJson()));
|
||||||
while (! reply->isFinished()) { loop.exec(); }
|
while (! reply->isFinished()) { loop.exec(); }
|
||||||
|
|
||||||
qDebug() << "POST api/v1/auth (" << m_watch.elapsed() << "ms)";
|
qDebug() << "POST api/v1/auth (" << m_watch->elapsed() << "ms)";
|
||||||
if (reply->error() != QNetworkReply::NoError)
|
if (reply->error() != QNetworkReply::NoError)
|
||||||
{
|
{
|
||||||
qWarning() << reply->errorString();
|
qWarning() << reply->errorString();
|
||||||
@@ -142,7 +143,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
checkExpiry();
|
checkExpiry();
|
||||||
|
|
||||||
m_watch.start();
|
m_watch->start();
|
||||||
QUrl url(m_address);
|
QUrl url(m_address);
|
||||||
url.setPath(resource);
|
url.setPath(resource);
|
||||||
QNetworkAccessManager *nam = sApp->getNetworkAccessManager();
|
QNetworkAccessManager *nam = sApp->getNetworkAccessManager();
|
||||||
@@ -154,7 +155,7 @@ namespace BlackCore
|
|||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||||
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> reply(nam->post(request, json.toJson()));
|
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> reply(nam->post(request, json.toJson()));
|
||||||
while (! reply->isFinished()) { loop.exec(); }
|
while (! reply->isFinished()) { loop.exec(); }
|
||||||
qDebug() << "POST" << resource << "(" << m_watch.elapsed() << "ms)";
|
qDebug() << "POST" << resource << "(" << m_watch->elapsed() << "ms)";
|
||||||
|
|
||||||
if (reply->error() != QNetworkReply::NoError)
|
if (reply->error() != QNetworkReply::NoError)
|
||||||
{
|
{
|
||||||
@@ -167,7 +168,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
if (! m_isAuthenticated) { return; }
|
if (! m_isAuthenticated) { return; }
|
||||||
|
|
||||||
m_watch.start();
|
m_watch->start();
|
||||||
QUrl url(m_address);
|
QUrl url(m_address);
|
||||||
url.setPath(resource);
|
url.setPath(resource);
|
||||||
|
|
||||||
@@ -179,7 +180,7 @@ namespace BlackCore
|
|||||||
request.setRawHeader("Authorization", "Bearer " + m_jwt);
|
request.setRawHeader("Authorization", "Bearer " + m_jwt);
|
||||||
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> reply(nam->deleteResource(request));
|
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> reply(nam->deleteResource(request));
|
||||||
while (! reply->isFinished()) { loop.exec(); }
|
while (! reply->isFinished()) { loop.exec(); }
|
||||||
qDebug() << "DELETE" << resource << "(" << m_watch.elapsed() << "ms)";
|
qDebug() << "DELETE" << resource << "(" << m_watch->elapsed() << "ms)";
|
||||||
|
|
||||||
if (reply->error() != QNetworkReply::NoError)
|
if (reply->error() != QNetworkReply::NoError)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
QNetworkAccessManager *nam = sApp->getNetworkAccessManager();
|
QNetworkAccessManager *nam = sApp->getNetworkAccessManager();
|
||||||
|
|
||||||
m_watch.start();
|
m_watch->start();
|
||||||
QUrl url(m_address);
|
QUrl url(m_address);
|
||||||
url.setPath(resource);
|
url.setPath(resource);
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
@@ -82,7 +82,7 @@ namespace BlackCore
|
|||||||
request.setRawHeader("Authorization", "Bearer " + m_jwt);
|
request.setRawHeader("Authorization", "Bearer " + m_jwt);
|
||||||
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> reply(nam->post(request, QByteArray()));
|
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> reply(nam->post(request, QByteArray()));
|
||||||
while (! reply->isFinished()) { loop.exec(); }
|
while (! reply->isFinished()) { loop.exec(); }
|
||||||
qDebug() << "POST" << resource << "(" << m_watch.elapsed() << "ms)";
|
qDebug() << "POST" << resource << "(" << m_watch->elapsed() << "ms)";
|
||||||
|
|
||||||
if (reply->error() != QNetworkReply::NoError)
|
if (reply->error() != QNetworkReply::NoError)
|
||||||
{
|
{
|
||||||
@@ -108,7 +108,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
QNetworkAccessManager *nam = sApp->getNetworkAccessManager();
|
QNetworkAccessManager *nam = sApp->getNetworkAccessManager();
|
||||||
|
|
||||||
m_watch.start();
|
m_watch->start();
|
||||||
QUrl url(m_address);
|
QUrl url(m_address);
|
||||||
url.setPath(resource);
|
url.setPath(resource);
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
@@ -118,7 +118,7 @@ namespace BlackCore
|
|||||||
request.setRawHeader("Authorization", "Bearer " + m_jwt);
|
request.setRawHeader("Authorization", "Bearer " + m_jwt);
|
||||||
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> reply(nam->get(request));
|
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> reply(nam->get(request));
|
||||||
while (! reply->isFinished()) { loop.exec(); }
|
while (! reply->isFinished()) { loop.exec(); }
|
||||||
qDebug() << "GET" << resource << "(" << m_watch.elapsed() << "ms)";
|
qDebug() << "GET" << resource << "(" << m_watch->elapsed() << "ms)";
|
||||||
|
|
||||||
if (reply->error() != QNetworkReply::NoError)
|
if (reply->error() != QNetworkReply::NoError)
|
||||||
{
|
{
|
||||||
@@ -156,7 +156,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
bool m_isAuthenticated = false;
|
bool m_isAuthenticated = false;
|
||||||
|
|
||||||
QElapsedTimer m_watch;
|
QElapsedTimer *m_watch = nullptr;
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
CClientConnection::CClientConnection(const QString &apiServer, QObject *parent) :
|
CClientConnection::CClientConnection(const QString &apiServer, QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_apiServerConnection(apiServer, this)
|
m_udpSocket(new QUdpSocket(this)),
|
||||||
|
m_voiceServerTimer(new QTimer(this)),
|
||||||
|
m_apiServerConnection(new ApiServerConnection(apiServer, this))
|
||||||
{
|
{
|
||||||
qDebug() << "ClientConnection instantiated";
|
qDebug() << "ClientConnection instantiated";
|
||||||
|
|
||||||
@@ -27,10 +29,10 @@ namespace BlackCore
|
|||||||
// connect(&m_apiServerConnection, &ApiServerConnection::addCallsignFinished, this, &ClientConnection::addCallsignFinished);
|
// connect(&m_apiServerConnection, &ApiServerConnection::addCallsignFinished, this, &ClientConnection::addCallsignFinished);
|
||||||
// connect(&m_apiServerConnection, &ApiServerConnection::removeCallsignFinished, this, &ClientConnection::removeCallsignFinished);
|
// connect(&m_apiServerConnection, &ApiServerConnection::removeCallsignFinished, this, &ClientConnection::removeCallsignFinished);
|
||||||
|
|
||||||
connect(&m_voiceServerTimer, &QTimer::timeout, this, &CClientConnection::voiceServerHeartbeat);
|
connect(m_voiceServerTimer, &QTimer::timeout, this, &CClientConnection::voiceServerHeartbeat);
|
||||||
|
|
||||||
connect(&m_udpSocket, &QUdpSocket::readyRead, this, &CClientConnection::readPendingDatagrams);
|
connect(m_udpSocket, &QUdpSocket::readyRead, this, &CClientConnection::readPendingDatagrams);
|
||||||
connect(&m_udpSocket, qOverload<QAbstractSocket::SocketError>(&QUdpSocket::error), this, &CClientConnection::handleSocketError);
|
connect(m_udpSocket, qOverload<QAbstractSocket::SocketError>(&QUdpSocket::error), this, &CClientConnection::handleSocketError);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClientConnection::connectTo(const QString &userName, const QString &password, const QString &callsign)
|
void CClientConnection::connectTo(const QString &userName, const QString &password, const QString &callsign)
|
||||||
@@ -43,9 +45,9 @@ namespace BlackCore
|
|||||||
|
|
||||||
m_connection.m_userName = userName;
|
m_connection.m_userName = userName;
|
||||||
m_connection.m_callsign = callsign;
|
m_connection.m_callsign = callsign;
|
||||||
bool result = m_apiServerConnection.connectTo(userName, password, m_networkVersion);
|
bool result = m_apiServerConnection->connectTo(userName, password, m_networkVersion);
|
||||||
if (!result) { return; }
|
if (!result) { return; }
|
||||||
m_connection.m_tokens = m_apiServerConnection.addCallsign(m_connection.m_callsign);
|
m_connection.m_tokens = m_apiServerConnection->addCallsign(m_connection.m_callsign);
|
||||||
m_connection.m_authenticatedDateTimeUtc = QDateTime::currentDateTimeUtc();
|
m_connection.m_authenticatedDateTimeUtc = QDateTime::currentDateTimeUtc();
|
||||||
m_connection.createCryptoChannels();
|
m_connection.createCryptoChannels();
|
||||||
|
|
||||||
@@ -71,12 +73,12 @@ namespace BlackCore
|
|||||||
|
|
||||||
if (! m_connection.m_callsign.isEmpty())
|
if (! m_connection.m_callsign.isEmpty())
|
||||||
{
|
{
|
||||||
m_apiServerConnection.removeCallsign(m_connection.m_callsign);
|
m_apiServerConnection->removeCallsign(m_connection.m_callsign);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO connectionCheckCancelTokenSource.Cancel(); //Stops connection check loop
|
// TODO connectionCheckCancelTokenSource.Cancel(); //Stops connection check loop
|
||||||
disconnectFromVoiceServer();
|
disconnectFromVoiceServer();
|
||||||
m_apiServerConnection.forceDisconnect();
|
m_apiServerConnection->forceDisconnect();
|
||||||
m_connection.m_tokens = {};
|
m_connection.m_tokens = {};
|
||||||
|
|
||||||
qDebug() << "Disconnection complete";
|
qDebug() << "Disconnection complete";
|
||||||
@@ -94,35 +96,35 @@ namespace BlackCore
|
|||||||
|
|
||||||
void CClientConnection::updateTransceivers(const QString &callsign, const QVector<TransceiverDto> &transceivers)
|
void CClientConnection::updateTransceivers(const QString &callsign, const QVector<TransceiverDto> &transceivers)
|
||||||
{
|
{
|
||||||
m_apiServerConnection.updateTransceivers(callsign, transceivers);
|
m_apiServerConnection->updateTransceivers(callsign, transceivers);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<StationDto> CClientConnection::getAllAliasedStations()
|
QVector<StationDto> CClientConnection::getAllAliasedStations()
|
||||||
{
|
{
|
||||||
return m_apiServerConnection.getAllAliasedStations();
|
return m_apiServerConnection->getAllAliasedStations();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClientConnection::connectToVoiceServer()
|
void CClientConnection::connectToVoiceServer()
|
||||||
{
|
{
|
||||||
QHostAddress localAddress(QHostAddress::AnyIPv4);
|
QHostAddress localAddress(QHostAddress::AnyIPv4);
|
||||||
m_udpSocket.bind(localAddress);
|
m_udpSocket->bind(localAddress);
|
||||||
m_voiceServerTimer.start(3000);
|
m_voiceServerTimer->start(3000);
|
||||||
|
|
||||||
qDebug() << "Connected to voice server (" + m_connection.m_tokens.VoiceServer.addressIpV4 << ")";
|
qDebug() << "Connected to voice server (" + m_connection.m_tokens.VoiceServer.addressIpV4 << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClientConnection::disconnectFromVoiceServer()
|
void CClientConnection::disconnectFromVoiceServer()
|
||||||
{
|
{
|
||||||
m_voiceServerTimer.stop();
|
m_voiceServerTimer->stop();
|
||||||
m_udpSocket.disconnectFromHost();
|
m_udpSocket->disconnectFromHost();
|
||||||
qDebug() << "All TaskVoiceServer tasks stopped";
|
qDebug() << "All TaskVoiceServer tasks stopped";
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClientConnection::readPendingDatagrams()
|
void CClientConnection::readPendingDatagrams()
|
||||||
{
|
{
|
||||||
while (m_udpSocket.hasPendingDatagrams())
|
while (m_udpSocket->hasPendingDatagrams())
|
||||||
{
|
{
|
||||||
QNetworkDatagram datagram = m_udpSocket.receiveDatagram();
|
QNetworkDatagram datagram = m_udpSocket->receiveDatagram();
|
||||||
processMessage(datagram.data());
|
processMessage(datagram.data());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,7 +156,7 @@ namespace BlackCore
|
|||||||
void CClientConnection::handleSocketError(QAbstractSocket::SocketError error)
|
void CClientConnection::handleSocketError(QAbstractSocket::SocketError error)
|
||||||
{
|
{
|
||||||
Q_UNUSED(error)
|
Q_UNUSED(error)
|
||||||
qDebug() << "UDP socket error" << m_udpSocket.errorString();
|
qDebug() << "UDP socket error" << m_udpSocket->errorString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClientConnection::voiceServerHeartbeat()
|
void CClientConnection::voiceServerHeartbeat()
|
||||||
@@ -164,7 +166,7 @@ namespace BlackCore
|
|||||||
HeartbeatDto keepAlive;
|
HeartbeatDto keepAlive;
|
||||||
keepAlive.callsign = m_connection.m_callsign.toStdString();
|
keepAlive.callsign = m_connection.m_callsign.toStdString();
|
||||||
const QByteArray dataBytes = CryptoDtoSerializer::serialize(*m_connection.voiceCryptoChannel, CryptoDtoMode::AEAD_ChaCha20Poly1305, keepAlive);
|
const QByteArray dataBytes = CryptoDtoSerializer::serialize(*m_connection.voiceCryptoChannel, CryptoDtoMode::AEAD_ChaCha20Poly1305, keepAlive);
|
||||||
m_udpSocket.writeDatagram(dataBytes, QHostAddress(voiceServerUrl.host()), static_cast<quint16>(voiceServerUrl.port()));
|
m_udpSocket->writeDatagram(dataBytes, QHostAddress(voiceServerUrl.host()), static_cast<quint16>(voiceServerUrl.port()));
|
||||||
}
|
}
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
QUrl voiceServerUrl("udp://" + m_connection.m_tokens.VoiceServer.addressIpV4);
|
QUrl voiceServerUrl("udp://" + m_connection.m_tokens.VoiceServer.addressIpV4);
|
||||||
QByteArray dataBytes = Crypto::CryptoDtoSerializer::serialize(*m_connection.voiceCryptoChannel, CryptoDtoMode::AEAD_ChaCha20Poly1305, dto);
|
QByteArray dataBytes = Crypto::CryptoDtoSerializer::serialize(*m_connection.voiceCryptoChannel, CryptoDtoMode::AEAD_ChaCha20Poly1305, dto);
|
||||||
m_udpSocket.writeDatagram(dataBytes, QHostAddress(voiceServerUrl.host()), static_cast<quint16>(voiceServerUrl.port()));
|
m_udpSocket->writeDatagram(dataBytes, QHostAddress(voiceServerUrl.host()), static_cast<quint16>(voiceServerUrl.port()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool receiveAudioDto() const;
|
bool receiveAudioDto() const;
|
||||||
@@ -85,11 +85,11 @@ namespace BlackCore
|
|||||||
CClientConnectionData m_connection;
|
CClientConnectionData m_connection;
|
||||||
|
|
||||||
// Voice server
|
// Voice server
|
||||||
QUdpSocket m_udpSocket;
|
QUdpSocket *m_udpSocket = nullptr;
|
||||||
QTimer m_voiceServerTimer;
|
QTimer *m_voiceServerTimer = nullptr;
|
||||||
|
|
||||||
// API server
|
// API server
|
||||||
ApiServerConnection m_apiServerConnection;
|
ApiServerConnection *m_apiServerConnection = nullptr;
|
||||||
|
|
||||||
// Properties
|
// Properties
|
||||||
bool m_receiveAudioDto = true;
|
bool m_receiveAudioDto = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user