Ref T89, signal when server (flight network) connects

* server contains the ecosystem
* connect server signal with web data services (so ecosystem is available)
This commit is contained in:
Klaus Basan
2018-01-26 04:22:56 +01:00
parent 321cb8e563
commit 5829917694
6 changed files with 50 additions and 11 deletions

View File

@@ -147,8 +147,14 @@ namespace BlackCore
void kicked(const QString &kickMessage); void kicked(const QString &kickMessage);
//! Connection status changed //! Connection status changed
//! \sa IContextNetwork::connectedServerChanged
void connectionStatusChanged(BlackCore::INetwork::ConnectionStatus from, BlackCore::INetwork::ConnectionStatus to); 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) //! Text messages received (also private chat messages, radio channel messages)
void textMessagesReceived(const BlackMisc::Network::CTextMessageList &textMessages); void textMessagesReceived(const BlackMisc::Network::CTextMessageList &textMessages);

View File

@@ -66,7 +66,7 @@ namespace BlackCore
// 1. Init by "network driver" // 1. Init by "network driver"
m_network = new CNetworkVatlib(this->getRuntime()->getCContextOwnAircraft(), this); 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::kicked, this, &CContextNetwork::kicked);
connect(m_network, &INetwork::textMessagesReceived, this, &CContextNetwork::textMessagesReceived); connect(m_network, &INetwork::textMessagesReceived, this, &CContextNetwork::textMessagesReceived);
connect(m_network, &INetwork::textMessagesReceived, this, &CContextNetwork::checkForSupervisiorTextMessage); connect(m_network, &INetwork::textMessagesReceived, this, &CContextNetwork::checkForSupervisiorTextMessage);
@@ -396,10 +396,10 @@ namespace BlackCore
return sApp->getWebDataServices()->getVatsimVoiceServers(); 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; } 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; m_currentStatus = to;
if (fromOld == INetwork::Disconnecting) if (fromOld == INetwork::Disconnecting)
@@ -420,6 +420,12 @@ namespace BlackCore
if (to == INetwork::Connected) if (to == INetwork::Connected)
{ {
CLogMessage(this).info("Connected, own aircraft %1") << this->ownAircraft().getCallsignAsString(); 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 // send as message

View File

@@ -232,7 +232,7 @@ namespace BlackCore
void checkForSupervisiorTextMessage(const BlackMisc::Network::CTextMessageList &messages); void checkForSupervisiorTextMessage(const BlackMisc::Network::CTextMessageList &messages);
//! Connection status changed //! 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 //! Render restrictions have been changed, used with analyzer
//! \sa CAirspaceAnalyzer //! \sa CAirspaceAnalyzer

View File

@@ -93,7 +93,9 @@ namespace BlackCore
s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(),
"removedAircraft", this, SIGNAL(removedAircraft(BlackMisc::Aviation::CCallsign))); "removedAircraft", this, SIGNAL(removedAircraft(BlackMisc::Aviation::CCallsign)));
Q_ASSERT(s); Q_ASSERT(s);
s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(),
"connectedServerChanged", this, SIGNAL(connectedServerChanged(BlackMisc::Network::CServer)));
Q_ASSERT(s);
Q_UNUSED(s); Q_UNUSED(s);
this->relayBaseClassSignals(serviceName, connection, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName()); this->relayBaseClassSignals(serviceName, connection, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName());
} }

View File

