Skip to content

Commit a8fdec6

Browse files
author
Andy Ford
authored
Merge pull request #12 from ECFMP/data-update-events
Data update events
2 parents d5f722c + d5b6432 commit a8fdec6

65 files changed

Lines changed: 2596 additions & 470 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/ECFMP/ECFMP.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "ECFMP/eventbus/EventListener.h"
1010
#include "ECFMP/flightinformationregion/FlightInformationRegion.h"
1111
#include "ECFMP/flowmeasure/AirportFilter.h"
12+
#include "ECFMP/flowmeasure/CanonicalFlowMeasureInfo.h"
1213
#include "ECFMP/flowmeasure/EventFilter.h"
1314
#include "ECFMP/flowmeasure/FlowMeasure.h"
1415
#include "ECFMP/flowmeasure/FlowMeasureFilters.h"

include/ECFMP/Sdk.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#pragma once
2+
#include "api/ElementCollectionTypes.h"
23

34
namespace ECFMP {
45
namespace EventBus {
@@ -19,6 +20,23 @@ namespace ECFMP::Plugin {
1920
public:
2021
virtual ~Sdk() = default;
2122

23+
/**
24+
* All the flight information regions that are currently loaded.
25+
*/
26+
[[nodiscard]] virtual auto FlightInformationRegions() const noexcept
27+
-> std::shared_ptr<const Api::FlightInformationRegionCollection> = 0;
28+
29+
/**
30+
* All the events that are currently loaded.
31+
*/
32+
[[nodiscard]] virtual auto Events() const noexcept -> std::shared_ptr<const Api::EventCollection> = 0;
33+
34+
/**
35+
* All the flow measures that are currently loaded.
36+
*/
37+
[[nodiscard]] virtual auto FlowMeasures() const noexcept
38+
-> std::shared_ptr<const Api::FlowMeasureCollection> = 0;
39+
2240
/**
2341
* The event bus for the SDK, which can be used to subscribe to events.
2442
*/

include/ECFMP/SdkEvents.h

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,40 @@
11
#pragma once
2+
#include "ECFMP/api/ElementCollectionTypes.h"
23

34
namespace ECFMP::FlowMeasure {
45
class FlowMeasure;
56
}// namespace ECFMP::FlowMeasure
67

78
namespace ECFMP::Plugin {
9+
10+
// Events
11+
using EventsUpdatedEvent = struct EventsUpdatedEvent {
12+
std::shared_ptr<ECFMP::Api::EventCollection> events;
13+
};
14+
15+
// Flow measures
16+
using FlowMeasuresUpdatedEvent = struct FlowMeasureUpdatedEvent {
17+
std::shared_ptr<ECFMP::Api::FlowMeasureCollection> flowMeasures;
18+
};
19+
820
using FlowMeasureNotifiedEvent = struct FlowMeasureNotifiedEvent {
9-
const FlowMeasure::FlowMeasure& measure;
21+
std::shared_ptr<const FlowMeasure::FlowMeasure> flowMeasure;
1022
};
1123

1224
using FlowMeasureActivatedEvent = struct FlowMeasureActivatedEvent {
13-
const FlowMeasure::FlowMeasure& measure;
25+
std::shared_ptr<const FlowMeasure::FlowMeasure> flowMeasure;
1426
};
1527

1628
using FlowMeasureExpiredEvent = struct FlowMeasureExpiredEvent {
17-
const FlowMeasure::FlowMeasure& measure;
29+
std::shared_ptr<const FlowMeasure::FlowMeasure> flowMeasure;
1830
};
1931

2032
using FlowMeasureWithdrawnEvent = struct FlowMeasureWithdrawnEvent {
21-
const FlowMeasure::FlowMeasure& measure;
33+
std::shared_ptr<const FlowMeasure::FlowMeasure> flowMeasure;
2234
};
2335

2436
using FlowMeasureReissuedEvent = struct FlowMeasureReissuedEvent {
25-
const FlowMeasure::FlowMeasure& original;
26-
const FlowMeasure::FlowMeasure& reissued;
37+
std::shared_ptr<const FlowMeasure::FlowMeasure> original;
38+
std::shared_ptr<const FlowMeasure::FlowMeasure> reissued;
2739
};
2840
}// namespace ECFMP::Plugin

include/ECFMP/SdkFactory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace ECFMP::Plugin {
5555
*
5656
* Throws an SdkConfigurationException if the configuration is bad.
5757
*/
58-
[[nodiscard]] auto Instance() -> std::unique_ptr<Sdk>;
58+
[[nodiscard]] auto Instance() -> std::shared_ptr<Sdk>;
5959

6060
private:
6161
SdkFactory();

include/ECFMP/eventbus/EventBus.h

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
2-
#include "eventbus/InternalEventStream.h"
2+
#include "../../src/eventbus/EventDispatcherFactory.h"
3+
#include "../../src/eventbus/EventStream.h"
4+
#include "../../src/eventbus/SubscriptionFlags.h"
35
#include <any>
46
#include <mutex>
57
#include <typeindex>
@@ -10,6 +12,12 @@ namespace ECFMP::EventBus {
1012
class EventBus
1113
{
1214
public:
15+
explicit EventBus(const std::shared_ptr<EventDispatcherFactory>& dispatcherFactory)
16+
: dispatcherFactory(dispatcherFactory)
17+
{
18+
assert(dispatcherFactory != nullptr && "Dispatcher factory cannot be null");
19+
}
20+
1321
virtual ~EventBus() = default;
1422
/**
1523
* Subscribes the given listener to the event stream.
@@ -24,7 +32,15 @@ namespace ECFMP::EventBus {
2432
void
2533
Subscribe(std::shared_ptr<EventListener<EventType>> listener, std::shared_ptr<EventFilter<EventType>> filter)
2634
{
27-
GetStream<EventType>().Subscribe(listener, filter);
35+
if (listener == nullptr) {
36+
throw std::invalid_argument("Listener cannot be null");
37+
}
38+
39+
Subscribe<EventType>(EventSubscription{
40+
dispatcherFactory->CreateDispatcher<EventType>(listener, EventDispatchMode::Euroscope),
41+
listener,
42+
filter,
43+
{EventDispatchMode::Euroscope, false}});
2844
};
2945

3046
/**
@@ -41,7 +57,15 @@ namespace ECFMP::EventBus {
4157
std::shared_ptr<EventListener<EventType>> listener, std::shared_ptr<EventFilter<EventType>> filter
4258
)
4359
{
44-
GetStream<EventType>().SubscribeOnce(listener, filter);
60+
if (listener == nullptr) {
61+
throw std::invalid_argument("Listener cannot be null");
62+
}
63+
64+
Subscribe<EventType>(EventSubscription{
65+
dispatcherFactory->CreateDispatcher<EventType>(listener, EventDispatchMode::Euroscope),
66+
listener,
67+
filter,
68+
{EventDispatchMode::Euroscope, true}});
4569
};
4670

4771
/**
@@ -55,18 +79,28 @@ namespace ECFMP::EventBus {
5579
return GetStream<EventType>().template HasListenerOfType<ListenerType>();
5680
}
5781

82+
protected:
83+
template<typename ListenerType, typename EventType>
84+
void Subscribe(const EventSubscription<EventType>& subscription)
85+
{
86+
GetStream<EventType>().Subscribe(subscription);
87+
}
88+
89+
// Factory for dispatchers
90+
std::shared_ptr<EventDispatcherFactory> dispatcherFactory;
91+
5892
private:
5993
template<typename EventType>
60-
auto GetStream() -> InternalEventStream<EventType>&
94+
auto GetStream() -> EventStream<EventType>&
6195
{
6296
auto lock = std::lock_guard(mutex);
6397

6498
const auto index = std::type_index(typeid(EventType));
6599
if (!streams.contains(index)) {
66-
streams.insert({index, std::any(std::make_shared<InternalEventStream<EventType>>())});
100+
streams.insert({index, std::any(std::make_shared<EventStream<EventType>>())});
67101
}
68102

69-
return *std::any_cast<std::shared_ptr<InternalEventStream<EventType>>>(streams.at(index));
103+
return *std::any_cast<std::shared_ptr<EventStream<EventType>>>(streams.at(index));
70104
}
71105

72106
// Protects the streams map

include/ECFMP/eventbus/EventFilter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ namespace ECFMP::EventBus {
77
{
88
public:
99
virtual ~EventFilter() = default;
10-
virtual bool ShouldProcess(const EventType&) = 0;
10+
virtual bool ShouldProcess(const EventType& event) = 0;
1111
};
1212
}// namespace ECFMP::EventBus

include/ECFMP/eventbus/EventListener.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ namespace ECFMP::EventBus {
66
{
77
public:
88
virtual ~EventListener() = default;
9-
virtual void OnEvent(const EventType&) = 0;
9+
virtual void OnEvent(const EventType& event) = 0;
1010
};
1111
}// namespace ECFMP::EventBus

include/ECFMP/eventbus/EventStream.h

Lines changed: 0 additions & 71 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
3+
namespace ECFMP::FlowMeasure {
4+
5+
/**
6+
* Contains information about a canonical flow measure.
7+
*/
8+
class CanonicalFlowMeasureInfo
9+
{
10+
public:
11+
CanonicalFlowMeasureInfo(const std::string& identifier);
12+
[[nodiscard]] auto Identifier() const noexcept -> const std::string&;
13+
[[nodiscard]] auto Revision() const noexcept -> int;
14+
[[nodiscard]] auto IsAfter(const CanonicalFlowMeasureInfo& other) const noexcept -> bool;
15+
16+
private:
17+
[[nodiscard]] static auto ParseIdentifier(const std::string& identifier) -> std::string;
18+
[[nodiscard]] static auto ParseRevision(const std::string& identifier) -> int;
19+
20+
// The identifier of the canonical flow measure
21+
std::string identifier;
22+
23+
// The revision of the canonical flow measure
24+
int revision;
25+
};
26+
27+
}// namespace ECFMP::FlowMeasure

include/ECFMP/flowmeasure/FlowMeasure.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace ECFMP {
1313
namespace ECFMP::FlowMeasure {
1414
class FlowMeasureFilters;
1515
class Measure;
16+
class CanonicalFlowMeasureInfo;
1617

1718
/**
1819
* Represents the status of the flow measure
@@ -111,5 +112,8 @@ namespace ECFMP::FlowMeasure {
111112
* Returns a collection of filters that apply to the flow measure.
112113
*/
113114
[[nodiscard]] virtual auto Filters() const noexcept -> const FlowMeasureFilters& = 0;
115+
116+
// Information about the canonical nature of the flow measure
117+
[[nodiscard]] virtual auto CanonicalInformation() const noexcept -> const CanonicalFlowMeasureInfo& = 0;
114118
};
115119
}// namespace ECFMP::FlowMeasure

0 commit comments

Comments
 (0)