From 5829917694ec0ff0c8656e74ad264d640409e21d Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 26 Jan 2018 04:22:56 +0100 Subject: [PATCH] Ref T89, signal when server (flight network) connects * server contains the ecosystem * connect server signal with web data services (so ecosystem is available) --- src/blackcore/context/contextnetwork.h | 6 ++++ src/blackcore/context/contextnetworkimpl.cpp | 12 +++++-- src/blackcore/context/contextnetworkimpl.h | 2 +- src/blackcore/context/contextnetworkproxy.cpp | 4 ++- src/blackcore/webdataservices.cpp | 31 +++++++++++++++---- src/blackcore/webdataservices.h | 6 ++++ 6 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/blackcore/context/contextnetwork.h b/src/blackcore/context/contextnetwork.h index 210870ace..471678d47 100644 --- a/src/blackcore/context/contextnetwork.h +++ b/src/blackcore/context/contextnetwork.h @@ -147,8 +147,14 @@ namespace BlackCore void kicked(const QString &kickMessage); //! Connection status changed + //! \sa IContextNetwork::connectedServerChanged void connectionStatusChanged(BlackCore::INetwork::ConnectionStatus from, BlackCore::INetwork::ConnectionStatus to); + //! The connected server has been changed + //! \remark can also be used to determine if the ecosystem has been changed + //! \sa BlackMisc::Network::CServer::getEcosysstem + void connectedServerChanged(const BlackMisc::Network::CServer &server); + //! Text messages received (also private chat messages, radio channel messages) void textMessagesReceived(const BlackMisc::Network::CTextMessageList &textMessages); diff --git a/src/blackcore/context/contextnetworkimpl.cpp b/src/blackcore/context/contextnetworkimpl.cpp index d4e7a043e..283079ac7 100644 --- a/src/blackcore/context/contextnetworkimpl.cpp +++ b/src/blackcore/context/contextnetworkimpl.cpp @@ -66,7 +66,7 @@ namespace BlackCore // 1. Init by "network driver" m_network = new CNetworkVatlib(this->getRuntime()->getCContextOwnAircraft(), this); - connect(m_network, &INetwork::connectionStatusChanged, this, &CContextNetwork::fsdConnectionStatusChanged); + connect(m_network, &INetwork::connectionStatusChanged, this, &CContextNetwork::onFsdConnectionStatusChanged); connect(m_network, &INetwork::kicked, this, &CContextNetwork::kicked); connect(m_network, &INetwork::textMessagesReceived, this, &CContextNetwork::textMessagesReceived); connect(m_network, &INetwork::textMessagesReceived, this, &CContextNetwork::checkForSupervisiorTextMessage); @@ -396,10 +396,10 @@ namespace BlackCore return sApp->getWebDataServices()->getVatsimVoiceServers(); } - void CContextNetwork::fsdConnectionStatusChanged(BlackCore::INetwork::ConnectionStatus from, BlackCore::INetwork::ConnectionStatus to) + void CContextNetwork::onFsdConnectionStatusChanged(BlackCore::INetwork::ConnectionStatus from, BlackCore::INetwork::ConnectionStatus to) { if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << from << to; } - auto fromOld = m_currentStatus; // own status cached + const INetwork::ConnectionStatus fromOld = m_currentStatus; // own status cached m_currentStatus = to; if (fromOld == INetwork::Disconnecting) @@ -420,6 +420,12 @@ namespace BlackCore if (to == INetwork::Connected) { CLogMessage(this).info("Connected, own aircraft %1") << this->ownAircraft().getCallsignAsString(); + + if (m_network) + { + const CServer server = m_network->getPresetServer(); + emit this->connectedServerChanged(server); + } } // send as message diff --git a/src/blackcore/context/contextnetworkimpl.h b/src/blackcore/context/contextnetworkimpl.h index 0b3e3d918..633083689 100644 --- a/src/blackcore/context/contextnetworkimpl.h +++ b/src/blackcore/context/contextnetworkimpl.h @@ -232,7 +232,7 @@ namespace BlackCore void checkForSupervisiorTextMessage(const BlackMisc::Network::CTextMessageList &messages); //! Connection status changed - void fsdConnectionStatusChanged(BlackCore::INetwork::ConnectionStatus from, BlackCore::INetwork::ConnectionStatus to); + void onFsdConnectionStatusChanged(BlackCore::INetwork::ConnectionStatus from, BlackCore::INetwork::ConnectionStatus to); //! Render restrictions have been changed, used with analyzer //! \sa CAirspaceAnalyzer diff --git a/src/blackcore/context/contextnetworkproxy.cpp b/src/blackcore/context/contextnetworkproxy.cpp index 095224fe0..795d80432 100644 --- a/src/blackcore/context/contextnetworkproxy.cpp +++ b/src/blackcore/context/contextnetworkproxy.cpp @@ -93,7 +93,9 @@ namespace BlackCore s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), "removedAircraft", this, SIGNAL(removedAircraft(BlackMisc::Aviation::CCallsign))); Q_ASSERT(s); - + s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), + "connectedServerChanged", this, SIGNAL(connectedServerChanged(BlackMisc::Network::CServer))); + Q_ASSERT(s); Q_UNUSED(s); this->relayBaseClassSignals(serviceName, connection, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName()); } diff --git a/src/blackcore/webdataservices.cpp b/src/blackcore/webdataservices.cpp index d3945841d..496e99657 100644 --- a/src/blackcore/webdataservices.cpp +++ b/src/blackcore/webdataservices.cpp @@ -7,7 +7,7 @@ * contained in the LICENSE file. */ -#include "blackcore/application.h" +#include "blackcore/context/contextnetwork.h" #include "blackcore/data/globalsetup.h" #include "blackcore/db/airportdatareader.h" #include "blackcore/db/infodatareader.h" @@ -15,12 +15,13 @@ #include "blackcore/db/databasewriter.h" #include "blackcore/db/icaodatareader.h" #include "blackcore/db/modeldatareader.h" -#include "blackcore/setupreader.h" #include "blackcore/vatsim/vatsimbookingreader.h" #include "blackcore/vatsim/vatsimdatafilereader.h" #include "blackcore/vatsim/vatsimmetarreader.h" #include "blackcore/vatsim/vatsimstatusfilereader.h" #include "blackcore/webdataservices.h" +#include "blackcore/setupreader.h" +#include "blackcore/application.h" #include "blackmisc/network/networkutils.h" #include "blackmisc/fileutils.h" #include "blackmisc/logcategory.h" @@ -43,6 +44,7 @@ using namespace BlackCore; using namespace BlackCore::Db; using namespace BlackCore::Data; using namespace BlackCore::Vatsim; +using namespace BlackCore::Context; using namespace BlackMisc; using namespace BlackMisc::Db; using namespace BlackMisc::Simulation; @@ -86,6 +88,11 @@ namespace BlackCore this->initWriters(); } + if (sApp) + { + connect(sApp, &CApplication::coreFacadeStarted, this, &CWebDataServices::onCoreFacadeStarted, Qt::QueuedConnection); + } + // make sure this is called in event queue, so pending tasks cam be performed entities &= ~CEntityFlags::DbInfoObjectEntity; // triggered in init readers entities &= ~CEntityFlags::VatsimStatusFile; // triggered in init readers @@ -1225,7 +1232,7 @@ namespace BlackCore const int allUsedEntities = static_cast(this->allDbEntitiesForUsedReaders()); if (((static_cast(m_swiftDbEntitiesRead)) & allUsedEntities) == allUsedEntities) { - emit allSwiftDbDataRead(); + emit this->allSwiftDbDataRead(); } // individual signals @@ -1239,11 +1246,11 @@ namespace BlackCore if (m_swiftDbEntitiesRead.testFlag(CEntityFlags::AllIcaoEntities) && signalEntitiesAlreadyRead(CEntityFlags::AllIcaoEntities)) { - emit swiftDbAllIcaoEntitiesRead(); + emit this->swiftDbAllIcaoEntitiesRead(); } if (m_swiftDbEntitiesRead.testFlag(CEntityFlags::ModelMatchingEntities) && signalEntitiesAlreadyRead(CEntityFlags::ModelMatchingEntities)) { - emit swiftDbModelMatchingEntitiesRead(); + emit this->swiftDbModelMatchingEntitiesRead(); } } } @@ -1355,12 +1362,24 @@ namespace BlackCore else { // wait for 1st reply - // CLogMessage(this).info("Waiting for 1st reply of info objects (%1) for '%2', from '%4'") << info << CEntityFlags::flagToString(entities) << reader->getInfoObjectsUrl().toQString(); this->readDeferredInBackground(entities, waitForInfoObjectsMs); return false; // wait } } + void CWebDataServices::onCoreFacadeStarted() + { + if (sApp && sApp->supportsContexts() && sApp->getIContextNetwork()) + { + connect(sApp->getIContextNetwork(), &IContextNetwork::connectedServerChanged, this, &CWebDataServices::onConnectedNetworkServerChanged, Qt::QueuedConnection); + } + } + + void CWebDataServices::onConnectedNetworkServerChanged(const CServer &server) + { + Q_UNUSED(server); + } + bool CWebDataServices::writeDbDataToDisk(const QString &dir) const { if (dir.isEmpty()) { return false; } diff --git a/src/blackcore/webdataservices.h b/src/blackcore/webdataservices.h index 4b3b5b232..fbc7cd1ef 100644 --- a/src/blackcore/webdataservices.h +++ b/src/blackcore/webdataservices.h @@ -550,6 +550,12 @@ namespace BlackCore //! \return true means info objects available bool waitForInfoObjectsThenRead(BlackMisc::Network::CEntityFlags::Entity entities, const QString &info, BlackCore::Db::CInfoDataReader *infoReader, QDateTime &timeOut); + //! \copydoc BlackCore::CApplication::coreFacadeStarted + void onCoreFacadeStarted(); + + //! \copydoc BlackCore::Context::IContextNetwork::connectedServerChanged + void onConnectedNetworkServerChanged(const BlackMisc::Network::CServer &server); + CWebReaderFlags::WebReader m_readers = CWebReaderFlags::WebReaderFlag::None; //!< which readers are available BlackMisc::Network::CEntityFlags::Entity m_entitiesPeriodicallyRead = BlackMisc::Network::CEntityFlags::NoEntity; //!< entities permanently updated by timers BlackMisc::Network::CEntityFlags::Entity m_swiftDbEntitiesRead = BlackMisc::Network::CEntityFlags::NoEntity; //!< entities read