[FSD] Send correct pilot rating, use threadsafe getters in some places

The thread safety is still premature for the FSD client class.
However, most likely no critical as those values have to be preset and never change.
This commit is contained in:
Klaus Basan
2020-04-17 11:52:59 +02:00
committed by Mat Sutcliffe
parent 000d0da92a
commit 388138203e
3 changed files with 38 additions and 22 deletions

View File

@@ -247,8 +247,9 @@ namespace BlackCore
this->updateConnectionStatus(CConnectionStatus::Connecting);
const QString host = m_server.getAddress();
const quint16 port = static_cast<quint16>(m_server.getPort());
const CServer s = this->getServer();
const QString host = s.getAddress();
const quint16 port = static_cast<quint16>(s.getPort());
m_socket.connectToHost(host, port);
this->startPositionTimers();
}
@@ -261,10 +262,11 @@ namespace BlackCore
this->updateConnectionStatus(CConnectionStatus::Disconnecting);
// allow also to close if broken
CLoginMode mode = this->getLoginMode();
if (m_socket.isOpen())
{
if (m_loginMode.isPilot()) { this->sendDeletePilot(); }
else if (m_loginMode.isObserver()) { this->sendDeleteAtc(); }
if (mode.isPilot()) { this->sendDeletePilot(); }
else if (mode.isObserver()) { this->sendDeleteAtc(); }
}
m_socket.close();
@@ -274,18 +276,20 @@ namespace BlackCore
void CFSDClient::sendLogin()
{
const QString cid = m_server.getUser().getId();
const QString password = m_server.getUser().getPassword();
const QString name = m_server.getUser().getRealNameAndHomeBase(); // m_server.getUser().getRealName();
const CServer s = this->getServer();
const QString cid = s.getUser().getId();
const QString password = s.getUser().getPassword();
const QString name = s.getUser().getRealNameAndHomeBase(); // m_server.getUser().getRealName();
const QString callsign = m_ownCallsign.asString();
if (m_loginMode.isPilot())
const CLoginMode m = this->getLoginMode();
if (m.isPilot())
{
const AddPilot pilotLogin(callsign, cid, password, m_pilotRating, m_protocolRevision, m_simType, name);
sendQueudedMessage(pilotLogin);
CStatusMessage(this).info(u"Sending login as '%1' '%2' '%3' '%4' '%5' '%6'") << callsign << cid << toQString(m_pilotRating) << m_protocolRevision << toQString(m_simType) << name;
}
else if (m_loginMode.isObserver())
else if (m.isObserver())
{
const AddAtc addAtc(callsign, name, cid, password, m_atcRating, m_protocolRevision);
sendQueudedMessage(addAtc);
@@ -295,14 +299,14 @@ namespace BlackCore
void CFSDClient::sendDeletePilot()
{
const QString cid = m_server.getUser().getId();
const QString cid = this->getServer().getUser().getId();
const DeletePilot deletePilot(m_ownCallsign.getFsdCallsignString(), cid);
sendQueudedMessage(deletePilot);
}
void CFSDClient::sendDeleteAtc()
{
const QString cid = m_server.getUser().getId();
const QString cid = this->getServer().getUser().getId();
const DeleteAtc deleteAtc(getOwnCallsignAsString(), cid);
sendQueudedMessage(deleteAtc);
}
@@ -317,10 +321,11 @@ namespace BlackCore
}
else
{
PilotRating r = this->getPilotRating();
PilotDataUpdate pilotDataUpdate(myAircraft.getTransponderMode(),
getOwnCallsignAsString(),
static_cast<qint16>(myAircraft.getTransponderCode()),
PilotRating::Unknown,
r,
myAircraft.latitude().value(CAngleUnit::deg()),
myAircraft.longitude().value(CAngleUnit::deg()),
myAircraft.getAltitude().valueInteger(CLengthUnit::ft()),

View File

@@ -113,21 +113,32 @@ namespace BlackCore
void setAtcRating(AtcRating rating) { QWriteLocker l(&m_lockUserClientBuffered); m_atcRating = rating; }
//! @}
// ------ thread safe access to preset values -----
//! Get the server
//! \threadsafe
const BlackMisc::Network::CServer &getServer() const { QReadLocker l(&m_lockUserClientBuffered); return m_server; }
//! List of all preset values
//! \threadsafe
QStringList getPresetValues() const;
//! Callsign if any
//! \threadsafe
BlackMisc::Aviation::CCallsign getPresetCallsign() const { QReadLocker l(&m_lockUserClientBuffered); return m_ownCallsign; }
//! Partner callsign if any
//! \threadsafe
BlackMisc::Aviation::CCallsign getPresetPartnerCallsign() const { QReadLocker l(&m_lockUserClientBuffered); return m_partnerCallsign; }
//! Mode
//! \threadsafe
BlackMisc::Network::CLoginMode getLoginMode() const { QReadLocker l(&m_lockUserClientBuffered); return m_loginMode; }
//! Rating
//! \threadsafe
PilotRating getPilotRating() const { QReadLocker l(&m_lockUserClientBuffered); return m_pilotRating; }
//! Connenct/disconnect @{
void connectToServer();
void disconnectFromServer();

View File

@@ -38,17 +38,17 @@ namespace BlackCore
//! Properties @{
BlackMisc::Aviation::CTransponder::TransponderMode m_transponderMode = BlackMisc::Aviation::CTransponder::StateStandby;
int m_transponderCode = 0;
PilotRating m_rating = PilotRating::Unknown;
double m_latitude = 0.0;
double m_longitude = 0.0;
int m_altitudeTrue = 0.0;
int m_transponderCode = 0;
PilotRating m_rating = PilotRating::Unknown;
double m_latitude = 0.0;
double m_longitude = 0.0;
int m_altitudeTrue = 0.0;
int m_altitudePressure = 0.0;
int m_groundSpeed = 0;
double m_pitch = 0.0;
double m_bank = 0.0;
double m_heading = 0.0;
bool m_onGround = false;
int m_groundSpeed = 0;
double m_pitch = 0.0;
double m_bank = 0.0;
double m_heading = 0.0;
bool m_onGround = false;
//! @}
private: