Skip to content

Commit

Permalink
fix(handoff): departure frequencies not updating after runway dialog …
Browse files Browse the repository at this point in the history
…change

Runway dialog changes do trigger a SID change, but do not trigger a FP change event.
This means the plugin does not update the departure frequencies of any FPs that had
an airfield resolved handoff, even if the new SID (after the runway dialog change) would
have had a different controller. This fixes that by clearing the handoff cache after
a runway dialog change.

fix VATSIM-UK#480
  • Loading branch information
AndyTWF committed Aug 13, 2022
1 parent 0d23298 commit ad9b87b
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ set(src__handoff
"handoff/HandoffModule.cpp"
"handoff/HandoffModule.h"
controller/HandoffEventHandler.cpp
handoff/HandoffOrder.h handoff/HandoffOrder.cpp handoff/FlightplanSidHandoffMapper.cpp handoff/FlightplanSidHandoffMapper.h handoff/HandoffCache.cpp handoff/HandoffCache.h handoff/DepartureHandoffResolver.cpp handoff/DepartureHandoffResolver.h handoff/FlightplanAirfieldHandoffMapper.cpp handoff/FlightplanAirfieldHandoffMapper.h handoff/ClearCacheOnActiveCallsignChanges.cpp handoff/ClearCacheOnActiveCallsignChanges.h)
handoff/HandoffOrder.h handoff/HandoffOrder.cpp handoff/FlightplanSidHandoffMapper.cpp handoff/FlightplanSidHandoffMapper.h handoff/HandoffCache.cpp handoff/HandoffCache.h handoff/DepartureHandoffResolver.cpp handoff/DepartureHandoffResolver.h handoff/FlightplanAirfieldHandoffMapper.cpp handoff/FlightplanAirfieldHandoffMapper.h handoff/ClearCacheOnActiveCallsignChanges.cpp handoff/ClearCacheOnActiveCallsignChanges.h handoff/ClearCacheOnRunwayDialogSave.cpp handoff/ClearCacheOnRunwayDialogSave.h)
source_group("src\\handoff" FILES ${src__handoff})

set(src__headings headings/Heading.h headings/Heading.cpp)
Expand Down
1 change: 1 addition & 0 deletions src/plugin/euroscope/RunwayDialogAwareInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace UKControllerPlugin::Euroscope {
class RunwayDialogAwareInterface
{
public:
virtual ~RunwayDialogAwareInterface() = default;
virtual void RunwayDialogSaved() = 0;
};
} // namespace UKControllerPlugin::Euroscope
15 changes: 15 additions & 0 deletions src/plugin/handoff/ClearCacheOnRunwayDialogSave.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "ClearCacheOnRunwayDialogSave.h"
#include "HandoffCache.h"

namespace UKControllerPlugin::Handoff {

ClearCacheOnRunwayDialogSave::ClearCacheOnRunwayDialogSave(std::shared_ptr<HandoffCache> cache) : cache(cache)
{
assert(cache && "Handoff cache not set in ctor");
}

void ClearCacheOnRunwayDialogSave::RunwayDialogSaved()
{
cache->Clear();
}
} // namespace UKControllerPlugin::Handoff
18 changes: 18 additions & 0 deletions src/plugin/handoff/ClearCacheOnRunwayDialogSave.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once
#include "euroscope/RunwayDialogAwareInterface.h"

namespace UKControllerPlugin::Handoff {

class HandoffCache;

class ClearCacheOnRunwayDialogSave : public Euroscope::RunwayDialogAwareInterface
{
public:
ClearCacheOnRunwayDialogSave(std::shared_ptr<HandoffCache> cache);
void RunwayDialogSaved() override;

private:
// The cache
const std::shared_ptr<HandoffCache> cache;
};
} // namespace UKControllerPlugin::Handoff
3 changes: 3 additions & 0 deletions src/plugin/handoff/HandoffModule.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "ClearCacheOnActiveCallsignChanges.h"
#include "ClearCacheOnRunwayDialogSave.h"
#include "DepartureHandoffResolver.h"
#include "FlightplanAirfieldHandoffMapper.h"
#include "FlightplanSidHandoffMapper.h"
Expand All @@ -9,6 +10,7 @@
#include "bootstrap/PersistenceContainer.h"
#include "controller/ActiveCallsignCollection.h"
#include "dependency/DependencyLoaderInterface.h"
#include "euroscope/RunwayDialogAwareCollection.h"
#include "flightplan/FlightPlanEventHandlerCollection.h"
#include "tag/TagItemCollection.h"

