refs #395, improved synchronization of booked and online stations

* moved sync functionality into CAtcStation
* consolidated function names
This commit is contained in:
Klaus Basan
2015-04-22 23:50:28 +02:00
committed by Mathew Sutcliffe
parent f7158f17f9
commit 79e2a7b805
8 changed files with 161 additions and 142 deletions

View File

@@ -30,7 +30,7 @@ namespace BlackCore
: QObject(parent),
COwnAircraftAwareReadOnly(ownAircraftProvider),
m_network(network), m_vatsimBookingReader(bookings), m_vatsimDataFileReader(dataFile),
m_analyzer(new CAirspaceAnalyzer(network, this))
m_analyzer(new CAirspaceAnalyzer(ownAircraftProvider, this, network, this))
{
this->connect(this->m_network, &INetwork::atcPositionUpdate, this, &CAirspaceMonitor::ps_atcPositionUpdate);
this->connect(this->m_network, &INetwork::atisReplyReceived, this, &CAirspaceMonitor::ps_atisReceived);
@@ -549,15 +549,19 @@ namespace BlackCore
void CAirspaceMonitor::ps_receivedBookings(const CAtcStationList &bookedStations)
{
Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this));
this->m_atcStationsBooked.clear();
foreach(CAtcStation bookedStation, bookedStations)
if (bookedStations.isEmpty())
{
// complete by VATSIM data file data
this->m_vatsimDataFileReader->getAtcStations().updateFromVatsimDataFileStation(bookedStation);
// exchange booking and online data, both sides are updated
this->m_atcStationsOnline.mergeWithBooking(bookedStation);
// into list
this->m_atcStationsBooked.push_back(bookedStation);
this->m_atcStationsBooked.clear();
}
else
{
CAtcStationList newBookedStations(bookedStations); // modifyable copy
for (CAtcStation &bookedStation : newBookedStations)
{
// exchange booking and online data, both sides are updated
this->m_atcStationsOnline.syncronizeWithBookedStation(bookedStation);
}
this->m_atcStationsBooked = newBookedStations;
}
emit this->changedAtcStationsBooked(); // all booked stations reloaded
}
@@ -614,17 +618,26 @@ namespace BlackCore
CAtcStationList stationsWithCallsign = this->m_atcStationsOnline.findByCallsign(callsign);
if (stationsWithCallsign.isEmpty())
{
// new station
CAtcStation station;
// new station, init with data from data file
CAtcStation station(this->m_vatsimDataFileReader->getAtcStationsForCallsign(callsign).frontOrDefault());
station.setCallsign(callsign);
station.setRange(range);
station.setFrequency(frequency);
station.setPosition(position);
station.setOnline(true);
station.calculcateDistanceAndBearingToOwnAircraft(ownAircraft().getPosition());
this->m_vatsimDataFileReader->getAtcStations().updateFromVatsimDataFileStation(station); // prefill
// sync with bookings
if (this->m_atcStationsBooked.containsCallsign(callsign))
{
CAtcStation bookedStation(this->m_atcStationsBooked.findFirstByCallsign(callsign));
station.syncronizeWithBookedStation(bookedStation);
this->m_atcStationsBooked.replaceIf(&CAtcStation::getCallsign, callsign, bookedStation);
}
this->m_atcStationsOnline.push_back(station);
// subsequent queries
if (this->m_network->isConnected())
{
emit this->m_network->sendRealNameQuery(callsign);
@@ -633,7 +646,7 @@ namespace BlackCore
}
emit this->changedAtcStationsOnline();
// Remark: this->changedAtcStationOnlineConnectionStatus(station, true);
// Remark: this->changedAtcStationOnlineConnectionStatus
// will be sent in psFsdAtisVoiceRoomReceived
}
else

View File

@@ -229,14 +229,20 @@ namespace BlackCore
private slots:
//! Create aircraft in range, this is the only place where a new aircraft should be added
void ps_aircraftUpdateReceived(const BlackMisc::Aviation::CAircraftSituation &situation, const BlackMisc::Aviation::CTransponder &transponder);
void ps_aircraftInterimUpdateReceived(const BlackMisc::Aviation::CAircraftSituation &situation);
//! Create ATC station, this is the only place where an online ATC station should be added
void ps_atcPositionUpdate(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::PhysicalQuantities::CFrequency &frequency, const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::PhysicalQuantities::CLength &range);
//! Send the information if aircraft and(!) client are available
//! \note it can take some time to obtain all data for model matching, so function recursively calls itself if something is still missing (trial)
void ps_sendReadyForModelMatching(const BlackMisc::Aviation::CCallsign &callsign, int trial);
void ps_realNameReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &realname);
void ps_capabilitiesReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, quint32 flags);
void ps_customFSinnPacketReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &p1, const QString &aircraftDesignator, const QString &combinedAircraftType, const QString &model);
void ps_serverReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &server);
void ps_metarReceived(const QString &metarMessage);
void ps_flightPlanReceived(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CFlightPlan &flightPlan);
void ps_atcPositionUpdate(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::PhysicalQuantities::CFrequency &frequency, const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::PhysicalQuantities::CLength &range);
void ps_atcControllerDisconnected(const BlackMisc::Aviation::CCallsign &callsign);
void ps_atisReceived(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CInformationMessage &atisMessage);
void ps_atisVoiceRoomReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &url);
@@ -247,10 +253,7 @@ namespace BlackCore
void ps_receivedBookings(const BlackMisc::Aviation::CAtcStationList &bookedStations);
void ps_receivedDataFile();
void ps_aircraftConfigReceived(const BlackMisc::Aviation::CCallsign &callsign, const QJsonObject &jsonObject, bool isFull);
//! Send the information if aircraft and(!) client are vailable
void ps_sendReadyForModelMatching(const BlackMisc::Aviation::CCallsign &callsign, int trial);
void ps_aircraftInterimUpdateReceived(const BlackMisc::Aviation::CAircraftSituation &situation);
void ps_sendInterimPosition();
};

