Skip to content

Commit

Permalink
feat: drive intention codes from api data
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyTWF committed Jan 1, 2023
1 parent ff60129 commit 690c37f
Show file tree
Hide file tree
Showing 59 changed files with 619 additions and 95 deletions.
2 changes: 1 addition & 1 deletion src/plugin/CMakeLists.txt
Expand Up @@ -484,7 +484,7 @@ set(src__intention
"intention/SectorExitRepositoryFactory.h"
"intention/ShannonAirfieldGroup.cpp"
"intention/ShannonAirfieldGroup.h"
intention/FirExitPointCollection.cpp intention/FirExitPointCollection.h intention/FirExitPointCollectionFactory.cpp intention/FirExitPointCollectionFactory.h intention/IntentionCodeModuleFactory.cpp intention/IntentionCodeModuleFactory.h intention/IntentionCodeBootstrapProvider.cpp intention/IntentionCodeBootstrapProvider.h intention/Condition.h intention/AllOf.cpp intention/AllOf.h intention/AnyOf.cpp intention/AnyOf.h intention/Not.cpp intention/Not.h intention/ArrivalAirfields.cpp intention/ArrivalAirfields.h intention/ArrivalAirfieldPattern.cpp intention/ArrivalAirfieldPattern.h intention/MaximumCruisingAltitude.cpp intention/MaximumCruisingAltitude.h intention/ControllerPositionStartsWith.cpp intention/ControllerPositionStartsWith.h intention/ExitingFirAtPoint.cpp intention/ExitingFirAtPoint.h intention/RoutingVia.cpp intention/RoutingVia.h intention/CodeGenerator.h intention/SingleCode.cpp intention/SingleCode.h intention/AirfieldIdentifier.cpp intention/AirfieldIdentifier.h intention/FullAirfieldIdentifier.cpp intention/FullAirfieldIdentifier.h intention/IntentionCodeModel.cpp intention/IntentionCodeModel.h intention/IntentionCodeCollection.cpp intention/IntentionCodeCollection.h intention/IntentionCodeCollectionFactory.cpp intention/IntentionCodeCollectionFactory.h intention/AircraftIntentionCodeGenerator.h intention/AircraftIntentionCode.h intention/CachedAircraftIntentionCodeGenerator.cpp intention/CachedAircraftIntentionCodeGenerator.h intention/IntentionCodeEventHandlerInterface.h intention/SendIntentionCodeUpdatedIntegrationMessage.cpp intention/SendIntentionCodeUpdatedIntegrationMessage.h intention/IntentionCodeMetadata.h intention/IntentionCodeEventHandlerCollection.cpp intention/IntentionCodeEventHandlerCollection.h)
intention/FirExitPointCollection.cpp intention/FirExitPointCollection.h intention/FirExitPointCollectionFactory.cpp intention/FirExitPointCollectionFactory.h intention/IntentionCodeModuleFactory.cpp intention/IntentionCodeModuleFactory.h intention/IntentionCodeBootstrapProvider.cpp intention/IntentionCodeBootstrapProvider.h intention/Condition.h intention/AllOf.cpp intention/AllOf.h intention/AnyOf.cpp intention/AnyOf.h intention/Not.cpp intention/Not.h intention/ArrivalAirfields.cpp intention/ArrivalAirfields.h intention/ArrivalAirfieldPattern.cpp intention/ArrivalAirfieldPattern.h intention/MaximumCruisingAltitude.cpp intention/MaximumCruisingAltitude.h intention/ControllerPositionStartsWith.cpp intention/ControllerPositionStartsWith.h intention/ExitingFirAtPoint.cpp intention/ExitingFirAtPoint.h intention/RoutingVia.cpp intention/RoutingVia.h intention/CodeGenerator.h intention/SingleCode.cpp intention/SingleCode.h intention/AirfieldIdentifier.cpp intention/AirfieldIdentifier.h intention/FullAirfieldIdentifier.cpp intention/FullAirfieldIdentifier.h intention/IntentionCodeModel.cpp intention/IntentionCodeModel.h intention/IntentionCodeCollection.cpp intention/IntentionCodeCollection.h intention/IntentionCodeCollectionFactory.cpp intention/IntentionCodeCollectionFactory.h intention/AircraftIntentionCodeGenerator.h intention/AircraftIntentionCode.h intention/CachedAircraftIntentionCodeGenerator.cpp intention/CachedAircraftIntentionCodeGenerator.h intention/IntentionCodeEventHandlerInterface.h intention/SendIntentionCodeUpdatedIntegrationMessage.cpp intention/SendIntentionCodeUpdatedIntegrationMessage.h intention/IntentionCodeMetadata.h intention/IntentionCodeEventHandlerCollection.cpp intention/IntentionCodeEventHandlerCollection.h intention/IntentionCodeTagItem.cpp intention/IntentionCodeTagItem.h)
source_group("src\\intention" FILES ${src__intention})

