refs #602, remove QNetworkAccessManager from readers, use central one

This commit is contained in:
Klaus Basan
2016-02-26 18:17:01 +01:00
committed by Mathew Sutcliffe
parent fb046ae1fb
commit 12957f8ec0
7 changed files with 15 additions and 30 deletions

View File

@@ -150,7 +150,7 @@ namespace BlackCore
BlackMisc::Network::CUrl m_dbRootDirectoryUrl; //!< Root directory of DB BlackMisc::Network::CUrl m_dbRootDirectoryUrl; //!< Root directory of DB
BlackMisc::Network::CUrl m_vatsimBookingsUrl; //!< ATC bookings BlackMisc::Network::CUrl m_vatsimBookingsUrl; //!< ATC bookings
BlackMisc::Network::CUrl m_vatsimMetarsUrl; //!< METAR data BlackMisc::Network::CUrl m_vatsimMetarsUrl; //!< METAR data
BlackMisc::Network::CUrlList m_vatsimDataFileUrls; //!< Overall VATSIM data file BlackMisc::Network::CUrlList m_vatsimDataFileUrls; //!< Overall VATSIM data file / merely for bootstrapping the first time
BlackMisc::Network::CUrlList m_sharedUrls; //!< where we can obtain shared info files such as bootstrap, .. BlackMisc::Network::CUrlList m_sharedUrls; //!< where we can obtain shared info files such as bootstrap, ..
BlackMisc::Network::CUrlList m_newsUrls; //!< where we can obtain latest news BlackMisc::Network::CUrlList m_newsUrls; //!< where we can obtain latest news
BlackMisc::Network::CServerList m_fsdTestServers; //!< FSD test servers BlackMisc::Network::CServerList m_fsdTestServers; //!< FSD test servers

View File

@@ -7,6 +7,7 @@
* contained in the LICENSE file. * contained in the LICENSE file.
*/ */
#include "blackcore/application.h"
#include "blackmisc/sequence.h" #include "blackmisc/sequence.h"
#include "blackmisc/aviation/atcstation.h" #include "blackmisc/aviation/atcstation.h"
#include "blackmisc/network/user.h" #include "blackmisc/network/user.h"
@@ -25,8 +26,6 @@ namespace BlackCore
CVatsimBookingReader::CVatsimBookingReader(QObject *owner) : CVatsimBookingReader::CVatsimBookingReader(QObject *owner) :
CThreadedReader(owner, "CVatsimBookingReader") CThreadedReader(owner, "CVatsimBookingReader")
{ {
this->m_networkManager = new QNetworkAccessManager(this);
this->connect(this->m_networkManager, &QNetworkAccessManager::finished, this, &CVatsimBookingReader::ps_parseBookings);
this->connect(this->m_updateTimer, &QTimer::timeout, this, &CVatsimBookingReader::ps_read); this->connect(this->m_updateTimer, &QTimer::timeout, this, &CVatsimBookingReader::ps_read);
} }
@@ -39,19 +38,17 @@ namespace BlackCore
void CVatsimBookingReader::cleanup() void CVatsimBookingReader::cleanup()
{ {
delete this->m_networkManager; // void
this->m_networkManager = nullptr;
} }
void CVatsimBookingReader::ps_read() void CVatsimBookingReader::ps_read()
{ {
this->threadAssertCheck(); this->threadAssertCheck();
Q_ASSERT_X(this->m_networkManager, Q_FUNC_INFO, "No network manager"); Q_ASSERT_X(sApp, Q_FUNC_INFO, "No application");
QUrl url(m_setup.get().vatsimBookingsUrl()); QUrl url(m_setup.get().vatsimBookingsUrl());
if (url.isEmpty()) { return; } if (url.isEmpty()) { return; }
QNetworkRequest request(url); sApp->getFromNetwork(url, { this, &CVatsimBookingReader::ps_parseBookings});
this->m_networkManager->get(request);
} }
void CVatsimBookingReader::ps_parseBookings(QNetworkReply *nwReplyPtr) void CVatsimBookingReader::ps_parseBookings(QNetworkReply *nwReplyPtr)