View File

@@ -45,6 +45,17 @@ namespace BlackCore
return this->m_atcStations;
}
CAtcStationList CVatsimDataFileReader::getAtcStationsForCallsign(const CCallsign &callsign) const
{
CCallsignSet cs({callsign});
return this->getAtcStationsForCallsigns(cs);
}
CAtcStationList CVatsimDataFileReader::getAtcStationsForCallsigns(const CCallsignSet &callsigns) const
{
return this->getAtcStations().findByCallsigns(callsigns);
}
CServerList CVatsimDataFileReader::getVoiceServers() const
{
QReadLocker rl(&this->m_lock);
@@ -64,8 +75,7 @@ namespace BlackCore
CUserList CVatsimDataFileReader::getPilotsForCallsign(const CCallsign &callsign)
{
CCallsignSet callsigns;
callsigns.push_back(callsign);
CCallsignSet callsigns({callsign});
return this->getPilotsForCallsigns(callsigns);
}
@@ -95,16 +105,8 @@ namespace BlackCore
CUserList CVatsimDataFileReader::getControllersForCallsign(const CCallsign &callsign)
{
CCallsignSet callsigns;
callsigns.push_back(callsign);
return this->getControllersForCallsigns(callsigns);
}
CUserList CVatsimDataFileReader::getUsersForCallsign(const CCallsign &callsign)
{
CCallsignSet callsigns;
callsigns.push_back(callsign);
return this->getUsersForCallsigns(callsigns);
CCallsignSet cs({callsign});
return this->getControllersForCallsigns(cs);
}
CUserList CVatsimDataFileReader::getControllersForCallsigns(const CCallsignSet &callsigns)
@@ -112,6 +114,12 @@ namespace BlackCore
return this->getAtcStations().findByCallsigns(callsigns).transform(Predicates::MemberTransform(&CAtcStation::getController));
}
CUserList CVatsimDataFileReader::getUsersForCallsign(const CCallsign &callsign)
{
CCallsignSet callsigns({callsign});
return this->getUsersForCallsigns(callsigns);
}
CUserList CVatsimDataFileReader::getUsersForCallsigns(const CCallsignSet &callsigns)
{
CUserList users;

View File

@@ -28,9 +28,7 @@
namespace BlackCore
{
/*!
* Read bookings from VATSIM
*/
//! Read bookings from VATSIM
class BLACKCORE_EXPORT CVatsimDataFileReader : public BlackMisc::CThreadedReader
{
Q_OBJECT
@@ -39,14 +37,22 @@ namespace BlackCore
//! Constructor
explicit CVatsimDataFileReader(QObject *owner, const QStringList &urls);
//! Get aircrafts
//! Get aircraft
//! \threadsafe
BlackMisc::Aviation::CAircraftList getAircraft() const;
//! Get aircrafts
//! Get ATC station
//! \threadsafe
BlackMisc::Aviation::CAtcStationList getAtcStations() const;
//! Get ATC stations for callsign
//! \threadsafe
BlackMisc::Aviation::CAtcStationList getAtcStationsForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const;
//! Get ATC stations for callsigns
//! \threadsafe
BlackMisc::Aviation::CAtcStationList getAtcStationsForCallsigns(const BlackMisc::Aviation::CCallsignSet &callsigns) const;
//! Get all voice servers
//! \threadsafe
BlackMisc::Network::CServerList getVoiceServers() const;
@@ -103,7 +109,7 @@ namespace BlackCore
private:
QNetworkAccessManager *m_networkManager = nullptr;
QStringList m_serviceUrls; /*!< URL of the service */
QStringList m_serviceUrls; //!< URL of the service
int m_currentUrlIndex;
BlackMisc::Network::CServerList m_voiceServers;
BlackMisc::Network::CServerList m_fsdServers;