set(src__list
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/bootstrap/InitialisePlugin.cpp
Expand Up @@ -238,7 +238,7 @@ namespace UKControllerPlugin {
Metar::BootstrapPlugin(*this->container);
InitialAltitudeModule::BootstrapPlugin(*this->container);
InitialHeading::BootstrapPlugin(*this->container);
IntentionCodeModule::BootstrapPlugin(*this->container);
// IntentionCodeModule::BootstrapPlugin(*this->container);
Srd::BootstrapPlugin(*this->container);
HistoryTrailModule::BootstrapPlugin(*this->container);
CountdownModule::BootstrapPlugin(*this->container);
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/intention/AircraftFirExitGenerator.h
Expand Up @@ -17,7 +17,7 @@ namespace UKControllerPlugin::IntentionCode {
/*
Generates the aircrafts FIR exit point data, or nullptr if there are none.
*/
[[nodiscard]] virtual auto Generate(Euroscope::EuroScopeCFlightPlanInterface& flightplan)
[[nodiscard]] virtual auto Generate(const Euroscope::EuroScopeCFlightPlanInterface& flightplan)
-> std::shared_ptr<AircraftFirExit> = 0;
};
} // namespace UKControllerPlugin::IntentionCode
4 changes: 2 additions & 2 deletions src/plugin/intention/AircraftIntentionCodeGenerator.h
Expand Up @@ -19,7 +19,7 @@ namespace UKControllerPlugin::IntentionCode {
Generates the aircrafts FIR exit point data, or nullptr if there are none.
*/
[[nodiscard]] virtual auto Generate(
Euroscope::EuroScopeCFlightPlanInterface& flightplan,
Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> std::shared_ptr<AircraftIntentionCode> = 0;
const Euroscope::EuroScopeCFlightPlanInterface& flightplan,
const Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> std::shared_ptr<AircraftIntentionCode> = 0;
};
} // namespace UKControllerPlugin::IntentionCode
4 changes: 2 additions & 2 deletions src/plugin/intention/AllOf.cpp
Expand Up @@ -7,8 +7,8 @@ namespace UKControllerPlugin::IntentionCode {
}

auto AllOf::Passes(
Euroscope::EuroScopeCFlightPlanInterface& flightplan, Euroscope::EuroScopeCRadarTargetInterface& radarTarget)
-> bool
const Euroscope::EuroScopeCFlightPlanInterface& flightplan,
const Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool
{
for (const auto& condition : conditions) {
if (!condition->Passes(flightplan, radarTarget)) {
Expand Down
4 changes: 2 additions & 2 deletions src/plugin/intention/AllOf.h
Expand Up @@ -12,8 +12,8 @@ namespace UKControllerPlugin::IntentionCode {
AllOf(std::list<std::shared_ptr<Condition>> conditions);
[[nodiscard]] auto Subconditions() const -> const std::list<std::shared_ptr<Condition>>&;
[[nodiscard]] auto Passes(
Euroscope::EuroScopeCFlightPlanInterface& flightplan,
Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool override;
const Euroscope::EuroScopeCFlightPlanInterface& flightplan,
const Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool override;

private:
// The conditions that must be true
Expand Down
4 changes: 2 additions & 2 deletions src/plugin/intention/AnyOf.cpp
Expand Up @@ -7,8 +7,8 @@ namespace UKControllerPlugin::IntentionCode {
}

auto AnyOf::Passes(
Euroscope::EuroScopeCFlightPlanInterface& flightplan, Euroscope::EuroScopeCRadarTargetInterface& radarTarget)
-> bool
const Euroscope::EuroScopeCFlightPlanInterface& flightplan,
const Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool
{
for (const auto& condition : conditions) {
if (condition->Passes(flightplan, radarTarget)) {
Expand Down
4 changes: 2 additions & 2 deletions src/plugin/intention/AnyOf.h
Expand Up @@ -12,8 +12,8 @@ namespace UKControllerPlugin::IntentionCode {
AnyOf(std::list<std::shared_ptr<Condition>> conditions);
[[nodiscard]] auto Subconditions() const -> const std::list<std::shared_ptr<Condition>>&;
[[nodiscard]] auto Passes(
Euroscope::EuroScopeCFlightPlanInterface& flightplan,
Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool override;
const Euroscope::EuroScopeCFlightPlanInterface& flightplan,
const Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool override;

private:
// The conditions that must be true
Expand Down
4 changes: 2 additions & 2 deletions src/plugin/intention/ArrivalAirfieldPattern.cpp
Expand Up @@ -8,8 +8,8 @@ namespace UKControllerPlugin::IntentionCode {
}

auto ArrivalAirfieldPattern::Passes(
Euroscope::EuroScopeCFlightPlanInterface& flightplan, Euroscope::EuroScopeCRadarTargetInterface& radarTarget)
-> bool
const Euroscope::EuroScopeCFlightPlanInterface& flightplan,
const Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool
{
return flightplan.GetDestination().empty() ? false
: flightplan.GetDestination().substr(0, pattern.size()) == pattern;
Expand Down
4 changes: 2 additions & 2 deletions src/plugin/intention/ArrivalAirfieldPattern.h
Expand Up @@ -13,8 +13,8 @@ namespace UKControllerPlugin::IntentionCode {
ArrivalAirfieldPattern(std::string pattern);
[[nodiscard]] auto Pattern() const -> const std::string&;
[[nodiscard]] auto Passes(
Euroscope::EuroScopeCFlightPlanInterface& flightplan,
Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool override;
const Euroscope::EuroScopeCFlightPlanInterface& flightplan,
const Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool override;

private:
// The airfield pattern to match
Expand Down
3 changes: 2 additions & 1 deletion src/plugin/intention/ArrivalAirfields.cpp
Expand Up @@ -8,7 +8,8 @@ namespace UKControllerPlugin::IntentionCode {
}

auto ArrivalAirfields::Passes(
Euroscope::EuroScopeCFlightPlanInterface& flightplan, Euroscope::EuroScopeCRadarTargetInterface& radarTarget)
const Euroscope::EuroScopeCFlightPlanInterface& flightplan, const Euroscope::EuroScopeCRadarTargetInterface&
radarTarget)
-> bool
{
return airfields.contains(flightplan.GetDestination());
Expand Down
4 changes: 2 additions & 2 deletions src/plugin/intention/ArrivalAirfields.h
Expand Up @@ -13,8 +13,8 @@ namespace UKControllerPlugin::IntentionCode {
ArrivalAirfields(std::set<std::string> airfields);
[[nodiscard]] auto Airfields() const -> const std::set<std::string>&;
[[nodiscard]] auto Passes(
Euroscope::EuroScopeCFlightPlanInterface& flightplan,
Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool override;
const Euroscope::EuroScopeCFlightPlanInterface& flightplan,
const Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool override;

private:
std::set<std::string> airfields;
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/intention/CachedAircraftFirExitGenerator.cpp
Expand Up @@ -30,7 +30,7 @@ namespace UKControllerPlugin::IntentionCode {
cache.erase(callsign);
}

auto CachedAircraftFirExitGenerator::Generate(Euroscope::EuroScopeCFlightPlanInterface& flightplan)
auto CachedAircraftFirExitGenerator::Generate(const Euroscope::EuroScopeCFlightPlanInterface& flightplan)
-> std::shared_ptr<AircraftFirExit>
{
auto cachedEntry = GetCacheEntryForCallsign(flightplan.GetCallsign());
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/intention/CachedAircraftFirExitGenerator.h
Expand Up @@ -27,7 +27,7 @@ namespace UKControllerPlugin::IntentionCode {
/*
Generates the aircrafts FIR exit point data, or nullptr if there are none.
*/
[[nodiscard]] auto Generate(Euroscope::EuroScopeCFlightPlanInterface& flightplan)
[[nodiscard]] auto Generate(const Euroscope::EuroScopeCFlightPlanInterface& flightplan)
-> std::shared_ptr<AircraftFirExit> override;

private:
Expand Down
11 changes: 7 additions & 4 deletions src/plugin/intention/CachedAircraftIntentionCodeGenerator.cpp
Expand Up @@ -5,14 +5,15 @@
#include "IntentionCodeCollection.h"
#include "IntentionCodeModel.h"
#include "IntentionCodeUpdatedMessage.h"
#include "IntentionCodeEventHandlerCollection.h"
#include "controller/ActiveCallsign.h"
#include "euroscope/EuroScopeCFlightPlanInterface.h"

namespace UKControllerPlugin::IntentionCode {

CachedAircraftIntentionCodeGenerator::CachedAircraftIntentionCodeGenerator(
const IntentionCodeCollection& intentionCodes)
: intentionCodes(intentionCodes)
const IntentionCodeCollection& intentionCodes, const IntentionCodeEventHandlerCollection& eventHandlers)
: intentionCodes(intentionCodes), eventHandlers(eventHandlers)
{
}

Expand All @@ -33,8 +34,8 @@ namespace UKControllerPlugin::IntentionCode {
}

auto CachedAircraftIntentionCodeGenerator::Generate(
Euroscope::EuroScopeCFlightPlanInterface& flightplan, Euroscope::EuroScopeCRadarTargetInterface& radarTarget)
-> std::shared_ptr<AircraftIntentionCode>
const Euroscope::EuroScopeCFlightPlanInterface& flightplan,
const Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> std::shared_ptr<AircraftIntentionCode>
{
auto cachedEntry = GetCacheEntryForCallsign(flightplan.GetCallsign());
if (cachedEntry) {
Expand All @@ -51,9 +52,11 @@ namespace UKControllerPlugin::IntentionCode {

intentionCode.intentionCode =
matchedIntentionCode ? matchedIntentionCode->Generator().GenerateCode(flightplan) : "--";
intentionCode.matchedIntentionCode = matchedIntentionCode;

auto cacheItem = std::make_shared<AircraftIntentionCode>(intentionCode);
AddCacheEntry(cacheItem);
eventHandlers.IntentionCodeUpdated(*cacheItem);

return cacheItem;
}
Expand Down
14 changes: 10 additions & 4 deletions src/plugin/intention/CachedAircraftIntentionCodeGenerator.h
@@ -1,11 +1,12 @@
#pragma once
#include "AircraftIntentionCodeGenerator.h"
#include "controller/ActiveCallsignEventHandlerInterface.h"
#include "flightplan/FlightplanEventHandlerInterface.h"
#include "flightplan/FlightPlanEventHandlerInterface.h"

namespace UKControllerPlugin::IntentionCode {

class IntentionCodeCollection;
class IntentionCodeEventHandlerCollection;

/**
* Generates intention codes for aircraft, and caches them.
Expand All @@ -15,7 +16,8 @@ namespace UKControllerPlugin::IntentionCode {
public Flightplan::FlightPlanEventHandlerInterface
{
public:
CachedAircraftIntentionCodeGenerator(const IntentionCodeCollection& intentionCodes);
CachedAircraftIntentionCodeGenerator(
const IntentionCodeCollection& intentionCodes, const IntentionCodeEventHandlerCollection& eventHandlers);
void AddCacheEntry(const std::shared_ptr<AircraftIntentionCode>& entry);
void FlightPlanEvent(
Euroscope::EuroScopeCFlightPlanInterface& flightPlan,
Expand All @@ -30,8 +32,9 @@ namespace UKControllerPlugin::IntentionCode {
Generates the aircrafts FIR exit point data, or nullptr if there are none.
*/
[[nodiscard]] auto Generate(
Euroscope::EuroScopeCFlightPlanInterface& flightplan,
Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> std::shared_ptr<AircraftIntentionCode> override;
const Euroscope::EuroScopeCFlightPlanInterface& flightplan,
const Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> std::shared_ptr<AircraftIntentionCode>
override;

void ActiveCallsignAdded(const Controller::ActiveCallsign& callsign) override;
void ActiveCallsignRemoved(const Controller::ActiveCallsign& callsign) override;
Expand All @@ -40,6 +43,9 @@ namespace UKControllerPlugin::IntentionCode {
// The intention codes
const IntentionCodeCollection& intentionCodes;

// Handles intention code events
const IntentionCodeEventHandlerCollection& eventHandlers;

// The cache
std::map<std::string, std::shared_ptr<AircraftIntentionCode>> cache;
};
Expand Down
4 changes: 2 additions & 2 deletions src/plugin/intention/Condition.h
Expand Up @@ -19,7 +19,7 @@ namespace UKControllerPlugin::IntentionCode {
* Should return true if the condition is applicable and hence the intention code should be used.
*/
[[nodiscard]] virtual auto Passes(
Euroscope::EuroScopeCFlightPlanInterface& flightplan,
Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool = 0;
const Euroscope::EuroScopeCFlightPlanInterface& flightplan,
const Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool = 0;
};
} // namespace UKControllerPlugin::IntentionCode
3 changes: 2 additions & 1 deletion src/plugin/intention/ControllerPositionStartsWith.cpp
Expand Up @@ -13,7 +13,8 @@ namespace UKControllerPlugin::IntentionCode {
}

auto ControllerPositionStartsWith::Passes(
Euroscope::EuroScopeCFlightPlanInterface& flightplan, Euroscope::EuroScopeCRadarTargetInterface& radarTarget)
const Euroscope::EuroScopeCFlightPlanInterface& flightplan, const Euroscope::EuroScopeCRadarTargetInterface&
radarTarget)
-> bool
{
return activeControllers.UserHasCallsign() &&
Expand Down
4 changes: 2 additions & 2 deletions src/plugin/intention/ControllerPositionStartsWith.h
Expand Up @@ -17,8 +17,8 @@ namespace UKControllerPlugin::IntentionCode {
const UKControllerPlugin::Controller::ActiveCallsignCollection& activeControllers, std::string pattern);
[[nodiscard]] auto Pattern() const -> const std::string&;
[[nodiscard]] auto Passes(
Euroscope::EuroScopeCFlightPlanInterface& flightplan,
Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool override;
const Euroscope::EuroScopeCFlightPlanInterface& flightplan,
const Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool override;

private:
// Active controllers
Expand Down
3 changes: 2 additions & 1 deletion src/plugin/intention/CruisingLevelAbove.cpp
Expand Up @@ -8,7 +8,8 @@ namespace UKControllerPlugin::IntentionCode {
}

auto CruisingLevelAbove::Passes(
Euroscope::EuroScopeCFlightPlanInterface& flightplan, Euroscope::EuroScopeCRadarTargetInterface& radarTarget)
const Euroscope::EuroScopeCFlightPlanInterface& flightplan, const Euroscope::EuroScopeCRadarTargetInterface&
radarTarget)
-> bool
{
return flightplan.GetCruiseLevel() > altitude;
Expand Down
4 changes: 2 additions & 2 deletions src/plugin/intention/CruisingLevelAbove.h
Expand Up @@ -12,8 +12,8 @@ namespace UKControllerPlugin::IntentionCode {
CruisingLevelAbove(int altitude);
[[nodiscard]] auto Level() const -> int;
[[nodiscard]] auto Passes(
Euroscope::EuroScopeCFlightPlanInterface& flightplan,
Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool override;
const Euroscope::EuroScopeCFlightPlanInterface& flightplan,
const Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool override;

private:
int altitude;
Expand Down
3 changes: 2 additions & 1 deletion src/plugin/intention/ExitCone.cpp
Expand Up @@ -11,7 +11,8 @@ namespace UKControllerPlugin::IntentionCode {
}

auto ExitCone::AircraftIsExiting(
const Flightplan::FlightplanPoint& flightplanPoint, Euroscope::EuroScopeCFlightPlanInterface& flightplan) const
const Flightplan::FlightplanPoint& flightplanPoint, const Euroscope::EuroScopeCFlightPlanInterface& flightplan)
const
-> bool
{
const auto nextPoint = flightplan.GetParsedFlightplan()->PointByIndex(flightplanPoint.Index() + 1);
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/intention/ExitCone.h
Expand Up @@ -8,7 +8,7 @@ namespace UKControllerPlugin::IntentionCode {
ExitCone(int startDirection, int endDirection);
[[nodiscard]] auto AircraftIsExiting(
const Flightplan::FlightplanPoint& flightplanPoint,
Euroscope::EuroScopeCFlightPlanInterface& flightplan) const -> bool override;
const Euroscope::EuroScopeCFlightPlanInterface& flightplan) const -> bool override;
[[nodiscard]] auto StartDirection() const -> int;
[[nodiscard]] auto EndDirection() const -> int;

Expand Down
2 changes: 1 addition & 1 deletion src/plugin/intention/ExitDetermination.h
Expand Up @@ -20,6 +20,6 @@ namespace UKControllerPlugin::IntentionCode {
virtual ~ExitDetermination() = default;
[[nodiscard]] virtual auto AircraftIsExiting(
const Flightplan::FlightplanPoint& flightplanPoint,
Euroscope::EuroScopeCFlightPlanInterface& flightplan) const -> bool = 0;
const Euroscope::EuroScopeCFlightPlanInterface& flightplan) const -> bool = 0;
};
} // namespace UKControllerPlugin::IntentionCode
3 changes: 2 additions & 1 deletion src/plugin/intention/ExitingFirAtPoint.cpp
Expand Up @@ -12,7 +12,8 @@ namespace UKControllerPlugin::IntentionCode {
}

auto ExitingFirAtPoint::Passes(
Euroscope::EuroScopeCFlightPlanInterface& flightplan, Euroscope::EuroScopeCRadarTargetInterface& radarTarget)
const Euroscope::EuroScopeCFlightPlanInterface& flightplan, const Euroscope::EuroScopeCRadarTargetInterface&
radarTarget)
-> bool
{
const auto firExit = firExitGenerator.Generate(flightplan);
Expand Down

0 comments on commit 690c37f

Please sign in to comment.