mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-29 04:35:41 +08:00
[AFV] Add method to read all aliased HF stations
ref T729
This commit is contained in:
committed by
Mat Sutcliffe
parent
4a578110b0
commit
8b1fb1baca
@@ -125,6 +125,12 @@ namespace BlackCore
|
||||
m_jwt.clear();
|
||||
}
|
||||
|
||||
QVector<StationDto> ApiServerConnection::getAllAliasedStations()
|
||||
{
|
||||
getAsVector<StationDto>("/api/v1/stations/aliased");
|
||||
return {};
|
||||
}
|
||||
|
||||
void ApiServerConnection::postNoResponse(const QString &resource, const QJsonDocument &json)
|
||||
{
|
||||
if (isShuttingDown()) { return; } // avoid crash
|
||||
|
||||
@@ -56,6 +56,8 @@ namespace BlackCore
|
||||
|
||||
void forceDisconnect();
|
||||
|
||||
QVector<StationDto> getAllAliasedStations();
|
||||
|
||||
private:
|
||||
template<typename TResponse>
|
||||
TResponse postNoRequest(const QString &resource)
|
||||
@@ -78,7 +80,7 @@ namespace BlackCore
|
||||
|
||||
QNetworkRequest request(url);
|
||||
request.setRawHeader("Authorization", "Bearer " + m_jwt);
|
||||
QNetworkReply *reply = nam->post(request, QByteArray());
|
||||
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> reply(nam->post(request, QByteArray()));
|
||||
while (! reply->isFinished()) { loop.exec(); }
|
||||
qDebug() << "POST" << resource << "(" << m_watch.elapsed() << "ms)";
|
||||
|
||||
@@ -90,11 +92,55 @@ namespace BlackCore
|
||||
|
||||
const QJsonDocument doc = QJsonDocument::fromJson(reply->readAll());
|
||||
TResponse response = TResponse::fromJson(doc.object());
|
||||
|
||||
reply->deleteLater();
|
||||
return response;
|
||||
}
|
||||
|
||||
template<typename TResponse>
|
||||
QVector<TResponse> getAsVector(const QString &resource)
|
||||
{
|
||||
if (! m_isAuthenticated)
|
||||
{
|
||||
qDebug() << "Not authenticated";
|
||||
return {};
|
||||
}
|
||||
|
||||
checkExpiry();
|
||||
|
||||
QNetworkAccessManager *nam = sApp->getNetworkAccessManager();
|
||||
|
||||
m_watch.start();
|
||||
QUrl url(m_address);
|
||||
url.setPath(resource);
|
||||
QEventLoop loop;
|
||||
connect(nam, &QNetworkAccessManager::finished, &loop, &QEventLoop::quit);
|
||||
|
||||
QNetworkRequest request(url);
|
||||
request.setRawHeader("Authorization", "Bearer " + m_jwt);
|
||||
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> reply(nam->get(request));
|
||||
while (! reply->isFinished()) { loop.exec(); }
|
||||
qDebug() << "GET" << resource << "(" << m_watch.elapsed() << "ms)";
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError)
|
||||
{
|
||||
qWarning() << "GET" << resource << "failed:" << reply->errorString();
|
||||
return {};
|
||||
}
|
||||
|
||||
const QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll());
|
||||
QVector<TResponse> dtos;
|
||||
if (jsonDoc.isArray())
|
||||
{
|
||||
QJsonArray rootArray = jsonDoc.array();
|
||||
for (auto o : rootArray)
|
||||
{
|
||||
QJsonObject d = o.toObject();
|
||||
TResponse dto = TResponse::fromJson(d);
|
||||
dtos.push_back(dto);
|
||||
}
|
||||
}
|
||||
return dtos;
|
||||
}
|
||||
|
||||
void postNoResponse(const QString &resource, const QJsonDocument &json);
|
||||
void deleteResource(const QString &resource);
|
||||
void checkExpiry();
|
||||
|
||||
@@ -97,6 +97,11 @@ namespace BlackCore
|
||||
m_apiServerConnection.updateTransceivers(callsign, transceivers);
|
||||
}
|
||||
|
||||
QVector<StationDto> ClientConnection::getAllAliasedStations()
|
||||
{
|
||||
return m_apiServerConnection.getAllAliasedStations();
|
||||
}
|
||||
|
||||
void ClientConnection::connectToVoiceServer()
|
||||
{
|
||||
QHostAddress localAddress(QHostAddress::AnyIPv4);
|
||||
|
||||
@@ -64,6 +64,8 @@ namespace BlackCore
|
||||
|
||||
void updateTransceivers(const QString &callsign, const QVector<TransceiverDto> &transceivers);
|
||||
|
||||
QVector<StationDto> getAllAliasedStations();
|
||||
|
||||
signals:
|
||||
void audioReceived(const AudioRxOnTransceiversDto &dto);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user