Ref T259, Ref T243 automatically update client gnd. capability by situation

Rational: If we receive a gnd flag from network, the client does have this capability
This commit is contained in:
Klaus Basan
2018-03-26 02:52:06 +02:00
parent 7ae0649dd6
commit 21644c9f24
3 changed files with 32 additions and 6 deletions

View File

@@ -8,6 +8,7 @@
*/
#include "clientprovider.h"
#include "blackmisc/aviation/aircraftsituation.h"
using namespace BlackMisc::Aviation;
@@ -83,6 +84,24 @@ namespace BlackMisc
return m_clients.removeByCallsign(callsign);
}
bool IClientProvider::autoAdjustCientGndCapability(const CAircraftSituation &situation)
{
if (situation.getCallsign().isEmpty()) { return false; } // no callsign
if (!situation.isOnGround()) { return false; } // nothing to adjust
if (situation.getOnGroundDetails() != CAircraftSituation::InFromNetwork) { return false; } // not from network
CClient client = this->getClientOrDefaultForCallsign(situation.getCallsign());
// need to change?
if (!client.isValid()) { return false; } // no client
if (client.hasGndFlagCapability()) { return false; } // already set
client.addCapability(CClient::FsdWithGroundFlag);
QWriteLocker l(&m_lockClient);
m_clients.replaceOrAddObjectByCallsign(client);
return true;
}
CClientList CClientAware::getClients() const
{
if (this->provider()) { return this->provider()->getClients(); }

View File

@@ -19,6 +19,7 @@
namespace BlackMisc
{
namespace Aviation { class CAircraftSituation; }
namespace Network
{
//! Direct in memory access to client (network client) data
@@ -61,6 +62,10 @@ namespace BlackMisc
//! \threadsafe
int removeClient(const Aviation::CCallsign &callsign);
//! Adjust gnd.flag capability from situation
//! \threadsafe
bool autoAdjustCientGndCapability(const Aviation::CAircraftSituation &situation);
private:
CClientList m_clients;
mutable QReadWriteLock m_lockClient; //!< lock clients: m_clients