Skip to content

Commit

Permalink
fix: invalidate intention code caches on controller and fp events
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyTWF committed Jan 4, 2023
1 parent d1afc48 commit 4174460
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/plugin/intention/IntentionCodeBootstrapProvider.cpp
@@ -1,11 +1,13 @@
#include "CachedAircraftFirExitGenerator.h"
#include "CachedAircraftIntentionCodeGenerator.h"
#include "IntentionCodeBootstrapProvider.h"
#include "IntentionCodeEventHandlerCollection.h"
#include "IntentionCodeModuleFactory.h"
#include "IntentionCodeTagItem.h"
#include "SendIntentionCodeUpdatedIntegrationMessage.h"
#include "bootstrap/ModuleFactories.h"
#include "bootstrap/PersistenceContainer.h"
#include "controller/ActiveCallsignCollection.h"
#include "flightplan/FlightPlanEventHandlerCollection.h"
#include "integration/IntegrationPersistenceContainer.h"
#include "integration/OutboundIntegrationEventHandler.h"
Expand All @@ -26,9 +28,13 @@ namespace UKControllerPlugin::IntentionCode {
container.integrationModuleContainer->outboundMessageHandler));

// Register the tag item for intention codes
const auto intentionCodeGenerator = container.moduleFactories->IntentionCode().CachedIntentionCodeGenerator(
*container.dependencyLoader, container.activeCallsigns);
container.tagHandler->RegisterTagItem(
intentionCodeTagItemId,
std::make_shared<IntentionCodeTagItem>(container.moduleFactories->IntentionCode().IntentionCodeGenerator(
*container.dependencyLoader, container.activeCallsigns)));
intentionCodeTagItemId, std::make_shared<IntentionCodeTagItem>(intentionCodeGenerator));

// Register the intention code generator for flightplan events and controller events
container.flightplanHandler->RegisterHandler(intentionCodeGenerator);
container.activeCallsigns->AddHandler(intentionCodeGenerator);
}
} // namespace UKControllerPlugin::IntentionCode
10 changes: 8 additions & 2 deletions test/plugin/intention/IntentionCodeBootstrapProviderTest.cpp
Expand Up @@ -34,10 +34,16 @@ namespace UKControllerPluginTest::IntentionCode {
IntentionCodeBootstrapProvider provider;
};

TEST_F(IntentionCodeModuleBootstrapProviderTest, TestItRegistersFirExitGeneratorForFlightplanEvents)
TEST_F(IntentionCodeModuleBootstrapProviderTest, TestItRegistersFirExitAndIntentionGeneratorsForFlightplanEvents)
{
this->RunBootstrapPlugin(provider);
EXPECT_EQ(1, container.flightplanHandler->CountHandlers());
EXPECT_EQ(2, container.flightplanHandler->CountHandlers());
}

TEST_F(IntentionCodeModuleBootstrapProviderTest, TestItRegistersIntentionGeneratorForActiveCallsignEvents)
{
this->RunBootstrapPlugin(provider);
EXPECT_EQ(1, container.activeCallsigns->CountHandlers());
}

TEST_F(IntentionCodeModuleBootstrapProviderTest, TestItRegistersIntegrationCodeUpdatedMessageForEvents)
Expand Down

0 comments on commit 4174460

Please sign in to comment.