View File

@@ -57,7 +57,6 @@ namespace BlackCore
private: private:
BlackMisc::CData<BlackCore::Data::GlobalSetup> m_setup {this}; //!< setup cache BlackMisc::CData<BlackCore::Data::GlobalSetup> m_setup {this}; //!< setup cache
QNetworkAccessManager *m_networkManager = nullptr;
}; };
} }

View File

@@ -7,6 +7,8 @@
* contained in the LICENSE file. * contained in the LICENSE file.
*/ */
#include "blackcore/vatsimdatafilereader.h"
#include "blackcore/application.h"
#include "blackmisc/sequence.h" #include "blackmisc/sequence.h"
#include "blackmisc/aviation/atcstation.h" #include "blackmisc/aviation/atcstation.h"
#include "blackmisc/network/user.h" #include "blackmisc/network/user.h"
@@ -14,8 +16,6 @@
#include "blackmisc/network/urllist.h" #include "blackmisc/network/urllist.h"
#include "blackmisc/network/entityflags.h" #include "blackmisc/network/entityflags.h"
#include "blackmisc/logmessage.h" #include "blackmisc/logmessage.h"
#include "blackcore/vatsimdatafilereader.h"
#include <QRegularExpression> #include <QRegularExpression>
using namespace BlackMisc; using namespace BlackMisc;
@@ -31,8 +31,6 @@ namespace BlackCore
CVatsimDataFileReader::CVatsimDataFileReader(QObject *owner) : CVatsimDataFileReader::CVatsimDataFileReader(QObject *owner) :
CThreadedReader(owner, "CVatsimDataFileReader") CThreadedReader(owner, "CVatsimDataFileReader")
{ {
this->m_networkManager = new QNetworkAccessManager(this);
this->connect(this->m_networkManager, &QNetworkAccessManager::finished, this, &CVatsimDataFileReader::ps_parseVatsimFile);
this->connect(this->m_updateTimer, &QTimer::timeout, this, &CVatsimDataFileReader::ps_read); this->connect(this->m_updateTimer, &QTimer::timeout, this, &CVatsimDataFileReader::ps_read);
} }
@@ -150,8 +148,7 @@ namespace BlackCore
void CVatsimDataFileReader::cleanup() void CVatsimDataFileReader::cleanup()
{ {
delete this->m_networkManager; // void
this->m_networkManager = nullptr;
} }
void CVatsimDataFileReader::ps_read() void CVatsimDataFileReader::ps_read()
@@ -163,9 +160,9 @@ namespace BlackCore
// see http://qt-project.org/doc/qt-4.7/qnetworkaccessmanager.html // see http://qt-project.org/doc/qt-4.7/qnetworkaccessmanager.html
QUrl url(m_setup.get().vatsimDataFileUrls().getRandomUrl()); QUrl url(m_setup.get().vatsimDataFileUrls().getRandomUrl());
if (url.isEmpty()) { return; } if (url.isEmpty()) { return; }
Q_ASSERT_X(this->m_networkManager, Q_FUNC_INFO, "Missing network manager"); Q_ASSERT_X(sApp, Q_FUNC_INFO, "Missing application");
QNetworkRequest request(url); sApp->getFromNetwork(url, { this, &CVatsimDataFileReader::ps_parseVatsimFile});
this->m_networkManager->get(request);
} }
void CVatsimDataFileReader::ps_parseVatsimFile(QNetworkReply *nwReplyPtr) void CVatsimDataFileReader::ps_parseVatsimFile(QNetworkReply *nwReplyPtr)

View File