Expand Down Expand Up @@ -41,6 +43,7 @@ namespace UKControllerPlugin::Handoff {
container.tagHandler->RegisterTagItem(handoffTagItem, handler);
container.flightplanHandler->RegisterHandler(handler);
container.activeCallsigns->AddHandler(std::make_shared<ClearCacheOnActiveCallsignChanges>(*cache));
container.runwayDialogEventHandlers->AddHandler(std::make_shared<ClearCacheOnRunwayDialogSave>(cache));
}

auto GetHandoffDependencyKey() -> std::string
Expand Down
4 changes: 3 additions & 1 deletion test/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ set(test__handoff
handoff/FlightplanSidHandoffMapperTest.cpp
handoff/FlightplanAirfieldHandoffMapperTest.cpp
handoff/HandoffCacheTest.cpp
handoff/DepartureHandoffResolverTest.cpp handoff/ClearCacheOnActiveCallsignChangesTest.cpp)
handoff/DepartureHandoffResolverTest.cpp
handoff/ClearCacheOnActiveCallsignChangesTest.cpp
handoff/ClearCacheOnRunwayDialogSaveTest.cpp)
source_group("test\\handoff" FILES ${test__handoff})

set(test__headings
Expand Down
28 changes: 28 additions & 0 deletions test/plugin/handoff/ClearCacheOnRunwayDialogSaveTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "handoff/ClearCacheOnRunwayDialogSave.h"
#include "handoff/HandoffCache.h"
#include "handoff/ResolvedHandoff.h"

using UKControllerPlugin::Handoff::ClearCacheOnRunwayDialogSave;
using UKControllerPlugin::Handoff::HandoffCache;
using UKControllerPlugin::Handoff::ResolvedHandoff;

namespace UKControllerPluginTest::Handoff {

class ClearCacheOnRunwayDialogSaveTest : public testing::Test
{
};

TEST_F(ClearCacheOnRunwayDialogSaveTest, FlushingCallsignsClearsCache)
{
auto cache = std::make_shared<HandoffCache>();
ClearCacheOnRunwayDialogSave clear(cache);

cache->Add(std::make_shared<ResolvedHandoff>("BAW123", nullptr, nullptr, nullptr));
cache->Add(std::make_shared<ResolvedHandoff>("BAW456", nullptr, nullptr, nullptr));
cache->Add(std::make_shared<ResolvedHandoff>("BAW789", nullptr, nullptr, nullptr));

EXPECT_EQ(3, cache->Count());
clear.RunwayDialogSaved();
EXPECT_EQ(0, cache->Count());
}
} // namespace UKControllerPluginTest::Handoff
10 changes: 9 additions & 1 deletion test/plugin/handoff/HandoffModuleTest.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#include "bootstrap/PersistenceContainer.h"
#include "controller/ActiveCallsignCollection.h"
#include "euroscope/RunwayDialogAwareCollection.h"
#include "flightplan/FlightPlanEventHandlerCollection.h"
#include "handoff/HandoffModule.h"
#include "handoff/HandoffCollection.h"
#include "integration/IntegrationServer.h"
#include "tag/TagItemCollection.h"

using ::testing::NiceMock;
using ::testing::Test;
using UKControllerPlugin::Bootstrap::PersistenceContainer;
using UKControllerPlugin::Controller::ActiveCallsignCollection;
using UKControllerPlugin::Euroscope::RunwayDialogAwareCollection;
using UKControllerPlugin::Flightplan::FlightPlanEventHandlerCollection;
using UKControllerPlugin::Handoff::BootstrapPlugin;
using UKControllerPlugin::Integration::IntegrationPersistenceContainer;
Expand All @@ -26,6 +27,7 @@ namespace UKControllerPluginTest::Handoff {
this->container.tagHandler = std::make_unique<TagItemCollection>();
this->container.flightplanHandler = std::make_unique<FlightPlanEventHandlerCollection>();
this->container.activeCallsigns = std::make_unique<ActiveCallsignCollection>();
this->container.runwayDialogEventHandlers = std::make_unique<RunwayDialogAwareCollection>();
this->container.integrationModuleContainer =
std::make_unique<IntegrationPersistenceContainer>(nullptr, nullptr, nullptr);
}
Expand All @@ -52,4 +54,10 @@ namespace UKControllerPluginTest::Handoff {
BootstrapPlugin(this->container, this->dependencyLoader);
ASSERT_EQ(1, this->container.activeCallsigns->CountHandlers());
}

TEST_F(HandoffModuleTest, TestItRegistersRunwayDialogHandler)
{
BootstrapPlugin(this->container, this->dependencyLoader);
ASSERT_EQ(1, this->container.runwayDialogEventHandlers->CountHandlers());
}
} // namespace UKControllerPluginTest::Handoff

0 comments on commit ad9b87b

Please sign in to comment.