refs #602, CWebDataServices and CCookieManager now part of CApplication

* New hint flag: DB data for the client will no longer be web loaded but fetched from cache whenever possible
* No public constructors for the 2 classes
* adjusted main
This commit is contained in:
Klaus Basan
2016-02-24 00:01:04 +01:00
committed by Mathew Sutcliffe
parent 4b7ba4f117
commit 65af7d87da
11 changed files with 54 additions and 71 deletions

View File

@@ -7,8 +7,8 @@
* contained in the LICENSE file. * contained in the LICENSE file.
*/ */
#include "application.h"
#include "contextnetworkimpl.h" #include "contextnetworkimpl.h"
#include "corefacade.h"
#include "contextapplication.h" #include "contextapplication.h"
#include "contextsimulator.h" #include "contextsimulator.h"
#include "contextownaircraftimpl.h" #include "contextownaircraftimpl.h"
@@ -57,9 +57,9 @@ namespace BlackCore
this->m_networkDataUpdateTimer->start(30 * 1000); this->m_networkDataUpdateTimer->start(30 * 1000);
// 3. data reader, start reading when setup is synced with xx delay // 3. data reader, start reading when setup is synced with xx delay
this->m_webDataReader = new CWebDataServices(CWebReaderFlags::AllReaders, this); Q_ASSERT_X(sApp->getWebDataServices(), Q_FUNC_INFO, "Missing web data services");
this->m_webReaderSignalConnections.append( this->m_webReaderSignalConnections.append(
this->m_webDataReader->connectDataReadSignal( sApp->getWebDataServices()->connectDataReadSignal(
this, // the object here must be the same as in the bind this, // the object here must be the same as in the bind
std::bind(&CContextNetwork::webServiceDataRead, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3) std::bind(&CContextNetwork::webServiceDataRead, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)
) )
@@ -67,8 +67,7 @@ namespace BlackCore
// 4. Airspace contents // 4. Airspace contents
Q_ASSERT_X(this->getRuntime()->getCContextOwnAircraft(), Q_FUNC_INFO, "this and own aircraft context must be local"); Q_ASSERT_X(this->getRuntime()->getCContextOwnAircraft(), Q_FUNC_INFO, "this and own aircraft context must be local");
Q_ASSERT_X(this->m_webDataReader, Q_FUNC_INFO, "Missing reader"); this->m_airspace = new CAirspaceMonitor(this->getRuntime()->getCContextOwnAircraft(), this->m_network, sApp->getWebDataServices(), this);
this->m_airspace = new CAirspaceMonitor(this->getRuntime()->getCContextOwnAircraft(), this->m_network, this->m_webDataReader, this);
connect(this->m_airspace, &CAirspaceMonitor::changedAtcStationsOnline, this, &CContextNetwork::changedAtcStationsOnline); connect(this->m_airspace, &CAirspaceMonitor::changedAtcStationsOnline, this, &CContextNetwork::changedAtcStationsOnline);
connect(this->m_airspace, &CAirspaceMonitor::changedAtcStationsBooked, this, &CContextNetwork::changedAtcStationsBooked); connect(this->m_airspace, &CAirspaceMonitor::changedAtcStationsBooked, this, &CContextNetwork::changedAtcStationsBooked);
connect(this->m_airspace, &CAirspaceMonitor::changedAtcStationOnlineConnectionStatus, this, &CContextNetwork::changedAtcStationOnlineConnectionStatus); connect(this->m_airspace, &CAirspaceMonitor::changedAtcStationOnlineConnectionStatus, this, &CContextNetwork::changedAtcStationOnlineConnectionStatus);
@@ -135,7 +134,6 @@ namespace BlackCore
{ {
this->disconnect(); // all signals this->disconnect(); // all signals
this->disconnectReaderSignals(); // disconnect this->disconnectReaderSignals(); // disconnect
this->m_webDataReader->gracefulShutdown();
if (this->isConnected()) { this->disconnectFromNetwork(); } if (this->isConnected()) { this->disconnectFromNetwork(); }
if (this->m_airspace) { this->m_airspace->gracefulShutdown(); } if (this->m_airspace) { this->m_airspace->gracefulShutdown(); }
@@ -374,16 +372,16 @@ namespace BlackCore
CServerList CContextNetwork::getVatsimFsdServers() const CServerList CContextNetwork::getVatsimFsdServers() const
{ {
Q_ASSERT_X(this->m_webDataReader, Q_FUNC_INFO, "Missing data reader"); Q_ASSERT_X(sApp->getWebDataServices(), Q_FUNC_INFO, "Missing data reader");
if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
return this->m_webDataReader->getVatsimFsdServers(); return sApp->getWebDataServices()->getVatsimFsdServers();
} }
CServerList CContextNetwork::getVatsimVoiceServers() const CServerList CContextNetwork::getVatsimVoiceServers() const
{ {
Q_ASSERT_X(this->m_webDataReader, Q_FUNC_INFO, "Missing data reader"); Q_ASSERT_X(sApp->getWebDataServices(), Q_FUNC_INFO, "Missing data reader");
if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
return this->m_webDataReader->getVatsimVoiceServers(); return sApp->getWebDataServices()->getVatsimVoiceServers();
} }
void CContextNetwork::ps_fsdConnectionStatusChanged(INetwork::ConnectionStatus from, INetwork::ConnectionStatus to) void CContextNetwork::ps_fsdConnectionStatusChanged(INetwork::ConnectionStatus from, INetwork::ConnectionStatus to)
@@ -569,8 +567,8 @@ namespace BlackCore
void CContextNetwork::readAtcBookingsFromSource() const void CContextNetwork::readAtcBookingsFromSource() const
{ {
if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
Q_ASSERT_X(this->m_webDataReader, Q_FUNC_INFO, "missing reader"); Q_ASSERT_X(sApp->getWebDataServices(), Q_FUNC_INFO, "missing reader");
this->m_webDataReader->readInBackground(BlackMisc::Network::CEntityFlags::BookingEntity); sApp->getWebDataServices()->readInBackground(BlackMisc::Network::CEntityFlags::BookingEntity);
} }
bool CContextNetwork::updateAircraftRendered(const CCallsign &callsign, bool rendered, const CIdentifier &originator) bool CContextNetwork::updateAircraftRendered(const CCallsign &callsign, bool rendered, const CIdentifier &originator)

View File

@@ -238,7 +238,6 @@ namespace BlackCore
private: private:
CAirspaceMonitor *m_airspace = nullptr; CAirspaceMonitor *m_airspace = nullptr;
INetwork *m_network = nullptr; INetwork *m_network = nullptr;
CWebDataServices *m_webDataReader = nullptr; //!< web service readers
QList<QMetaObject::Connection> m_webReaderSignalConnections; QList<QMetaObject::Connection> m_webReaderSignalConnections;
INetwork::ConnectionStatus m_currentStatus = INetwork::Disconnected; //!< used to detect pending connections INetwork::ConnectionStatus m_currentStatus = INetwork::Disconnected; //!< used to detect pending connections
QTimer *m_networkDataUpdateTimer = nullptr; //!< general updates such as ATIS, frequencies, see requestDataUpdates() QTimer *m_networkDataUpdateTimer = nullptr; //!< general updates such as ATIS, frequencies, see requestDataUpdates()

View File

@@ -18,29 +18,6 @@ using namespace BlackMisc;
namespace BlackCore namespace BlackCore
{ {
CCookieManager *CCookieManager::instance()
{
static CCookieManager *manager = nullptr;
if (!manager)
{
Q_ASSERT_X(CThreadUtils::isCurrentThreadApplicationThread(), Q_FUNC_INFO, "Supposed to run in application thread");
manager = new CCookieManager(QCoreApplication::instance());
}
return manager;
}
void CCookieManager::resetParent()
{
instance()->setParent(nullptr);
}
void CCookieManager::setToAccessManager(QNetworkAccessManager *manager)
{
if (!manager) { return; }
manager->setCookieJar(instance());
resetParent();
}
CCookieManager::CCookieManager(QObject *parent) : QNetworkCookieJar(parent) CCookieManager::CCookieManager(QObject *parent) : QNetworkCookieJar(parent)
{ {
// code // code

View File

@@ -21,14 +21,17 @@
namespace BlackCore namespace BlackCore
{ {
class CApplication;
/*! /*!
* Centralized cookie manager, * Cookie manager, which allows thread safe sharing of cookies
* which allows thread safe sharing of cookies
*/ */
class BLACKCORE_EXPORT CCookieManager : QNetworkCookieJar class BLACKCORE_EXPORT CCookieManager : public QNetworkCookieJar
{ {
Q_OBJECT Q_OBJECT
friend class CApplication;
public: public:
//! cookiesForUrl::setCookiesFromUrl //! cookiesForUrl::setCookiesFromUrl
//! \threadsafe //! \threadsafe
@@ -58,19 +61,10 @@ namespace BlackCore
//! \threadsafe //! \threadsafe
virtual bool updateCookie(const QNetworkCookie &cookie) override; virtual bool updateCookie(const QNetworkCookie &cookie) override;
//! Our central access manager
static CCookieManager *instance();
//! Set the central instance to the given access manager
static void setToAccessManager(QNetworkAccessManager *manager);
private: private:
//! Constructor //! Constructor
CCookieManager(QObject *parent = nullptr); CCookieManager(QObject *parent = nullptr);
//! Reset the parent, required when CookieManager is set to QNetworkAccessManager
static void resetParent();
mutable QReadWriteLock m_lock { QReadWriteLock::Recursive }; mutable QReadWriteLock m_lock { QReadWriteLock::Recursive };
}; };

View File

@@ -36,9 +36,8 @@ using namespace BlackMisc::Weather;
namespace BlackCore namespace BlackCore
{ {
CWebDataServices::CWebDataServices( CWebDataServices::CWebDataServices(CWebReaderFlags::WebReader readerFlags, CWebReaderFlags::DbReaderHint hint, QObject *parent) :
CWebReaderFlags::WebReader readerFlags, QObject *parent) : QObject(parent), m_readerFlags(readerFlags), m_dbHint(hint)
QObject(parent), m_readerFlags(readerFlags)
{ {
if (!sApp) { return; } // shutting down if (!sApp) { return; } // shutting down
@@ -47,7 +46,6 @@ namespace BlackCore
this->setObjectName("CWebDataReader"); this->setObjectName("CWebDataReader");
this->initReaders(readerFlags); this->initReaders(readerFlags);
this->initWriters(); this->initWriters();
this->readInBackground(CEntityFlags::AllEntities, 500); this->readInBackground(CEntityFlags::AllEntities, 500);
} }

View File

@@ -38,6 +38,7 @@ namespace BlackCore
class CIcaoDataReader; class CIcaoDataReader;
class CModelDataReader; class CModelDataReader;
class CDatabaseWriter; class CDatabaseWriter;
class CApplication;
/*! /*!
* Encapsulates reading data from web sources * Encapsulates reading data from web sources
@@ -49,10 +50,9 @@ namespace BlackCore
Q_OBJECT Q_OBJECT
Q_INTERFACES(BlackMisc::Network::IWebDataServicesProvider) Q_INTERFACES(BlackMisc::Network::IWebDataServicesProvider)
public: friend class CApplication;
//! Constructor
CWebDataServices(CWebReaderFlags::WebReader readerFlags, QObject *parent = nullptr);
public:
//! Shutdown //! Shutdown
void gracefulShutdown(); void gracefulShutdown();
@@ -71,6 +71,9 @@ namespace BlackCore
//! Reader flags //! Reader flags
CWebReaderFlags::WebReader getReaderFlags() const { return m_readerFlags; } CWebReaderFlags::WebReader getReaderFlags() const { return m_readerFlags; }
//! Reader flags
CWebReaderFlags::DbReaderHint getDbHint() const { return m_dbHint; }
//! Log categories //! Log categories
static const BlackMisc::CLogCategoryList &getLogCategories(); static const BlackMisc::CLogCategoryList &getLogCategories();
@@ -133,10 +136,13 @@ namespace BlackCore
// ------------------------ provider functionality end ---------------------------- // ------------------------ provider functionality end ----------------------------
protected:
//! Constructor
CWebDataServices(CWebReaderFlags::WebReader readerFlags, CWebReaderFlags:: DbReaderHint hint, QObject *parent = nullptr);
// --------------------------------------------- // ---------------------------------------------
// Consider to use the connect method of the provider to connect by entity // Consider to use the connect method of the provider to connect by entity
// --------------------------------------------- // ---------------------------------------------
public slots: public slots:
//! First read (allows to immediately read in background) //! First read (allows to immediately read in background)
void readInBackground(BlackMisc::Network::CEntityFlags::Entity entities = BlackMisc::Network::CEntityFlags::AllEntities, int delayMs = 0); void readInBackground(BlackMisc::Network::CEntityFlags::Entity entities = BlackMisc::Network::CEntityFlags::AllEntities, int delayMs = 0);
@@ -165,6 +171,7 @@ namespace BlackCore
void initWriters(); void initWriters();
CWebReaderFlags::WebReader m_readerFlags = CWebReaderFlags::WebReaderFlag::None; //!< which readers are available CWebReaderFlags::WebReader m_readerFlags = CWebReaderFlags::WebReaderFlag::None; //!< which readers are available
CWebReaderFlags::DbReaderHint m_dbHint = CWebReaderFlags::NoHint; //!< how to read DB data
bool m_initialRead = false; //!< Initial read conducted bool m_initialRead = false; //!< Initial read conducted
BlackMisc::CData<BlackCore::Data::GlobalSetup> m_setup {this, &CWebDataServices::ps_setupChanged}; //!< setup cache BlackMisc::CData<BlackCore::Data::GlobalSetup> m_setup {this, &CWebDataServices::ps_setupChanged}; //!< setup cache

View File

@@ -40,6 +40,16 @@ namespace BlackCore
}; };
Q_DECLARE_FLAGS(WebReader, WebReaderFlag) Q_DECLARE_FLAGS(WebReader, WebReaderFlag)
//! How to read DB data
enum DbReaderHintFlag
{
NoHint = 0,
FromDb = 1 << 1, ///< directly from DB
FromJsonFile = 1 << 2, ///< from the JSON files
FromCache = 1 << 3, ///< try cache first
};
Q_DECLARE_FLAGS(DbReaderHint, DbReaderHintFlag)
//! Relationship between reader and entity //! Relationship between reader and entity
static WebReader entityToReader(BlackMisc::Network::CEntityFlags::Entity entity); static WebReader entityToReader(BlackMisc::Network::CEntityFlags::Entity entity);
@@ -53,6 +63,9 @@ namespace BlackCore
Q_DECLARE_METATYPE(BlackCore::CWebReaderFlags::WebReaderFlag) Q_DECLARE_METATYPE(BlackCore::CWebReaderFlags::WebReaderFlag)
Q_DECLARE_METATYPE(BlackCore::CWebReaderFlags::WebReader) Q_DECLARE_METATYPE(BlackCore::CWebReaderFlags::WebReader)
Q_DECLARE_METATYPE(BlackCore::CWebReaderFlags::DbReaderHintFlag)
Q_DECLARE_METATYPE(BlackCore::CWebReaderFlags::DbReaderHint)
Q_DECLARE_OPERATORS_FOR_FLAGS(BlackCore::CWebReaderFlags::WebReader) Q_DECLARE_OPERATORS_FOR_FLAGS(BlackCore::CWebReaderFlags::WebReader)
Q_DECLARE_OPERATORS_FOR_FLAGS(BlackCore::CWebReaderFlags::DbReaderHint)
#endif #endif

View File

@@ -28,7 +28,9 @@ using namespace BlackGui;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication qa(argc, argv); QApplication qa(argc, argv);
Q_UNUSED(qa);
CGuiApplication a("swift mapping tool", CIcons::swiftDatabase48()); CGuiApplication a("swift mapping tool", CIcons::swiftDatabase48());
a.useWebDataServices(BlackCore::CWebReaderFlags::AllSwiftDbReaders, BlackCore::CWebReaderFlags::FromDb);
a.start(); a.start();
CSwiftData w; CSwiftData w;
w.show(); w.show();

View File

@@ -32,8 +32,7 @@ using namespace BlackGui::Components;
CSwiftData::CSwiftData(QWidget *parent) : CSwiftData::CSwiftData(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
CIdentifiable(this), CIdentifiable(this),
ui(new Ui::CSwiftData), ui(new Ui::CSwiftData)
m_webDataReader(new CWebDataServices(CWebReaderFlags::AllSwiftDbReaders, this))
{ {
ui->setupUi(this); ui->setupUi(this);
this->init(); this->init();
@@ -58,7 +57,7 @@ void CSwiftData::closeEvent(QCloseEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
this->performGracefulShutdown(); this->performGracefulShutdown();
QApplication::exit(); sGui->exit();
} }
void CSwiftData::ps_appendLogMessage(const CStatusMessage &message) void CSwiftData::ps_appendLogMessage(const CStatusMessage &message)
@@ -100,9 +99,9 @@ void CSwiftData::initLogDisplay()
void CSwiftData::initReaders() void CSwiftData::initReaders()
{ {
Q_ASSERT_X(this->m_webDataReader, Q_FUNC_INFO, "Missing reader"); Q_ASSERT_X(sApp->getWebDataServices(), Q_FUNC_INFO, "Missing reader");
this->ui->comp_MainInfoArea->setProvider(this->m_webDataReader); this->ui->comp_MainInfoArea->setProvider(sApp->getWebDataServices());
this->ui->comp_InfoBar->setProvider(this->m_webDataReader); this->ui->comp_InfoBar->setProvider(sApp->getWebDataServices());
// web data will be read automatically when setup is syncronized // web data will be read automatically when setup is syncronized
} }
@@ -139,11 +138,7 @@ void CSwiftData::initMenu()
void CSwiftData::performGracefulShutdown() void CSwiftData::performGracefulShutdown()
{ {
if (this->m_webDataReader) // void
{
m_webDataReader->gracefulShutdown();
m_webDataReader = nullptr;
}
} }
void CSwiftData::displayConsole() void CSwiftData::displayConsole()

View File

@@ -72,7 +72,6 @@ private:
QScopedPointer<Ui::CSwiftData> ui; QScopedPointer<Ui::CSwiftData> ui;
BlackGui::CManagedStatusBar m_statusBar; BlackGui::CManagedStatusBar m_statusBar;
BlackCore::CWebDataServices *m_webDataReader = nullptr;
BlackMisc::CData<BlackCore::Data::GlobalSetup> m_setup {this, &CSwiftData::ps_setupChanged}; //!< setup cache BlackMisc::CData<BlackCore::Data::GlobalSetup> m_setup {this, &CSwiftData::ps_setupChanged}; //!< setup cache
BlackMisc::CData<BlackCore::Data::UpdateInfo> m_updateInfo { this }; //!< download / version data BlackMisc::CData<BlackCore::Data::UpdateInfo> m_updateInfo { this }; //!< download / version data
}; };

View File

@@ -19,6 +19,7 @@ CSwiftGuiStdApplication::CSwiftGuiStdApplication() : CGuiApplication("swift pilo
this->addParserOption(this->m_cmdFacadeMode); this->addParserOption(this->m_cmdFacadeMode);
this->addWindowModeOption(); this->addWindowModeOption();
this->addDBusAddressOption(); this->addDBusAddressOption();
this->useWebDataServices(CWebReaderFlags::AllReaders, CWebReaderFlags::FromCache);
} }
bool CSwiftGuiStdApplication::startHookIn() bool CSwiftGuiStdApplication::startHookIn()