10#include <QNetworkReply>
11#include <QScopedPointer>
12#include <QScopedPointerDeleteLater>
26using namespace swift::misc::aviation;
27using namespace swift::misc::network;
28using namespace swift::misc::simulation;
29using namespace swift::misc::physical_quantities;
32namespace swift::core::vatsim
41 Q_ASSERT_X(
hasStarted(), Q_FUNC_INFO,
"Thread was not started yet!");
56 void CVatsimStatusFileReader::read()
64 Q_ASSERT_X(sApp, Q_FUNC_INFO,
"Missing application");
65 const CUrl url(sApp->getGlobalSetup().getVatsimStatusFileUrl());
70 CLogMessage(
this).
info(u
"Trigger read of VATSIM status file from '%1'") << url.toQString(
true);
74 void CVatsimStatusFileReader::parseVatsimFile(QNetworkReply *nwReplyPtr)
78 QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr);
84 CLogMessage(
this).debug() << Q_FUNC_INFO;
85 CLogMessage(
this).info(u
"Terminated VATSIM status file parsing process");
90 const QString urlString = nwReply->url().toString();
94 const QString statusFileData = nwReply->readAll();
97 if (statusFileData.
isEmpty())
return;
99 if (jsonDoc.isEmpty())
110 if (
const QJsonArray dataUrls = jsonDoc[
"data"][
"v3"].toArray(); !dataUrls.empty())
112 dataFileUrl = QUrl(dataUrls.at(0).toString());
115 if (
const QJsonArray serverFileUrls = jsonDoc[
"data"][
"servers"].toArray(); !serverFileUrls.empty())
117 serverFileUrl = QUrl(serverFileUrls.at(0).toString());
120 if (
const QJsonArray metarUrls = jsonDoc[
"metar"].toArray(); !metarUrls.empty())
122 metarFileUrl = QUrl(metarUrls.at(0).toString());
126 CVatsimSetup vs(m_lastGoodSetup.get());
127 const bool changed = vs.setUrls(dataFileUrl, serverFileUrl, metarFileUrl);
129 const CStatusMessage cacheMsg = m_lastGoodSetup.set(vs);
136 CLogMessage(
this).info(u
"Read VATSIM status file from '%1'") << urlString;
147 CLogMessage(
this).warning(u
"Reading VATSIM status file failed '%1' '%2'")
148 << nwReply->errorString() << urlString;
void threadAssertCheck() const
Make sure everything runs correctly in own thread.
void logNetworkReplyReceived(QNetworkReply *reply)
Network reply received, mark in m_urlReadLog.
CThreadedReader(const CThreadedReader &)=delete
Copy constructor.
QNetworkReply * getFromNetworkAndLog(const swift::misc::network::CUrl &url, const swift::misc::CSlot< void(QNetworkReply *)> &callback)
Get request from network, and log with m_urlReadLog.
bool doWorkCheck() const
Still enabled etc.?
swift::misc::network::CUrl getDataFileUrl() const
Data file URL.
swift::misc::network::CUrl getMetarFileUrl() const
METAR URL.
void readInBackgroundThread()
Start reading in own thread.
void dataRead(swift::misc::network::CEntityFlags::Entity entity, swift::misc::network::CEntityFlags::ReadState state, int bytes)
Data have been read.
void statusFileRead(int bytes)
Data have been read.
CVatsimStatusFileReader(QObject *owner)
Constructor.
const QObject * owner() const
Owner of the worker.
Class for emitting a log message.
static void preformatted(const CStatusMessage &statusMessage)
Sends a verbatim, preformatted message to the log.
Derived & info(const char16_t(&format)[N])
Set the severity to info, providing a format string.
bool isFailure() const
Operation considered unsuccessful.
bool hasStarted() const
True if the worker has started.
@ VatsimStatusFile
the VATSIM status file (URLs for data files etc.)
@ ReadFinished
reading done
@ ReadFailed
reading failed
Value object encapsulating information of a location, kind of simplified CValueObject compliant versi...
Core data traits (aka cached values) and classes.
Free functions in swift::misc.
QDateTime currentDateTime()
QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error)
bool isEmpty() const const
qsizetype size() const const
QByteArray toUtf8() const const