refs #369, changed from CAircraftList to CSimulatedAircraft list

In the same step fixed / revised issues:
* make sure ATCT stations are removed from client list when disconnected
* use removeByCallsign functions
This commit is contained in:
Klaus Basan
2015-02-02 17:49:20 +01:00
parent adeac119d0
commit de23d1f5bc
2 changed files with 42 additions and 33 deletions

View File

@@ -162,13 +162,18 @@ namespace BlackCore
{
CClientList clients;
if (callsigns.isEmpty()) return clients;
foreach(CCallsign callsign, callsigns)
for (const CCallsign &callsign : callsigns)
{
clients.push_back(this->m_otherClients.findBy(&CClient::getCallsign, callsign));
}
return clients;
}
CClientList CAirspaceMonitor::getOtherClients() const
{
return m_otherClients;
}
BlackMisc::Aviation::CInformationMessage CAirspaceMonitor::getMetar(const BlackMisc::Aviation::CAirportIcao &airportIcaoCode)
{
CInformationMessage metar;
@@ -264,17 +269,22 @@ namespace BlackCore
void CAirspaceMonitor::ps_realNameReplyReceived(const CCallsign &callsign, const QString &realname)
{
Q_ASSERT(this->m_vatsimDataFileReader);
if (realname.isEmpty()) return;
CPropertyIndexVariantMap vm({CAtcStation::IndexController, CUser::IndexRealName}, realname);
this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm);
this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, vm);
CVoiceCapabilities caps = this->m_vatsimDataFileReader->getVoiceCapabilityForCallsign(callsign);
vm = CPropertyIndexVariantMap({CAircraft::IndexPilot, CUser::IndexRealName}, realname);
vm.addValue({ CSimulatedAircraft::IndexClient, CClient::IndexUser, CUser::IndexRealName }, realname);
vm.addValue({ CSimulatedAircraft::IndexClient, CClient::IndexVoiceCapabilities }, caps);
this->m_aircraftInRange.applyIf(&CAircraft::getCallsign, callsign, vm);
// Client
vm = CPropertyIndexVariantMap({CClient::IndexUser, CUser::IndexRealName}, realname);
this->addVoiceCapabilitiesFromDataFile(vm, callsign);
vm.addValue({ CClient::IndexVoiceCapabilities }, caps);
if (!this->m_otherClients.contains(&CClient::getCallsign, callsign)) { this->m_otherClients.push_back(CClient(callsign)); }
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm);
}
@@ -286,10 +296,17 @@ namespace BlackCore
capabilities.addValue(CClient::FsdAtisCanBeReceived, (flags & INetwork::AcceptsAtisResponses));
capabilities.addValue(CClient::FsdWithInterimPositions, (flags & INetwork::SupportsInterimPosUpdates));
capabilities.addValue(CClient::FsdWithModelDescription, (flags & INetwork::SupportsModelDescriptions));
//! \todo add aircraft config cap.
CPropertyIndexVariantMap vm(CClient::IndexCapabilities, capabilities.toCVariant());
this->addVoiceCapabilitiesFromDataFile(vm, callsign);
CVoiceCapabilities caps = m_vatsimDataFileReader->getVoiceCapabilityForCallsign(callsign);
vm.addValue({CClient::IndexVoiceCapabilities}, caps);
if (!this->m_otherClients.contains(&CClient::getCallsign, callsign)) { this->m_otherClients.push_back(CClient(callsign)); }
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm);
// apply same to client in aircraft
vm.prependIndex(static_cast<int>(CSimulatedAircraft::IndexClient));
this->m_aircraftInRange.applyIf(&CSimulatedAircraft::getCallsign, callsign, vm);
}
void CAirspaceMonitor::ps_fsipirCustomPacketReceived(const CCallsign &callsign, const QString &airlineIcao, const QString &aircraftDesignator, const QString &combinedAircraftType, const QString &model)
@@ -306,6 +323,8 @@ namespace BlackCore
this->m_otherClients.push_back(CClient(callsign));
}
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm);
vm.prependIndex(static_cast<int>(CSimulatedAircraft::IndexClient));
this->m_aircraftInRange.applyIf(&CSimulatedAircraft::getCallsign, callsign, vm);
this->sendFsipiCustomPacket(callsign); // response
// ICAO response from custom data
@@ -373,17 +392,6 @@ namespace BlackCore
this->m_network->sendFsipirCustomPacket(recipientCallsign, icao.getAirlineDesignator(), icao.getAircraftDesignator(), icao.getAircraftCombinedType(), modelString);
}
void CAirspaceMonitor::addVoiceCapabilitiesFromDataFile(CPropertyIndexVariantMap &vm, const CCallsign &callsign)
{
Q_ASSERT(this->m_vatsimDataFileReader);
if (callsign.isEmpty()) return;
CVoiceCapabilities vc = this->m_vatsimDataFileReader->getVoiceCapabilityForCallsign(callsign);
if (!vc.isUnknown())
{
vm.addValue(CClient::IndexVoiceCapabilities, vc);
}
}
void CAirspaceMonitor::removeAllOnlineAtcStations()
{
m_atcWatchdog.removeAll();
@@ -524,13 +532,16 @@ namespace BlackCore
void CAirspaceMonitor::ps_atcControllerDisconnected(const CCallsign &callsign)
{
Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this));
this->m_atcWatchdog.removeCallsign(callsign);
this->m_otherClients.removeByCallsign(callsign);
if (this->m_atcStationsOnline.contains(&CAtcStation::getCallsign, callsign))
{
CAtcStation removeStation = this->m_atcStationsOnline.findByCallsign(callsign).front();
this->m_atcStationsOnline.removeIf(&CAtcStation::getCallsign, callsign);
this->m_atcWatchdog.removeCallsign(callsign);
CAtcStation removedStation = this->m_atcStationsOnline.findFirstByCallsign(callsign);
this->m_atcStationsOnline.removeByCallsign(callsign);
emit this->changedAtcStationsOnline();
emit this->changedAtcStationOnlineConnectionStatus(removeStation, false);
emit this->changedAtcStationOnlineConnectionStatus(removedStation, false);
}
// booked
@@ -562,7 +573,7 @@ namespace BlackCore
Q_ASSERT(changedOnline == 1);
CAtcStation station = this->m_atcStationsOnline.findFirstByCallsign(callsign);
emit this->changedAtcStationsOnline();
emit this->changedAtcStationOnlineConnectionStatus(station, true);
emit this->changedAtcStationOnlineConnectionStatus(station, true); // send when voice room url is available
vm.addValue(CAtcStation::IndexIsOnline, true); // with voice room ATC is online
int changedBooked = this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, vm, true);
@@ -716,12 +727,12 @@ namespace BlackCore
void CAirspaceMonitor::ps_pilotDisconnected(const CCallsign &callsign)
{
Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this));
bool contains = this->m_aircraftInRange.contains(&CAircraft::getCallsign, callsign);
bool contains = this->m_aircraftInRange.containsCallsign(callsign);
this->m_aircraftWatchdog.removeCallsign(callsign);
this->m_otherClients.removeByCallsign(callsign);
if (contains)
{
this->m_aircraftInRange.removeIf(&CAircraft::getCallsign, callsign);
this->m_otherClients.removeIf(&CClient::getCallsign, callsign);
this->m_aircraftInRange.removeByCallsign(callsign);
this->removeFromAircraftCaches(callsign);
emit this->removedAircraft(callsign);
}

