Skip to content

Commit

Permalink
Fix initial controller load (#39)
Browse files Browse the repository at this point in the history
* Load ControllerMe On Initial Load

* Add Function To Translate Facility Abbreviations

Translates popular abbreviations of facilities (e.g. ESX -> ESSEX)
for matching against the ControllerPositionCollection

* ControllerPositionCollection Handles Special Positions

Updated to properly recognise ESSEX, THAMES, SOLENT and their
possible abbreviations

* Linting

* Bump Plugin Version

* Comment To Trigger CI

* Change Ownership Logging Logic

It needs to log if there is no owner.
  • Loading branch information
AndyTWF authored Feb 23, 2019
1 parent bbdf551 commit 3e87976
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 5 deletions.
2 changes: 2 additions & 0 deletions msvc/UKControllerPlugin/UKControllerPlugin.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<ClInclude Include="..\..\src\controller\ControllerPositionParser.h" />
<ClInclude Include="..\..\src\controller\ControllerStatusEventHandlerCollection.h" />
<ClInclude Include="..\..\src\controller\ControllerStatusEventHandlerInterface.h" />
<ClInclude Include="..\..\src\controller\TranslateFrequencyAbbreviation.h" />
<ClInclude Include="..\..\src\countdown\CountdownModule.h" />
<ClInclude Include="..\..\src\countdown\CountdownRenderer.h" />
<ClInclude Include="..\..\src\countdown\CountdownTimer.h" />
Expand Down Expand Up @@ -253,6 +254,7 @@
<ClCompile Include="..\..\src\controller\ControllerPositionHierarchyFactory.cpp" />
<ClCompile Include="..\..\src\controller\ControllerPositionParser.cpp" />
<ClCompile Include="..\..\src\controller\ControllerStatusEventHandlerCollection.cpp" />
<ClCompile Include="..\..\src\controller\TranslateFrequencyAbbreviation.cpp" />
<ClCompile Include="..\..\src\countdown\CountdownModule.cpp" />
<ClCompile Include="..\..\src\countdown\CountdownRenderer.cpp" />
<ClCompile Include="..\..\src\countdown\CountdownTimer.cpp" />
Expand Down
8 changes: 7 additions & 1 deletion msvc/UKControllerPlugin/UKControllerPlugin.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,9 @@
<ClInclude Include="..\..\src\squawk\ApiSquawkAllocation.h">
<Filter>src\squawk</Filter>
</ClInclude>
<ClInclude Include="..\..\src\controller\TranslateFrequencyAbbreviation.h">
<Filter>src\controller</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\resource\UKControllerPlugin.rc">
Expand Down Expand Up @@ -1207,5 +1210,8 @@
<ClCompile Include="..\..\src\squawk\ApiSquawkAllocationHandler.cpp">
<Filter>src\squawk</Filter>
</ClCompile>
<ClCompile Include="..\..\src\controller\TranslateFrequencyAbbreviation.cpp">
<Filter>src\controller</Filter>
</ClCompile>
</ItemGroup>
</Project>
</Project>
1 change: 1 addition & 0 deletions msvc/UKControllerPluginTest/UKControllerPluginTest.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<ClCompile Include="..\..\test\test\controller\ControllerPositionParserTest.cpp" />
<ClCompile Include="..\..\test\test\controller\ControllerPositionTest.cpp" />
<ClCompile Include="..\..\test\test\controller\ControllerStatusEventHandlerCollectionTest.cpp" />
<ClCompile Include="..\..\test\test\controller\TranslateFrequencyAbbreviationTest.cpp" />
<ClCompile Include="..\..\test\test\countdown\CountdownModuleTest.cpp" />
<ClCompile Include="..\..\test\test\countdown\CountdownRendererTest.cpp" />
<ClCompile Include="..\..\test\test\countdown\CountdownTimerTest.cpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,9 @@
<ClCompile Include="..\..\test\test\squawk\ApiSquawkAllocationTest.cpp">
<Filter>test\squawk</Filter>
</ClCompile>
<ClCompile Include="..\..\test\test\controller\TranslateFrequencyAbbreviationTest.cpp">
<Filter>test\controller</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\test\helper\ApiRequestHelperFunctions.h">
Expand Down Expand Up @@ -636,4 +639,4 @@
<Filter>mock</Filter>
</ClInclude>
</ItemGroup>
</Project>
</Project>
2 changes: 1 addition & 1 deletion src/airfield/AirfieldOwnershipManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ namespace UKControllerPlugin {
}

// Only log when positions have changed hands
bool needsLog = this->ownershipMap.count(icao) > 0 &&
bool needsLog = this->ownershipMap.count(icao) == 0 ||
this->ownershipMap.at(icao)->GetCallsign() !=
this->activeCallsigns.GetLeadCallsignForPosition(*it).GetCallsign();

Expand Down
7 changes: 6 additions & 1 deletion src/controller/ControllerPositionCollection.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "pch/stdafx.h"
#include "controller/ControllerPositionCollection.h"
#include "controller/ControllerPosition.h"
#include "controller/TranslateFrequencyAbbreviation.h"

using UKControllerPlugin::Controller::ControllerPosition;

Expand Down Expand Up @@ -35,6 +36,9 @@ namespace UKControllerPlugin {
std::string facility,
double frequency
) const {

facility = TranslateFrequencyAbbreviation(facility);

// If there's no chance of finding anything, save us the iteration.
if (!this->IsPossibleAreaPosition(facility) && !this->IsPossibleAirfieldPosition(facility)) {
throw std::out_of_range("Position not found.");
Expand Down Expand Up @@ -70,7 +74,8 @@ namespace UKControllerPlugin {
*/
bool ControllerPositionCollection::IsPossibleAirfieldPosition(std::string facility) const
{
return facility.size() == 4 && facility.substr(0, 2) == "EG";
return facility == "ESSEX" || facility == "THAMES" || facility == "SOLENT" ||
facility.size() == 4 && facility.substr(0, 2) == "EG";
}

/*
Expand Down
23 changes: 23 additions & 0 deletions src/controller/TranslateFrequencyAbbreviation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "pch/stdafx.h"
#include "controller/TranslateFrequencyAbbreviation.h"

namespace UKControllerPlugin {
namespace Controller {

std::map <std::string, std::string> translations = {
{"ESX", "ESSEX"},
{"SOL", "SOLENT"},
{"THA", "THAMES"},
{"TMS", "THAMES"}
};

/*
Given a recognised abbreviation for a facility, translate
it to the full facility for use in matching controller positions.
*/
std::string TranslateFrequencyAbbreviation(std::string facility)
{
return translations.count(facility) ? translations.at(facility) : facility;
}
} // namespace Controller
} // namespace UKControllerPlugin
8 changes: 8 additions & 0 deletions src/controller/TranslateFrequencyAbbreviation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

namespace UKControllerPlugin {
namespace Controller {

std::string TranslateFrequencyAbbreviation(std::string facility);
} // namespace Controller
} // namespace UKControllerPlugin
7 changes: 7 additions & 0 deletions src/plugin/UKPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ namespace UKControllerPlugin {
void UKPlugin::DoInitialControllerLoad(void)
{
LogInfo("Initial controller load started");

EuroScopePlugIn::CController me = this->ControllerMyself();
if (me.IsValid()) {
this->OnControllerPositionUpdate(me);
LogInfo("Loaded myself, on " + std::string(me.GetCallsign()));
}

EuroScopePlugIn::CController current = this->ControllerSelectFirst();

// If there's nobody online, stop.
Expand Down
2 changes: 1 addition & 1 deletion src/update/PluginVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace UKControllerPlugin {
namespace Plugin {
const char * const PluginVersion::version = "1.1.1";
const char * const PluginVersion::version = "1.1.2";
const char * const PluginVersion::title = "UK Controller Plugin";
const char * const PluginVersion::author = "VATSIM UK";
const char * const PluginVersion::copyright = "VATSIM United Kingdom Division";
Expand Down
6 changes: 6 additions & 0 deletions src/update/PluginVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

namespace UKControllerPlugin {
namespace Plugin {

/*
Contains the version details of the plugin
that get passed to ES and are also used in update
checks.
*/
typedef struct PluginVersion {
static const char * const version;
static const char * const title;
Expand Down
48 changes: 48 additions & 0 deletions test/test/controller/ControllerPositionCollectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,53 @@ namespace UKControllerPluginTest {
collection.AddPosition(std::move(controller));
EXPECT_EQ(*controllerRaw, collection.FetchPositionByFacilityAndFrequency("EGFF", 125.8514));
}

TEST(ControllerPositionCollection, FetchPositionByFacilityAndFrequencyWillWorkForEssex)
{
ControllerPositionCollection collection;
std::unique_ptr<ControllerPosition> controller(
new ControllerPosition("ESSEX_APP", 120.620, "APP", std::vector<std::string> {"EGSS, EGGW, EGSC"})
);

ControllerPosition * controllerRaw = controller.get();
collection.AddPosition(std::move(controller));
EXPECT_EQ(*controllerRaw, collection.FetchPositionByFacilityAndFrequency("ESSEX", 120.620));
}

TEST(ControllerPositionCollection, FetchPositionByFacilityAndFrequencyWillWorkForThames)
{
ControllerPositionCollection collection;
std::unique_ptr<ControllerPosition> controller(
new ControllerPosition("THAMES", 132.700, "APP", std::vector<std::string> {"EGLC, EGKB"})
);

ControllerPosition * controllerRaw = controller.get();
collection.AddPosition(std::move(controller));
EXPECT_EQ(*controllerRaw, collection.FetchPositionByFacilityAndFrequency("THAMES", 132.700));
}

TEST(ControllerPositionCollection, FetchPositionByFacilityAndFrequencyWillWorkForSolent)
{
ControllerPositionCollection collection;
std::unique_ptr<ControllerPosition> controller(
new ControllerPosition("SOLENT", 120.220, "APP", std::vector<std::string> {"EGLC, EGKB"})
);

ControllerPosition * controllerRaw = controller.get();
collection.AddPosition(std::move(controller));
EXPECT_EQ(*controllerRaw, collection.FetchPositionByFacilityAndFrequency("SOLENT", 120.220));
}

TEST(ControllerPositionCollection, FetchPositionByFacilityAndFrequencyWillWorkForAbbreviations)
{
ControllerPositionCollection collection;
std::unique_ptr<ControllerPosition> controller(
new ControllerPosition("ESSEX_APP", 120.620, "APP", std::vector<std::string> {"EGSS, EGGW, EGSC"})
);

ControllerPosition * controllerRaw = controller.get();
collection.AddPosition(std::move(controller));
EXPECT_EQ(*controllerRaw, collection.FetchPositionByFacilityAndFrequency("ESX", 120.620));
}
} // namespace Controller
} // namespace UKControllerPluginTest
34 changes: 34 additions & 0 deletions test/test/controller/TranslateFrequencyAbbreviationTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "pch/pch.h"
#include "controller/TranslateFrequencyAbbreviation.h"

using UKControllerPlugin::Controller::TranslateFrequencyAbbreviation;

namespace UKControllerPluginTest {
namespace Controller {

TEST(TranslateFrequencyAbbreviation, ItTranslatesEssexAbbreviation)
{
EXPECT_EQ("ESSEX", TranslateFrequencyAbbreviation("ESX"));
}

TEST(TranslateFrequencyAbbreviation, ItTranslatesSolentAbbreviation)
{
EXPECT_EQ("SOLENT", TranslateFrequencyAbbreviation("SOL"));
}

TEST(TranslateFrequencyAbbreviation, ItTranslatesThamesAbbreviation)
{
EXPECT_EQ("THAMES", TranslateFrequencyAbbreviation("THA"));
}

TEST(TranslateFrequencyAbbreviation, ItTranslatesThamesAbbreviation2)
{
EXPECT_EQ("THAMES", TranslateFrequencyAbbreviation("TMS"));
}

TEST(TranslateFrequencyAbbreviation, ItReturnsFacilityIfNoTranslation)
{
EXPECT_EQ("EGKK", TranslateFrequencyAbbreviation("EGKK"));
}
} // namespace Controller
} // namespace UKControllerPluginTest

0 comments on commit 3e87976

Please sign in to comment.