Skip to content

Commit b3804c7

Browse files
committed
DataManager: amend async Euroscope updates to use Pilot type
1 parent dd3a003 commit b3804c7

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

src/core/DataManager.cpp

+15-19
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,14 @@ void DataManager::setActiveAirports(const std::list<std::string> activeAirports)
347347
}
348348

349349
void DataManager::queueFlightplanUpdate(EuroScopePlugIn::CFlightPlan flightplan) {
350-
if (false == flightplan.IsValid()) return;
350+
if (false == flightplan.IsValid() || nullptr == flightplan.GetFlightPlanData().GetPlanType() ||
351+
nullptr == flightplan.GetFlightPlanData().GetOrigin())
352+
return;
353+
354+
auto pilot = this->CFlightPlanToPilot(flightplan);
355+
351356
std::lock_guard guard(this->m_euroscopeUpdatesLock);
352-
this->m_euroscopeFlightplanUpdates.push_back({std::chrono::utc_clock::now(), flightplan});
357+
this->m_euroscopeFlightplanUpdates.push_back({std::chrono::utc_clock::now(), pilot});
353358
}
354359

355360
void DataManager::consolidateWithBackend(std::map<std::string, std::array<types::Pilot, 3U>>& pilots) {
@@ -436,7 +441,7 @@ void DataManager::processEuroScopeUpdates(std::map<std::string, std::array<types
436441
for (auto& update : flightplanUpdates) {
437442
bool found = false;
438443

439-
auto pilot = DataManager::CFlightPlanToPilot(update.data);
444+
const auto pilot = update.data;
440445

441446
// find pilot in list
442447
for (auto& pair : pilots) {
@@ -461,27 +466,20 @@ void DataManager::consolidateFlightplanUpdates(std::list<EuroscopeFlightplanUpda
461466
std::list<DataManager::EuroscopeFlightplanUpdate> resultList;
462467

463468
for (const auto& currentUpdate : inputList) {
464-
auto& flightplan = currentUpdate.data;
465-
if (false == flightplan.IsValid() || nullptr == flightplan.GetFlightPlanData().GetPlanType()) {
466-
continue;
467-
}
468-
if (nullptr == flightplan.GetFlightPlanData().GetOrigin()) {
469-
continue;
470-
}
469+
auto pilot = currentUpdate.data;
471470

472471
// only handle updates for active airports
473472
{
474473
std::lock_guard guard(this->m_airportLock);
475-
bool flightDepartsFromActiveAirport =
476-
std::find(m_activeAirports.begin(), m_activeAirports.end(),
477-
std::string(flightplan.GetFlightPlanData().GetOrigin())) != m_activeAirports.end();
474+
bool flightDepartsFromActiveAirport = std::find(m_activeAirports.begin(), m_activeAirports.end(),
475+
std::string(pilot.origin)) != m_activeAirports.end();
478476
if (false == flightDepartsFromActiveAirport) continue;
479477
}
480478

481479
// Check if the flight plan already exists in the result list
482480
auto it = std::find_if(resultList.begin(), resultList.end(),
483481
[&currentUpdate](const EuroscopeFlightplanUpdate& existingUpdate) {
484-
return existingUpdate.data.GetCallsign() == currentUpdate.data.GetCallsign();
482+
return existingUpdate.data.callsign == currentUpdate.data.callsign;
485483
});
486484

487485
if (it != resultList.end()) {
@@ -491,20 +489,18 @@ void DataManager::consolidateFlightplanUpdates(std::list<EuroscopeFlightplanUpda
491489
// Update with the newer data
492490
*it = currentUpdate;
493491
Logger::instance().log(Logger::LogSender::DataManager,
494-
"Updated: " + std::string(currentUpdate.data.GetCallsign()),
495-
Logger::LogLevel::Info);
492+
"Updated: " + std::string(currentUpdate.data.callsign), Logger::LogLevel::Info);
496493
} else {
497494
// Existing data is already newer, no update needed
498495
Logger::instance().log(Logger::LogSender::DataManager,
499-
"Skipped old update for: " + std::string(currentUpdate.data.GetCallsign()),
496+
"Skipped old update for: " + std::string(currentUpdate.data.callsign),
500497
Logger::LogLevel::Info);
501498
}
502499
} else {
503500
// Flight plan with the callsign doesn't exist, add it to the result list
504501
resultList.push_back(currentUpdate);
505502
Logger::instance().log(Logger::LogSender::DataManager,
506-
"Update added: " + std::string(currentUpdate.data.GetCallsign()),
507-
Logger::LogLevel::Info);
503+
"Update added: " + std::string(currentUpdate.data.callsign), Logger::LogLevel::Info);
508504
}
509505
}
510506

src/core/DataManager.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class DataManager {
7070

7171
struct EuroscopeFlightplanUpdate {
7272
std::chrono::utc_clock::time_point timeIssued;
73-
EuroScopePlugIn::CFlightPlan data;
73+
types::Pilot data;
7474
};
7575

7676
std::mutex m_euroscopeUpdatesLock;

0 commit comments

Comments
 (0)