View File

@@ -14,7 +14,7 @@
#include "blackmisc/simulation/simulatedaircraft.h"
#include "blackmisc/avatcstationlist.h"
#include "blackmisc/avaircraftlist.h"
#include "blackmisc/simulation/simulatedaircraftlist.h"
#include "blackmisc/avaircraftsituationlist.h"
#include "blackmisc/nwclientlist.h"
#include "blackmisc/avflightplan.h"
@@ -32,7 +32,9 @@ namespace BlackCore
/*!
* Keeps track of other entities in the airspace: aircraft, ATC stations, etc.
*/
class CAirspaceMonitor : public QObject, BlackMisc::Simulation::COwnAircraftProviderSupportReadOnly
class CAirspaceMonitor :
public QObject,
public BlackMisc::Simulation::COwnAircraftProviderSupportReadOnly
{
Q_OBJECT
@@ -51,7 +53,7 @@ namespace BlackCore
BlackMisc::Aviation::CFlightPlan loadFlightPlanFromNetwork(const BlackMisc::Aviation::CCallsign &callsign);
//! Returns this list of other clients we know about
BlackMisc::Network::CClientList getOtherClients() const { return m_otherClients; }
BlackMisc::Network::CClientList getOtherClients() const;
//! Returns a list of other clients corresponding to the given callsigns
BlackMisc::Network::CClientList getOtherClientsForCallsigns(const BlackMisc::Aviation::CCallsignList &callsigns) const;
@@ -66,7 +68,7 @@ namespace BlackCore
BlackMisc::Aviation::CAtcStationList getAtcStationsBooked() const { return m_atcStationsBooked; }
//! Returns the current aircraft in range
BlackMisc::Aviation::CAircraftList getAircraftInRange() const { return m_aircraftInRange; }
BlackMisc::Simulation::CSimulatedAircraftList getAircraftInRange() const { return m_aircraftInRange; }
//! Returns the closest ATC station operating on the given frequency, if any
BlackMisc::Aviation::CAtcStation getAtcStationForComUnit(const BlackMisc::Aviation::CComSystem &comSystem);
@@ -115,10 +117,9 @@ namespace BlackCore
private:
BlackMisc::Aviation::CAtcStationList m_atcStationsOnline;
BlackMisc::Aviation::CAtcStationList m_atcStationsBooked;
BlackMisc::Aviation::CAircraftList m_aircraftInRange;
BlackMisc::Aviation::CAircraftSituationList m_aircraftSituations;
BlackMisc::Network::CClientList m_otherClients;
BlackMisc::Simulation::CSimulatedAircraftList m_aircraftInRange;
BlackMisc::Aviation::CAircraftSituationList m_aircraftSituations;
QMap<BlackMisc::Aviation::CAirportIcao, BlackMisc::Aviation::CInformationMessage> m_metarCache;
QMap<BlackMisc::Aviation::CCallsign, BlackMisc::Aviation::CFlightPlan> m_flightPlanCache;
@@ -135,16 +136,13 @@ namespace BlackCore
void sendFsipirCustomPacket(const BlackMisc::Aviation::CCallsign &recipientCallsign) const;
QStringList createFsipiCustomPacketData() const;
//! Helper method, add voice capabilites if available
void addVoiceCapabilitiesFromDataFile(BlackMisc::CPropertyIndexVariantMap &vm, const BlackMisc::Aviation::CCallsign &callsign);
//! Remove ATC online stations
void removeAllOnlineAtcStations();
//! Remove all aircraft in range
void removeAllAircraft();
//! Remove all clients
//! Remove all other clients
void removeAllOtherClients();
//! Remove data from caches