mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 15:25:35 +08:00
refs #274, pending connection state detection and disallowing further connection states while pending
This commit is contained in:
@@ -33,7 +33,8 @@ namespace BlackCore
|
||||
* Init this context
|
||||
*/
|
||||
CContextNetwork::CContextNetwork(CRuntimeConfig::ContextMode mode, CRuntime *runtime) :
|
||||
IContextNetwork(mode, runtime), m_airspace(nullptr), m_network(nullptr), m_vatsimBookingReader(nullptr), m_vatsimDataFileReader(nullptr), m_dataUpdateTimer(nullptr)
|
||||
IContextNetwork(mode, runtime), m_airspace(nullptr), m_network(nullptr), m_currentStatus(INetwork::Disconnected),
|
||||
m_vatsimBookingReader(nullptr), m_vatsimDataFileReader(nullptr), m_dataUpdateTimer(nullptr)
|
||||
{
|
||||
Q_ASSERT(this->getRuntime());
|
||||
Q_ASSERT(this->getRuntime()->getIContextSettings());
|
||||
@@ -104,16 +105,21 @@ namespace BlackCore
|
||||
{
|
||||
msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityWarning, "Invalid ICAO data for own aircraft"));
|
||||
}
|
||||
else if (this->m_network->isConnected())
|
||||
{
|
||||
msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityWarning, "Already connected"));
|
||||
}
|
||||
else if (!CNetworkUtils::canConnect(currentServer, msg, 2000))
|
||||
{
|
||||
msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityError, msg));
|
||||
}
|
||||
else if (this->m_network->isConnected())
|
||||
{
|
||||
msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityWarning, "Already connected"));
|
||||
}
|
||||
else if (this->isPendingConnection())
|
||||
{
|
||||
msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityWarning, "Pending connection, please wait"));
|
||||
}
|
||||
else
|
||||
{
|
||||
this->m_currentStatus = INetwork::Connecting; // as semaphore we are going to connect
|
||||
INetwork::LoginMode mode = static_cast<INetwork::LoginMode>(loginMode);
|
||||
this->getIContextOwnAircraft()->updatePilot(currentServer.getUser(), this->getPathAndContextId());
|
||||
const CAircraft ownAircraft = this->ownAircraft();
|
||||
@@ -139,10 +145,15 @@ namespace BlackCore
|
||||
CStatusMessageList msgs;
|
||||
if (this->m_network->isConnected())
|
||||
{
|
||||
this->m_currentStatus = INetwork::Disconnecting; // as semaphore we are going to disconnect
|
||||
this->m_network->terminateConnection();
|
||||
this->m_airspace->clear();
|
||||
msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityInfo, "Connection terminating"));
|
||||
}
|
||||
else if (this->isPendingConnection())
|
||||
{
|
||||
msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityWarning, "Pending connection, please wait"));
|
||||
}
|
||||
else
|
||||
{
|
||||
msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityWarning, "Already disconnected"));
|
||||
@@ -159,6 +170,15 @@ namespace BlackCore
|
||||
return this->m_network->isConnected();
|
||||
}
|
||||
|
||||
bool CContextNetwork::isPendingConnection() const
|
||||
{
|
||||
// if underlying class says pending, we believe it. But not all states (e.g. disconnecting) are covered
|
||||
if (this->m_network->isPendingConnection()) return true;
|
||||
|
||||
// now check out own extra states, e.g. disconnecting
|
||||
return INetwork::isPendingStatus(this->m_currentStatus);
|
||||
}
|
||||
|
||||
/*
|
||||
* Send text messages
|
||||
*/
|
||||
@@ -236,6 +256,7 @@ namespace BlackCore
|
||||
void CContextNetwork::psFsdConnectionStatusChanged(INetwork::ConnectionStatus from, INetwork::ConnectionStatus to, const QString &message)
|
||||
{
|
||||
this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, { QString::number(from), QString::number(to) });
|
||||
this->m_currentStatus = to;
|
||||
CStatusMessageList msgs;
|
||||
// send 1st position
|
||||
if (to == INetwork::Connected)
|
||||
@@ -252,6 +273,7 @@ namespace BlackCore
|
||||
msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork,
|
||||
to == INetwork::DisconnectedError ? CStatusMessage::SeverityError : CStatusMessage::SeverityInfo, m));
|
||||
// FIXME (MS) conditional increases the number of scenarios which must be considered and continuously tested
|
||||
// This is more a guard than a real conditional, e.g. when system shuts down
|
||||
if (this->getIContextApplication())
|
||||
{
|
||||
this->getIContextApplication()->sendStatusMessages(msgs);
|
||||
|
||||
@@ -72,6 +72,13 @@ namespace BlackCore
|
||||
//! \copydoc IContextNetwork::isConnected()
|
||||
virtual bool isConnected() const override;
|
||||
|
||||
/*!
|
||||
* In transition state, e.g. connecting, disconnecting.
|
||||
* \details In such a state it is advisable to wait until an end state (connected/disconnected) is reached
|
||||
* \remarks Intentionally only running locally, not in interface
|
||||
*/
|
||||
bool isPendingConnection() const;
|
||||
|
||||
//! \copydoc IContextNetwork::sendTextMessages()
|
||||
virtual void sendTextMessages(const BlackMisc::Network::CTextMessageList &textMessages) override;
|
||||
|
||||
@@ -128,6 +135,7 @@ namespace BlackCore
|
||||
|
||||
CAirspaceMonitor *m_airspace;
|
||||
BlackCore::INetwork *m_network;
|
||||
INetwork::ConnectionStatus m_currentStatus; //!< used to detect pending connections
|
||||
|
||||
// for reading XML and VATSIM data files
|
||||
CVatsimBookingReader *m_vatsimBookingReader;
|
||||
|
||||
@@ -117,11 +117,24 @@ namespace BlackCore
|
||||
return status == DisconnectedError;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns true if the given ConnectionStatus represents a pending state.
|
||||
*/
|
||||
static bool isPendingStatus(ConnectionStatus status)
|
||||
{
|
||||
return status == Disconnecting || status == Connecting;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns true if the current ConnectionStatus is a connected state.
|
||||
*/
|
||||
virtual bool isConnected() const = 0;
|
||||
|
||||
/*!
|
||||
* Returns true if the current ConnectionStatus is in transition, e.g. connecting.
|
||||
*/
|
||||
virtual bool isPendingConnection() const = 0;
|
||||
|
||||
/*!
|
||||
* Returns a list of URLs where network status data can be found.
|
||||
* To obtain the status, one of these URLs should be picked at random.
|
||||
@@ -226,8 +239,8 @@ namespace BlackCore
|
||||
virtual void sendCustomPacket(const BlackMisc::Aviation::CCallsign &callsign, const QString &packetId, const QStringList &data) = 0;
|
||||
|
||||
/*!
|
||||
* Send an FSInn custom packet.
|
||||
* \details FSIPI(R) queries
|
||||
* Send a FSInn custom packet.
|
||||
* \details FSIPI(R) queries, some example data below:
|
||||
* <BLOCKQUOTE>
|
||||
* index 0 .. 0/1 ???
|
||||
* 1 .. MQT, GEC, DLH -> Airline ICAO, most of the time empty
|
||||
@@ -242,9 +255,9 @@ namespace BlackCore
|
||||
*/
|
||||
//! @{
|
||||
virtual void sendFsipiCustomPacket(const BlackMisc::Aviation::CCallsign &callsign, const QString &airlineDesignator,
|
||||
const QString &aircraftDesignator, const QString &combinedType, const QString &modelString) = 0;
|
||||
const QString &aircraftDesignator, const QString &combinedType, const QString &modelString) = 0;
|
||||
virtual void sendFsipirCustomPacket(const BlackMisc::Aviation::CCallsign &callsign, const QString &airlineDesignator,
|
||||
const QString &aircraftDesignator, const QString &combinedType, const QString &modelString) = 0;
|
||||
const QString &aircraftDesignator, const QString &combinedType, const QString &modelString) = 0;
|
||||
//! @}
|
||||
|
||||
//! @}
|
||||
@@ -509,13 +522,13 @@ namespace BlackCore
|
||||
* We received an FSInn custom packet.
|
||||
*/
|
||||
void fsipiCustomPacketReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &airlineDesignator,
|
||||
const QString &aircraftDesignator, const QString &combinedType, const QString &modelString);
|
||||
const QString &aircraftDesignator, const QString &combinedType, const QString &modelString);
|
||||
|
||||
/*!
|
||||
* We received an FSInn custom response packet.
|
||||
*/
|
||||
void fsipirCustomPacketReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &airlineDesignator,
|
||||
const QString &aircraftDesignator, const QString &combinedType, const QString &modelString);
|
||||
const QString &aircraftDesignator, const QString &combinedType, const QString &modelString);
|
||||
|
||||
//! @}
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -34,6 +34,9 @@ namespace BlackCore
|
||||
//! \copydoc INetwork::isConnected()
|
||||
virtual bool isConnected() const override { return m_status == Cvatlib_Network::connStatus_Connected; }
|
||||
|
||||
//! \copydoc INetwork::pendingConnection()
|
||||
virtual bool isPendingConnection() const override { return m_status == Cvatlib_Network::connStatus_Connecting; }
|
||||
|
||||
//! \copydoc INetwork::getStatusUrls()
|
||||
virtual QList<QUrl> getStatusUrls() const override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user