@@ -24,7 +24,6 @@
#include <QObject> #include <QObject>
#include <QTimer> #include <QTimer>
#include <QNetworkReply>
#include <QReadWriteLock> #include <QReadWriteLock>
namespace BlackCore namespace BlackCore
@@ -124,7 +123,6 @@ namespace BlackCore
void ps_read(); void ps_read();
private: private:
QNetworkAccessManager *m_networkManager = nullptr;
BlackMisc::Network::CServerList m_voiceServers; BlackMisc::Network::CServerList m_voiceServers;
BlackMisc::Network::CServerList m_fsdServers; BlackMisc::Network::CServerList m_fsdServers;
BlackMisc::Aviation::CAtcStationList m_atcStations; BlackMisc::Aviation::CAtcStationList m_atcStations;
@@ -147,7 +145,6 @@ namespace BlackCore
//! Get current section //! Get current section
static Section currentLineToSection(const QString &currentLine); static Section currentLineToSection(const QString &currentLine);
}; };
} // ns } // ns

View File

@@ -8,6 +8,7 @@
*/ */
#include "blackcore/vatsimmetarreader.h" #include "blackcore/vatsimmetarreader.h"
#include "blackcore/application.h"
#include "blackmisc/network/entityflags.h" #include "blackmisc/network/entityflags.h"
#include "blackmisc/sequence.h" #include "blackmisc/sequence.h"
#include "blackmisc/logmessage.h" #include "blackmisc/logmessage.h"
@@ -26,8 +27,6 @@ namespace BlackCore
CVatsimMetarReader::CVatsimMetarReader(QObject *owner) : CVatsimMetarReader::CVatsimMetarReader(QObject *owner) :
CThreadedReader(owner, "CVatsimMetarReader") CThreadedReader(owner, "CVatsimMetarReader")
{ {
this->m_networkManager = new QNetworkAccessManager(this);
this->connect(this->m_networkManager, &QNetworkAccessManager::finished, this, &CVatsimMetarReader::ps_decodeMetars);
this->connect(this->m_updateTimer, &QTimer::timeout, this, &CVatsimMetarReader::ps_readMetars); this->connect(this->m_updateTimer, &QTimer::timeout, this, &CVatsimMetarReader::ps_readMetars);
} }
@@ -58,8 +57,7 @@ namespace BlackCore
void CVatsimMetarReader::cleanup() void CVatsimMetarReader::cleanup()
{ {
delete this->m_networkManager; // void
this->m_networkManager = nullptr;
} }
void CVatsimMetarReader::ps_readMetars() void CVatsimMetarReader::ps_readMetars()
@@ -67,9 +65,8 @@ namespace BlackCore
this->threadAssertCheck(); this->threadAssertCheck();
QUrl url(m_setup.get().vatsimMetarsUrl()); QUrl url(m_setup.get().vatsimMetarsUrl());
if (url.isEmpty()) { return; } if (url.isEmpty()) { return; }
Q_ASSERT_X(this->m_networkManager, Q_FUNC_INFO, "No network manager"); Q_ASSERT_X(sApp, Q_FUNC_INFO, "No Application");
QNetworkRequest request(url); sApp->getFromNetwork(url, { this, &CVatsimMetarReader::ps_decodeMetars});
this->m_networkManager->get(request);
} }
void CVatsimMetarReader::ps_decodeMetars(QNetworkReply *nwReplyPtr) void CVatsimMetarReader::ps_decodeMetars(QNetworkReply *nwReplyPtr)

View File

@@ -20,7 +20,6 @@
#include <QObject> #include <QObject>
#include <QTimer> #include <QTimer>
#include <QNetworkReply>
#include <QReadWriteLock> #include <QReadWriteLock>
namespace BlackCore namespace BlackCore
@@ -69,7 +68,6 @@ namespace BlackCore
void ps_readMetars(); void ps_readMetars();
private: private:
QNetworkAccessManager *m_networkManager = nullptr;
BlackMisc::Weather::CMetarDecoder m_metarDecoder; BlackMisc::Weather::CMetarDecoder m_metarDecoder;
BlackMisc::Weather::CMetarSet m_metars; BlackMisc::Weather::CMetarSet m_metars;
BlackMisc::CData<BlackCore::Data::GlobalSetup> m_setup {this}; //!< setup cache BlackMisc::CData<BlackCore::Data::GlobalSetup> m_setup {this}; //!< setup cache