8#include <QNetworkReply>
10#include <QScopedPointer>
11#include <QScopedPointerDeleteLater>
16#include <QWriteLocker>
26using namespace swift::misc::aviation;
27using namespace swift::misc::network;
28using namespace swift::misc::weather;
31namespace swift::core::vatsim
35 this->reloadSettings();
47 return m_metars.getMetarForAirport(icao);
52 void CVatsimMetarReader::read()
60 const CUrl url(sApp->getVatsimMetarUrl());
65 Q_ASSERT_X(sApp, Q_FUNC_INFO,
"No Application");
66 this->
getFromNetworkAndLog(url.withAppendedQuery(
"id=all"), { this, &CVatsimMetarReader::decodeMetars });
69 void CVatsimMetarReader::decodeMetars(
QNetworkReply *nwReplyPtr)
85 const QUrl url = nwReply->url();
86 const QString metarUrl = url.
toString();
90 QString metarData = nwReply->readAll();
95 CLogMessage(
this).warning(u
"No METAR data from '%1', skipped") << metarUrl;
100 CLogMessage(
this).info(u
"METAR file from '%1' has same content, skipped") << metarUrl;
105 int invalidLines = 0;
106 QTextStream lineReader(&metarData);
107 while (!lineReader.atEnd())
113 const QString line = lineReader.readLine();
119 const CMetar metar = m_metarDecoder.decode(line);
120 if (metar != CMetar())
130 CLogMessage(
this).info(u
"METARs: %1 Metars (invalid %2) from '%3'")
131 << metars.
size() << invalidLines << metarUrl;
143 CLogMessage(
this).warning(u
"Reading METARs failed '%1' for '%2'") << nwReply->errorString() << metarUrl;
149 void CVatsimMetarReader::reloadSettings()
151 const CReaderSettings s = m_settings.get();
153 std::chrono::milliseconds(s.getPeriodicTime().toMs()));
void threadAssertCheck() const
Make sure everything runs correctly in own thread.
void logNetworkReplyReceived(QNetworkReply *reply)
Network reply received, mark in m_urlReadLog.
QReadWriteLock m_lock
lock which can be used from the derived classes
bool didContentChange(const QString &content, int startPosition=-1)
Stores new content hash and returns if content changed (based on hash value.
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.?
CThreadedReaderPeriodic(QObject *owner, const QString &name)
Constructor.
void setInitialAndPeriodicTime(std::chrono::milliseconds initialTime, std::chrono::milliseconds periodicTime)
Set initial and periodic times Changes only apply after the next time the timer restarts.
const QObject * owner() const
Owner of the worker.
Class for emitting a log message.
Derived & info(const char16_t(&format)[N])
Set the severity to info, providing a format string.
size_type size() const
Returns number of elements in the sequence.
void push_back(const T &value)
Appends an element at the end of the sequence.
Value object encapsulating information of airport ICAO data.
@ 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.
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QString toString(QUrl::FormattingOptions options) const const