@@ -7,7 +7,7 @@
* contained in the LICENSE file. * contained in the LICENSE file.
*/ */
#include "blackcore/application.h" #include "blackcore/context/contextnetwork.h"
#include "blackcore/data/globalsetup.h" #include "blackcore/data/globalsetup.h"
#include "blackcore/db/airportdatareader.h" #include "blackcore/db/airportdatareader.h"
#include "blackcore/db/infodatareader.h" #include "blackcore/db/infodatareader.h"
@@ -15,12 +15,13 @@
#include "blackcore/db/databasewriter.h" #include "blackcore/db/databasewriter.h"
#include "blackcore/db/icaodatareader.h" #include "blackcore/db/icaodatareader.h"
#include "blackcore/db/modeldatareader.h" #include "blackcore/db/modeldatareader.h"
#include "blackcore/setupreader.h"
#include "blackcore/vatsim/vatsimbookingreader.h" #include "blackcore/vatsim/vatsimbookingreader.h"
#include "blackcore/vatsim/vatsimdatafilereader.h" #include "blackcore/vatsim/vatsimdatafilereader.h"
#include "blackcore/vatsim/vatsimmetarreader.h" #include "blackcore/vatsim/vatsimmetarreader.h"
#include "blackcore/vatsim/vatsimstatusfilereader.h" #include "blackcore/vatsim/vatsimstatusfilereader.h"
#include "blackcore/webdataservices.h" #include "blackcore/webdataservices.h"
#include "blackcore/setupreader.h"
#include "blackcore/application.h"
#include "blackmisc/network/networkutils.h" #include "blackmisc/network/networkutils.h"
#include "blackmisc/fileutils.h" #include "blackmisc/fileutils.h"
#include "blackmisc/logcategory.h" #include "blackmisc/logcategory.h"
@@ -43,6 +44,7 @@ using namespace BlackCore;
using namespace BlackCore::Db; using namespace BlackCore::Db;
using namespace BlackCore::Data; using namespace BlackCore::Data;
using namespace BlackCore::Vatsim; using namespace BlackCore::Vatsim;
using namespace BlackCore::Context;
using namespace BlackMisc; using namespace BlackMisc;
using namespace BlackMisc::Db; using namespace BlackMisc::Db;
using namespace BlackMisc::Simulation; using namespace BlackMisc::Simulation;
@@ -86,6 +88,11 @@ namespace BlackCore
this->initWriters(); 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 // make sure this is called in event queue, so pending tasks cam be performed
entities &= ~CEntityFlags::DbInfoObjectEntity; // triggered in init readers entities &= ~CEntityFlags::DbInfoObjectEntity; // triggered in init readers
entities &= ~CEntityFlags::VatsimStatusFile; // triggered in init readers entities &= ~CEntityFlags::VatsimStatusFile; // triggered in init readers
@@ -1225,7 +1232,7 @@ namespace BlackCore
const int allUsedEntities = static_cast<int>(this->allDbEntitiesForUsedReaders()); const int allUsedEntities = static_cast<int>(this->allDbEntitiesForUsedReaders());
if (((static_cast<int>(m_swiftDbEntitiesRead)) & allUsedEntities) == allUsedEntities) if (((static_cast<int>(m_swiftDbEntitiesRead)) & allUsedEntities) == allUsedEntities)
{ {
emit allSwiftDbDataRead(); emit this->allSwiftDbDataRead();
} }
// individual signals // individual signals
@@ -1239,11 +1246,11 @@ namespace BlackCore
if (m_swiftDbEntitiesRead.testFlag(CEntityFlags::AllIcaoEntities) && signalEntitiesAlreadyRead(CEntityFlags::AllIcaoEntities)) if (m_swiftDbEntitiesRead.testFlag(CEntityFlags::AllIcaoEntities) && signalEntitiesAlreadyRead(CEntityFlags::AllIcaoEntities))
{ {
emit swiftDbAllIcaoEntitiesRead(); emit this->swiftDbAllIcaoEntitiesRead();
} }
if (m_swiftDbEntitiesRead.testFlag(CEntityFlags::ModelMatchingEntities) && signalEntitiesAlreadyRead(CEntityFlags::ModelMatchingEntities)) if (m_swiftDbEntitiesRead.testFlag(CEntityFlags::ModelMatchingEntities) && signalEntitiesAlreadyRead(CEntityFlags::ModelMatchingEntities))
{ {
emit swiftDbModelMatchingEntitiesRead(); emit this->swiftDbModelMatchingEntitiesRead();
} }
} }
} }
@@ -1355,12 +1362,24 @@ namespace BlackCore
else else
{ {
// wait for 1st reply // 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); this->readDeferredInBackground(entities, waitForInfoObjectsMs);
return false; // wait 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 bool CWebDataServices::writeDbDataToDisk(const QString &dir) const
{ {
if (dir.isEmpty()) { return false; } if (dir.isEmpty()) { return false; }

View File

@@ -550,6 +550,12 @@ namespace BlackCore
//! \return true means info objects available //! \return true means info objects available
bool waitForInfoObjectsThenRead(BlackMisc::Network::CEntityFlags::Entity entities, const QString &info, BlackCore::Db::CInfoDataReader *infoReader, QDateTime &timeOut); 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 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_entitiesPeriodicallyRead = BlackMisc::Network::CEntityFlags::NoEntity; //!< entities permanently updated by timers
BlackMisc::Network::CEntityFlags::Entity m_swiftDbEntitiesRead = BlackMisc::Network::CEntityFlags::NoEntity; //!< entities read BlackMisc::Network::CEntityFlags::Entity m_swiftDbEntitiesRead = BlackMisc::Network::CEntityFlags::NoEntity; //!< entities read