-
Notifications
You must be signed in to change notification settings - Fork 22
/
SquawkModule.cpp
130 lines (113 loc) · 6.23 KB
/
SquawkModule.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "ApiSquawkAllocationHandler.h"
#include "ResetSquawkOnFailedDelete.h"
#include "SquawkAssignment.h"
#include "SquawkAssignmentDeleteForConspicuityFailedEvent.h"
#include "SquawkAssignmentMenu.h"
#include "SquawkEventHandler.h"
#include "SquawkGenerator.h"
#include "SquawkModule.h"
#include "bootstrap/PersistenceContainer.h"
#include "controller/ActiveCallsignCollection.h"
#include "controller/ControllerStatusEventHandlerCollection.h"
#include "euroscope/EuroscopeRadarLoopbackInterface.h"
#include "euroscope/RadarScreenCallbackFunction.h"
#include "euroscope/UserSettingAwareCollection.h"
#include "eventhandler/EventBus.h"
#include "eventhandler/EventHandlerFlags.h"
#include "flightplan/FlightPlanEventHandlerCollection.h"
#include "plugin/FunctionCallEventHandler.h"
#include "plugin/UKPlugin.h"
#include "tag/TagFunction.h"
#include "timedevent/TimedEventCollection.h"
using UKControllerPlugin::Squawk::ApiSquawkAllocationHandler;
using UKControllerPlugin::Squawk::SquawkEventHandler;
using UKControllerPlugin::Squawk::SquawkGenerator;
using UKControllerPlugin::Tag::TagFunction;
namespace UKControllerPlugin::Squawk {
// The callback function ID with euroscope for forcing squawk refresh (general squawk).
const int squawkForceCallbackIdGeneral = 9000;
// The callback function ID with euroscope for forcing squawk refresh (local squawk).
const int squawkForceCallbackIdLocal = 9001;
/*
Bootstrap the squawk module when the plugin loads.
*/
void SquawkModule::BootstrapPlugin(
UKControllerPlugin::Bootstrap::PersistenceContainer& container, bool automaticAssignmentDisabled)
{
// API allocation handler
std::shared_ptr<ApiSquawkAllocationHandler> allocations =
std::make_shared<ApiSquawkAllocationHandler>(*container.plugin);
container.timedHandler->RegisterEvent(allocations, SquawkModule::allocationCheckFrequency);
// Assignment rules and generator
container.squawkAssignmentRules = std::make_unique<SquawkAssignment>(
*container.flightplans, *container.plugin, *container.airfieldOwnership, *container.activeCallsigns);
container.squawkGenerator = std::make_unique<SquawkGenerator>(
*container.api,
container.taskRunner.get(),
*container.squawkAssignmentRules,
*container.activeCallsigns,
*container.flightplans,
allocations);
// The event handler
std::shared_ptr<SquawkEventHandler> eventHandler(new SquawkEventHandler(
*container.squawkGenerator,
*container.activeCallsigns,
*container.flightplans,
*container.plugin,
*container.login,
automaticAssignmentDisabled));
container.squawkEvents = eventHandler;
container.flightplanHandler->RegisterHandler(eventHandler);
container.timedHandler->RegisterEvent(eventHandler, squawkAssignmentsCheckFrequency);
container.userSettingHandlers->RegisterHandler(eventHandler);
container.activeCallsigns->AddHandler(eventHandler);
TagFunction forceSquawkCallbackGeneral(
squawkForceCallbackIdGeneral,
"Force Squawk Recycle (General)",
[eventHandler](
UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface& fp,
UKControllerPlugin::Euroscope::EuroScopeCRadarTargetInterface& rt,
const std::string& context,
const POINT& mousePos) { eventHandler->SquawkReycleGeneral(fp, rt, context, mousePos); });
container.pluginFunctionHandlers->RegisterFunctionCall(forceSquawkCallbackGeneral);
TagFunction forceSquawkCallbackLocal(
squawkForceCallbackIdLocal,
"Force Squawk Recycle (Local)",
[eventHandler](
UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface& fp,
UKControllerPlugin::Euroscope::EuroScopeCRadarTargetInterface& rt,
const std::string& context,
const POINT& mousePos) { eventHandler->SquawkRecycleLocal(fp, rt, context, mousePos); });
container.pluginFunctionHandlers->RegisterFunctionCall(forceSquawkCallbackLocal);
// Squawk assignment menu
int squawkMenuCallbackId = container.pluginFunctionHandlers->ReserveNextDynamicFunctionId();
std::shared_ptr<SquawkAssignmentMenu> squawkMenu = std::make_shared<SquawkAssignmentMenu>(
squawkMenuCallbackId, *container.squawkGenerator, *container.activeCallsigns, *container.plugin);
// Register a callback function for when the option is selected
Euroscope::RadarScreenCallbackFunction menuCallbackFunction(
squawkMenuCallbackId,
"Squawk Assignment Menu Callback",
[squawkMenu](
int,
UKControllerPlugin::Euroscope::EuroscopeRadarLoopbackInterface& radarScreen,
const std::string& context,
const POINT& mousePos,
const RECT& area) { squawkMenu->MenuOptionSelected(radarScreen, context, mousePos, area); });
container.pluginFunctionHandlers->RegisterFunctionCall(menuCallbackFunction);
// Register the tag function
TagFunction squawkMenuTagFunction(
9022,
"Open Squawk Assignment Menu",
[squawkMenu](
UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface& fp,
UKControllerPlugin::Euroscope::EuroScopeCRadarTargetInterface& rt,
const std::string& context,
const POINT& mousePos) { squawkMenu->DisplaySquawkAssignmentMenu(fp, mousePos); });
container.pluginFunctionHandlers->RegisterFunctionCall(squawkMenuTagFunction);
// Handler to reset squawks if delete fails
UKControllerPluginUtils::EventHandler::EventBus::Bus()
.AddHandler<SquawkAssignmentDeleteForConspicuityFailedEvent>(
std::make_shared<ResetSquawkOnFailedDelete>(*container.plugin, *container.flightplans),
UKControllerPluginUtils::EventHandler::EventHandlerFlags::EuroscopeThread);
}
} // namespace UKControllerPlugin::Squawk