Skip to content

Commit

Permalink
refactor: departure releases uses a shared collection
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyTWF committed May 23, 2023
1 parent fa9d030 commit d591be3
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 99 deletions.
6 changes: 6 additions & 0 deletions src/plugin/CMakeLists.txt
Expand Up @@ -77,6 +77,11 @@ set(src__bootstrap
bootstrap/PersistenceContainer.cpp bootstrap/BootstrapProviderInterface.h bootstrap/BootstrapProviderCollection.h bootstrap/BootstrapProviderCollection.cpp bootstrap/BootstrapProviderCollection.h bootstrap/ModuleFactories.h bootstrap/ModuleFactories.cpp bootstrap/ModuleFactories.h bootstrap/BootstrapProviderCollectionFactory.cpp bootstrap/BootstrapProviderCollectionFactory.h bootstrap/ModuleBootstrap.cpp bootstrap/ModuleBootstrap.h)
source_group("src\\bootstrap" FILES ${src__bootstrap})

set(src__collection

collection/PluginCollectionTypesFwd.h)
source_group("src\\collection" FILES ${src__collection})

set(src__command
"command/CommandHandlerCollection.cpp"
"command/CommandHandlerCollection.h"
Expand Down Expand Up @@ -960,6 +965,7 @@ set(ALL_FILES
${src__api}
${src__approach}
${src__bootstrap}
${src__collection}
${src__command}
${src__components}
${src__controller}
Expand Down
12 changes: 12 additions & 0 deletions src/plugin/collection/PluginCollectionTypesFwd.h
@@ -0,0 +1,12 @@
#pragma once

namespace UKControllerPluginUtils::Collection {
template <typename KeyType, typename ValueType> class Collection;
} // namespace UKControllerPluginUtils::Collection

namespace UKControllerPlugin::Releases {
class DepartureReleaseRequest;

using DepartureReleaseRequestCollection =
UKControllerPluginUtils::Collection::Collection<int, DepartureReleaseRequest>;
} // namespace UKControllerPlugin::Releases
147 changes: 61 additions & 86 deletions src/plugin/releases/DepartureReleaseEventHandler.cpp

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/plugin/releases/DepartureReleaseEventHandler.h
@@ -1,4 +1,5 @@
#pragma once
#include "collection/PluginCollectionTypesFwd.h"
#include "push/PushEventProcessorInterface.h"
#include "releases/CompareDepartureReleases.h"
#include "tag/TagItemInterface.h"
Expand Down Expand Up @@ -44,6 +45,7 @@ namespace UKControllerPlugin {
{
public:
DepartureReleaseEventHandler(
const std::shared_ptr<DepartureReleaseRequestCollection> releaseRequests,
const Api::ApiInterface& api,
TaskManager::TaskRunnerInterface& taskRunner,
Euroscope::EuroscopePluginLoopbackInterface& plugin,
Expand Down Expand Up @@ -137,7 +139,7 @@ namespace UKControllerPlugin {
static const int RELEASE_DECISION_MADE_DELETE_AFTER_SECONDS = 90;

// Release requests in progress
std::map<int, std::shared_ptr<DepartureReleaseRequest>> releaseRequests;
const std::shared_ptr<DepartureReleaseRequestCollection> releaseRequests;

// Controller positions
const Controller::ControllerPositionCollection& controllers;
Expand Down
5 changes: 5 additions & 0 deletions src/plugin/releases/DepartureReleaseRequest.cpp
Expand Up @@ -135,4 +135,9 @@ namespace UKControllerPlugin::Releases {
{
return this->remarks;
}

auto DepartureReleaseRequest::CollectionKey() const -> int
{
return this->id;
}
} // namespace UKControllerPlugin::Releases
1 change: 1 addition & 0 deletions src/plugin/releases/DepartureReleaseRequest.h
Expand Up @@ -13,6 +13,7 @@ namespace UKControllerPlugin::Releases {
std::chrono::system_clock::time_point requestExpiresAt);

void Acknowledge();
[[nodiscard]] auto CollectionKey() const -> int;
void Reject(std::string remarks);
void Approve(
std::chrono::system_clock::time_point releasedAtTime,
Expand Down
3 changes: 3 additions & 0 deletions src/plugin/releases/ReleaseModule.cpp
Expand Up @@ -8,6 +8,7 @@
#include "ReleaseModule.h"
#include "RequestDepartureReleaseDialog.h"
#include "bootstrap/PersistenceContainer.h"
#include "collection/Collection.h"
#include "controller/HandoffEventHandlerCollection.h"
#include "dependency/DependencyLoaderInterface.h"
#include "dialog/DialogManager.h"
Expand Down Expand Up @@ -113,7 +114,9 @@ namespace UKControllerPlugin::Releases {
// Create the event handler
const int releaseDecisionCallbackId = container.pluginFunctionHandlers->ReserveNextDynamicFunctionId();
const int releaseCancellationCallbackId = container.pluginFunctionHandlers->ReserveNextDynamicFunctionId();
auto releaseCollection = std::make_shared<UKControllerPlugin::Releases::DepartureReleaseRequestCollection>();
auto departureHandler = std::make_shared<DepartureReleaseEventHandler>(
releaseCollection,
*container.api,
*container.taskRunner,
*container.plugin,
Expand Down
2 changes: 2 additions & 0 deletions test/plugin/departure/DepartureCoordinationListTest.cpp
@@ -1,3 +1,4 @@
#include "collection/Collection.h"
#include "controller/ActiveCallsignCollection.h"
#include "controller/ControllerPosition.h"
#include "controller/ControllerPositionCollection.h"
Expand All @@ -24,6 +25,7 @@ namespace UKControllerPluginTest::Departure {
list(std::make_shared<DepartureCoordinationList>(
handler, prenotes, mockPlugin, controllers, activeCallsigns, 3)),
handler(
std::make_shared<UKControllerPlugin::Releases::DepartureReleaseRequestCollection>(),
mockApi,
taskRunner,
mockPlugin,
Expand Down
25 changes: 14 additions & 11 deletions test/plugin/departure/ToggleDepartureCoordinationListTest.cpp
@@ -1,3 +1,4 @@
#include "collection/Collection.h"
#include "controller/ActiveCallsignCollection.h"
#include "controller/ControllerPositionCollection.h"
#include "departure/DepartureCoordinationList.h"
Expand All @@ -19,17 +20,19 @@ namespace UKControllerPluginTest::Departure {
{
public:
ToggleDepartureCoordinationListTest()
: messager(mockPlugin), handler(
mockApi,
taskRunner,
mockPlugin,
controllers,
activeCallsigns,
dialogManager,
windows,
messager,
103,
104),
: messager(mockPlugin),
handler(
std::make_shared<UKControllerPlugin::Releases::DepartureReleaseRequestCollection>(),
mockApi,
taskRunner,
mockPlugin,
controllers,
activeCallsigns,
dialogManager,
windows,
messager,
103,
104),
list(std::make_shared<DepartureCoordinationList>(
handler, prenotes, mockPlugin, controllers, activeCallsigns, 3)),
dialogManager(dialogProvider)
Expand Down
13 changes: 12 additions & 1 deletion test/plugin/releases/DepartureReleaseEventHandlerTest.cpp
@@ -1,4 +1,5 @@
#include "api/ApiException.h"
#include "collection/Collection.h"
#include "controller/ActiveCallsignCollection.h"
#include "controller/ControllerPosition.h"
#include "controller/ControllerPositionCollection.h"
Expand Down Expand Up @@ -35,7 +36,17 @@ namespace UKControllerPluginTest::Releases {
DepartureReleaseEventHandlerTest()
: dialogManager(dialogProvider), messager(mockPlugin),
handler(
api, mockTaskRunner, mockPlugin, controllers, activeCallsigns, dialogManager, windows, messager, 3, 4)
std::make_shared<UKControllerPlugin::Releases::DepartureReleaseRequestCollection>(),
api,
mockTaskRunner,
mockPlugin,
controllers,
activeCallsigns,
dialogManager,
windows,
messager,
3,
4)
{
request = std::make_shared<DepartureReleaseRequest>(
1, "BAW123", 3, 2, std::chrono::system_clock::now() + std::chrono::minutes(5));
Expand Down
5 changes: 5 additions & 0 deletions test/plugin/releases/DepartureReleaseRequestTest.cpp
Expand Up @@ -26,6 +26,11 @@ namespace UKControllerPluginTes::Releases {
EXPECT_EQ(1, request->Id());
}

TEST_F(DepartureReleaseRequestTest, ItUsesIdAsCollectionKey)
{
EXPECT_EQ(1, request->CollectionKey());
}

TEST_F(DepartureReleaseRequestTest, ItHasACallsign)
{
EXPECT_EQ("BAW123", request->Callsign());
Expand Down

0 comments on commit d591be3

Please sign in to comment.