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
35 this->reloadSettings();
52 void CVatsimMetarReader::read()
58 if (url.isEmpty()) {
return; }
59 Q_ASSERT_X(
sApp, Q_FUNC_INFO,
"No Application");
60 this->
getFromNetworkAndLog(url.withAppendedQuery(
"id=all"), { this, &CVatsimMetarReader::decodeMetars });
63 void CVatsimMetarReader::decodeMetars(QNetworkReply *nwReplyPtr)
67 QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr);
79 const QUrl url = nwReply->url();
80 const QString metarUrl = url.toString();
82 if (nwReply->error() == QNetworkReply::NoError)
84 QString metarData = nwReply->readAll();
87 if (metarData.isEmpty())
94 CLogMessage(
this).
info(u
"METAR file from '%1' has same content, skipped") << metarUrl;
100 QTextStream lineReader(&metarData);
101 while (!lineReader.atEnd())
104 const QString line = lineReader.readLine();
106 if (line.contains(
"<html")) {
continue; }
109 else { invalidLines++; }
113 << metars.
size() << invalidLines << metarUrl;
120 emit
dataRead(CEntityFlags::MetarEntity, CEntityFlags::ReadFinished, metars.
size(), url);
125 CLogMessage(
this).
warning(u
"Reading METARs failed '%1' for '%2'") << nwReply->errorString() << metarUrl;
127 emit this->
dataRead(CEntityFlags::MetarEntity, CEntityFlags::ReadFailed, 0, url);
131 void CVatsimMetarReader::reloadSettings()
133 const CReaderSettings s = m_settings.
get();
135 std::chrono::milliseconds(s.getPeriodicTime().toMs()));
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.
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.?
Periodically executes doWorkImpl() in a separate thread.
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.
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.