mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-13 15:45:42 +08:00
Removed Connection state from the class,
as we have it now in INetwork. The connection state from the shimblib should not be used in the client code (abstraction from "drivers"), and in the past the corresponding client state was declared here, but is now one level deeper in INetwork. A second change applied here is to use the signature connectionStatusChanged(from, to), which allows the GUI to better detect whether we login or logout without keeping its own state.
This commit is contained in:
@@ -6,9 +6,8 @@
|
|||||||
#include "context_network.h"
|
#include "context_network.h"
|
||||||
#include "coreruntime.h"
|
#include "coreruntime.h"
|
||||||
#include "blackmisc/avatcstationlist.h"
|
#include "blackmisc/avatcstationlist.h"
|
||||||
#include "context_settings.h"
|
#include "blackcore/context_settings_interface.h"
|
||||||
#include <QtXml/QDomElement>
|
#include <QtXml/QDomElement>
|
||||||
#include <QNetworkAccessManager>
|
|
||||||
|
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
using namespace BlackMisc::PhysicalQuantities;
|
using namespace BlackMisc::PhysicalQuantities;
|
||||||
@@ -22,12 +21,12 @@ namespace BlackCore
|
|||||||
/*
|
/*
|
||||||
* Init this context
|
* Init this context
|
||||||
*/
|
*/
|
||||||
CContextNetwork::CContextNetwork(CCoreRuntime *parent) :
|
CContextNetwork::CContextNetwork(CCoreRuntime *runtime) :
|
||||||
IContextNetwork(parent), m_network(nullptr)
|
IContextNetwork(runtime), m_network(nullptr)
|
||||||
{
|
{
|
||||||
|
|
||||||
// 1. Init by "network driver"
|
// 1. Init by "network driver"
|
||||||
this->m_network = new CNetworkVatlib(this);
|
this->m_network = new CNetworkVatlib(CNetworkVatlib::LoginNormal, this);
|
||||||
|
|
||||||
// 2. Init own aircraft
|
// 2. Init own aircraft
|
||||||
this->initOwnAircraft();
|
this->initOwnAircraft();
|
||||||
@@ -41,8 +40,8 @@ namespace BlackCore
|
|||||||
|
|
||||||
// 4. connect signals and slots
|
// 4. connect signals and slots
|
||||||
bool connect;
|
bool connect;
|
||||||
connect = this->connect(this->m_network, SIGNAL(connectionStatusChanged(Cvatlib_Network::connStatus, Cvatlib_Network::connStatus)),
|
connect = this->connect(this->m_network, SIGNAL(connectionStatusChanged(INetwork::ConnectionStatus, INetwork::ConnectionStatus)),
|
||||||
this, SLOT(psFsdConnectionStatusChanged(Cvatlib_Network::connStatus, Cvatlib_Network::connStatus)));
|
this, SLOT(psFsdConnectionStatusChanged(INetwork::ConnectionStatus, INetwork::ConnectionStatus)));
|
||||||
Q_ASSERT_X(connect, "CContextNetwork", "Cannot connect connectionStatusChanged");
|
Q_ASSERT_X(connect, "CContextNetwork", "Cannot connect connectionStatusChanged");
|
||||||
|
|
||||||
connect = this->connect(this->m_network, SIGNAL(terminate()),
|
connect = this->connect(this->m_network, SIGNAL(terminate()),
|
||||||
@@ -144,15 +143,15 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityWarning, "Invalid user credentials"));
|
msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityWarning, "Invalid user credentials"));
|
||||||
}
|
}
|
||||||
//else if (!this->m_network->isDisconnected())
|
else if (!this->m_network->isDisconnected())
|
||||||
//{
|
{
|
||||||
// msgs.append(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityWarning, "Already connected"));
|
msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityWarning, "Already connected"));
|
||||||
//}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->m_ownAircraft.setPilot(currentServer.getUser());
|
this->m_ownAircraft.setPilot(currentServer.getUser());
|
||||||
this->m_network->setServer(currentServer);
|
this->m_network->setServer(currentServer);
|
||||||
//this->m_network->setOwnAircraft(this->m_ownAircraft);
|
this->m_network->setOwnAircraft(this->m_ownAircraft);
|
||||||
this->m_network->initiateConnection();
|
this->m_network->initiateConnection();
|
||||||
QString msg = "Connection pending ";
|
QString msg = "Connection pending ";
|
||||||
msg.append(" ").append(currentServer.getAddress()).append(" ").append(QString::number(currentServer.getPort()));
|
msg.append(" ").append(currentServer.getAddress()).append(" ").append(QString::number(currentServer.getPort()));
|
||||||
@@ -168,11 +167,11 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
// this->log(Q_FUNC_INFO);
|
// this->log(Q_FUNC_INFO);
|
||||||
CStatusMessageList msgs;
|
CStatusMessageList msgs;
|
||||||
//if (this->m_network->isDisconnected())
|
if (this->m_network->isDisconnected())
|
||||||
//{
|
{
|
||||||
// msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityWarning, "Already disconnected"));
|
msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityWarning, "Already disconnected"));
|
||||||
//}
|
}
|
||||||
//else
|
else
|
||||||
{
|
{
|
||||||
this->m_network->terminateConnection();
|
this->m_network->terminateConnection();
|
||||||
this->m_aircraftsInRange.clear();
|
this->m_aircraftsInRange.clear();
|
||||||
@@ -189,7 +188,7 @@ namespace BlackCore
|
|||||||
*/
|
*/
|
||||||
bool CContextNetwork::isConnected() const
|
bool CContextNetwork::isConnected() const
|
||||||
{
|
{
|
||||||
return false;
|
return !this->m_network->isDisconnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -199,14 +198,14 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
// this->log(Q_FUNC_INFO, aircraft.toQString());
|
// this->log(Q_FUNC_INFO, aircraft.toQString());
|
||||||
CStatusMessageList msgs;
|
CStatusMessageList msgs;
|
||||||
//if (this->m_network->isDisconnected())
|
if (this->m_network->isDisconnected())
|
||||||
{
|
{
|
||||||
this->m_ownAircraft = aircraft;
|
this->m_ownAircraft = aircraft;
|
||||||
}
|
}
|
||||||
//else
|
else
|
||||||
//{
|
{
|
||||||
// msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityError, "Cannot set plane info, network already connected"));
|
msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityError, "Cannot set plane info, network already connected"));
|
||||||
//}
|
}
|
||||||
return msgs;
|
return msgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,10 +214,9 @@ namespace BlackCore
|
|||||||
*/
|
*/
|
||||||
void CContextNetwork::updateOwnPosition(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::Aviation::CAltitude &altitude)
|
void CContextNetwork::updateOwnPosition(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::Aviation::CAltitude &altitude)
|
||||||
{
|
{
|
||||||
// TODO: Do I really need own member?
|
|
||||||
this->m_ownAircraft.setPosition(position);
|
this->m_ownAircraft.setPosition(position);
|
||||||
this->m_ownAircraft.setAltitude(altitude);
|
this->m_ownAircraft.setAltitude(altitude);
|
||||||
this->m_network->setOwnAircraftPosition(this->m_ownAircraft.getSituation());
|
this->m_network->updateOwnPosition(position, altitude);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -228,7 +226,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
// TODO: Do I really need own member?
|
// TODO: Do I really need own member?
|
||||||
this->m_ownAircraft.setSituation(situation);
|
this->m_ownAircraft.setSituation(situation);
|
||||||
this->m_network->setOwnAircraftPosition(situation);
|
this->m_network->updateOwnSituation(situation);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -254,7 +252,7 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!changed) return;
|
if (!changed) return;
|
||||||
//this->m_network->updateOwnCockpit(com1, com2, transponder);
|
this->m_network->updateOwnCockpit(com1, com2, transponder);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -287,15 +285,11 @@ namespace BlackCore
|
|||||||
/*
|
/*
|
||||||
* Connection status changed
|
* Connection status changed
|
||||||
*/
|
*/
|
||||||
void CContextNetwork::psFsdConnectionStatusChanged(Cvatlib_Network::connStatus from, Cvatlib_Network::connStatus to)
|
void CContextNetwork::psFsdConnectionStatusChanged(INetwork::ConnectionStatus from, INetwork::ConnectionStatus to)
|
||||||
{
|
{
|
||||||
ConnectionStatus fromCs = static_cast<ConnectionStatus>(from);
|
|
||||||
ConnectionStatus toCs = static_cast<ConnectionStatus>(to);
|
|
||||||
CStatusMessageList msgs;
|
CStatusMessageList msgs;
|
||||||
|
|
||||||
|
|
||||||
// send 1st position
|
// send 1st position
|
||||||
if (toCs == CContextNetwork::ConnectionStatusConnected)
|
if (to == INetwork::Connected)
|
||||||
{
|
{
|
||||||
QString m("Connected, own aircraft ");
|
QString m("Connected, own aircraft ");
|
||||||
m.append(this->m_ownAircraft.toQString(true));
|
m.append(this->m_ownAircraft.toQString(true));
|
||||||
@@ -304,15 +298,12 @@ namespace BlackCore
|
|||||||
|
|
||||||
// send as message
|
// send as message
|
||||||
QString m("connection status changed ");
|
QString m("connection status changed ");
|
||||||
m.append(this->connectionStatusToString(fromCs)).
|
m.append(this->m_network->connectionStatusToString(from)).append(" ").append(this->m_network->connectionStatusToString(to));
|
||||||
append(" ").
|
msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityInfo, m));
|
||||||
append(this->connectionStatusToString(toCs));
|
|
||||||
msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork,
|
|
||||||
toCs == ConnectionStatusError ? CStatusMessage::SeverityError : CStatusMessage::SeverityInfo, m));
|
|
||||||
emit this->statusMessage(msgs[0]);
|
emit this->statusMessage(msgs[0]);
|
||||||
|
|
||||||
// send as own signal
|
// send as own signal
|
||||||
emit this->connectionStatusChanged(fromCs, toCs);
|
emit this->connectionStatusChanged(from, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -8,14 +8,13 @@
|
|||||||
|
|
||||||
#include "blackcore/dbus_server.h"
|
#include "blackcore/dbus_server.h"
|
||||||
#include "blackcore/network_vatlib.h"
|
#include "blackcore/network_vatlib.h"
|
||||||
|
#include "blackcore/coreruntime.h"
|
||||||
#include "blackcore/context_network_interface.h"
|
#include "blackcore/context_network_interface.h"
|
||||||
#include "blackmisc/avallclasses.h"
|
#include "blackmisc/avallclasses.h"
|
||||||
#include "blackmisc/statusmessage.h"
|
#include "blackmisc/statusmessage.h"
|
||||||
#include "blackmisc/statusmessagelist.h"
|
#include "blackmisc/statusmessagelist.h"
|
||||||
#include "blackcore/coreruntime.h"
|
#include <QTimer>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
class QNetworkAccessManager;
|
|
||||||
class QNetworkReply;
|
|
||||||
|
|
||||||
#define BLACKCORE_CONTEXTNETWORK_INTERFACENAME "blackcore.contextnetwork"
|
#define BLACKCORE_CONTEXTNETWORK_INTERFACENAME "blackcore.contextnetwork"
|
||||||
|
|
||||||
@@ -32,12 +31,11 @@ namespace BlackCore
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief With link to server
|
* \brief With link to server
|
||||||
* \param server
|
* \param server
|
||||||
*/
|
*/
|
||||||
CContextNetwork(CCoreRuntime *parent);
|
CContextNetwork(CCoreRuntime *runtime);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Destructor
|
* \brief Destructor
|
||||||
@@ -240,7 +238,7 @@ namespace BlackCore
|
|||||||
* \param from
|
* \param from
|
||||||
* \param to
|
* \param to
|
||||||
*/
|
*/
|
||||||
void psFsdConnectionStatusChanged(Cvatlib_Network::connStatus from, Cvatlib_Network::connStatus to);
|
void psFsdConnectionStatusChanged(INetwork::ConnectionStatus from, INetwork::ConnectionStatus to);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief ATC position update
|
* \brief ATC position update
|
||||||
@@ -331,7 +329,4 @@ namespace BlackCore
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Declaring BlackCore::CContextNetwork * crashed when reading data
|
|
||||||
Q_DECLARE_METATYPE(BlackCore::CContextNetwork::ConnectionStatus)
|
|
||||||
|
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
@@ -42,16 +42,6 @@ namespace BlackCore
|
|||||||
"textMessagesReceived", this, SIGNAL(textMessagesReceived(BlackMisc::Network::CTextMessageList)));
|
"textMessagesReceived", this, SIGNAL(textMessagesReceived(BlackMisc::Network::CTextMessageList)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Clear text of status
|
|
||||||
*/
|
|
||||||
QString IContextNetwork::connectionStatusToString(ConnectionStatus status) const
|
|
||||||
{
|
|
||||||
int index = metaObject()->indexOfEnumerator("ConnectionStatus");
|
|
||||||
QMetaEnum metaEnum = metaObject()->enumerator(index);
|
|
||||||
return metaEnum.valueToKey(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Relay to DBus
|
* Relay to DBus
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -56,18 +56,6 @@ namespace BlackCore
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Qt compliant status
|
|
||||||
*/
|
|
||||||
enum ConnectionStatus
|
|
||||||
{
|
|
||||||
ConnectionStatusIdle = static_cast<uint>(Cvatlib_Network::connStatus_Idle),
|
|
||||||
ConnectionStatusConnected = static_cast<uint>(Cvatlib_Network::connStatus_Connected),
|
|
||||||
ConnectionStatusConnecting = static_cast<uint>(Cvatlib_Network::connStatus_Connecting),
|
|
||||||
ConnectionStatusDisconnected = static_cast<uint>(Cvatlib_Network::connStatus_Disconnected),
|
|
||||||
ConnectionStatusError = static_cast<uint>(Cvatlib_Network::connStatus_Error)
|
|
||||||
};
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief DBus version constructor
|
* \brief DBus version constructor
|
||||||
* \param serviceName
|
* \param serviceName
|
||||||
@@ -103,12 +91,7 @@ namespace BlackCore
|
|||||||
* \brief IContextNetwork
|
* \brief IContextNetwork
|
||||||
* \param parent
|
* \param parent
|
||||||
*/
|
*/
|
||||||
IContextNetwork(QObject *parent = 0) : QObject(parent), m_dBusInterface(0) {}
|
IContextNetwork(QObject *parent = nullptr) : QObject(parent), m_dBusInterface(0) {}
|
||||||
|
|
||||||
/*!
|
|
||||||
* Connection status as cleartext
|
|
||||||
*/
|
|
||||||
QString connectionStatusToString(ConnectionStatus status) const;
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Helper for logging, likely to be removed / changed
|
* \brief Helper for logging, likely to be removed / changed
|
||||||
@@ -154,6 +137,8 @@ namespace BlackCore
|
|||||||
* \param to
|
* \param to
|
||||||
*/
|
*/
|
||||||
// If I use the enum, adaptor / interface are not created correctly
|
// If I use the enum, adaptor / interface are not created correctly
|
||||||
|
|
||||||
|
|
||||||
void connectionStatusChanged(uint from, uint to);
|
void connectionStatusChanged(uint from, uint to);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
Reference in New Issue
Block a user