8 #include <QNetworkReply>
10 #include <QScopedPointer>
11 #include <QScopedPointerDeleteLater>
13 #include <QTextStream>
16 #include <QWriteLocker>
26 using namespace swift::misc::aviation;
27 using namespace swift::misc::network;
28 using namespace swift::misc::weather;
31 namespace swift::core::vatsim
33 CVatsimMetarReader::CVatsimMetarReader(QObject *owner) :
CThreadedReader(owner,
"CVatsimMetarReader")
35 this->reloadSettings();
40 QPointer<CVatsimMetarReader> myself(
this);
42 if (!myself) {
return; }
61 void CVatsimMetarReader::read()
67 if (url.isEmpty()) {
return; }
68 Q_ASSERT_X(
sApp, Q_FUNC_INFO,
"No Application");
69 this->
getFromNetworkAndLog(url.withAppendedQuery(
"id=all"), { this, &CVatsimMetarReader::decodeMetars });
72 void CVatsimMetarReader::decodeMetars(QNetworkReply *nwReplyPtr)
76 QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr);
88 const QUrl url = nwReply->url();
89 const QString metarUrl = url.toString();
91 if (nwReply->error() == QNetworkReply::NoError)
93 QString metarData = nwReply->readAll();
96 if (metarData.isEmpty())
103 CLogMessage(
this).
info(u
"METAR file from '%1' has same content, skipped") << metarUrl;
108 int invalidLines = 0;
109 QTextStream lineReader(&metarData);
110 while (!lineReader.atEnd())
113 const QString line = lineReader.readLine();
115 if (line.contains(
"<html")) {
continue; }
118 else { invalidLines++; }
122 << metars.
size() << invalidLines << metarUrl;
129 emit
dataRead(CEntityFlags::MetarEntity, CEntityFlags::ReadFinished, metars.
size(), url);
134 CLogMessage(
this).
warning(u
"Reading METARs failed '%1' for '%2'") << nwReply->errorString() << metarUrl;
136 emit this->
dataRead(CEntityFlags::MetarEntity, CEntityFlags::ReadFailed, 0, url);
140 void CVatsimMetarReader::reloadSettings()
142 const CReaderSettings s = m_settings.
get();
SWIFT_CORE_EXPORT swift::core::CApplication * sApp
Single instance of application object.
swift::misc::network::CUrl getVatsimMetarUrl() const
Consolidated version of METAR URLs, either from CGlobalSetup or CVatsimSetup.
Support for threaded based reading and parsing tasks such as data files via http, or file system and ...
void threadAssertCheck() const
Make sure everthing 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.
void setInitialAndPeriodicTime(int initialTime, int periodicTime)
Set initial and periodic times.
bool doWorkCheck() const
Still enabled etc.?
T get() const
Get a copy of the current value.
Class for emitting a log message.
Derived & warning(const char16_t(&format)[N])
Set the severity to warning, providing a format string.
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.
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.
auto singleShot(int msec, QObject *target, F &&task)
Starts a single-shot timer which will call a task in the thread of the given object when it times out...