RTC Toolkit 6.0.0-pre2
Loading...
Searching...
No Matches
eventDefinitions.hpp
Go to the documentation of this file.
1
12
13#ifndef RTCTK_COMPONENTFRAMEWORK_EVENTDEFINITIONS_HPP
14#define RTCTK_COMPONENTFRAMEWORK_EVENTDEFINITIONS_HPP
15
18
19#include <boost/core/demangle.hpp>
20
21#include <chrono>
22#include <set>
23
25// Suppressing warnings about duplicate ToJson methods. We are not using polymorphism on purpose.
26// cppcheck-suppress-begin duplInheritedMember
27
28template <typename T>
29std::string PrettyTypeName() {
30 return boost::core::demangle((typeid(T).name()));
31}
32
41template <typename EventType>
42bool ConvertibleTo(const JsonPayload& j) {
43 if (j.contains("type")) {
44 if (j.at("type").get<std::set<std::string>>().contains(PrettyTypeName<EventType>())) {
45 return true;
46 }
47 }
48 return false;
49}
50
59template <typename EventType>
60std::optional<EventType> ConvertTo(const JsonPayload& j) {
62 EventType e;
63 from_json(j, e);
64 return e;
65 }
66 return {};
67}
68
70
79 AbstractEvent() = default;
80
81 virtual ~AbstractEvent() = default;
82
83 explicit AbstractEvent(const std::string& origin);
84
85 AbstractEvent(const std::string& origin, const TimeString& time);
86
87 std::string origin; // from which srtc-component does the event come from
88 TimeString time; // when was event created
89};
90
91// The function names below do not follow our conventions. However, these names are required by the
92// nlohmann/json.hpp API. Therefore the linter warnings are being suppressed. This is applicable to
93// all subsequent to_json/from_json functions in this file.
94// NOLINTBEGIN(readability-identifier-naming)
95void to_json(JsonPayload& j, const AbstractEvent& e);
96void from_json(const JsonPayload& j, AbstractEvent& e);
97// NOLINTEND(readability-identifier-naming)
98
100
106 inline static const std::string TOPIC_NAME = "computation_topic";
107
108 ComputationEvent() = default;
109
110 ComputationEvent(const std::string& origin, const std::string& item, const std::string& state);
111
112 ComputationEvent(const std::string& origin, const std::string& item);
113
114 std::string item; // what was computed
115 std::string state; // was computaton started, finished, failed
116};
117
118// NOLINTBEGIN(readability-identifier-naming)
119void to_json(JsonPayload& j, const ComputationEvent& e);
120void from_json(const JsonPayload& j, ComputationEvent& e);
121// NOLINTEND(readability-identifier-naming)
122
124
131
132 ComputationStartedEvent(const std::string& origin, const std::string& item);
133};
134
135// NOLINTBEGIN(readability-identifier-naming)
138// NOLINTEND(readability-identifier-naming)
139
141
148
149 ComputationFinishedEvent(const std::string& origin,
150 const std::string& item,
151 const JsonPayload& result = nullptr);
152
153 JsonPayload result; // result of the computation
154};
155
156// NOLINTBEGIN(readability-identifier-naming)
159// NOLINTEND(readability-identifier-naming)
160
162
168 inline static const std::string TOPIC_NAME = "configuration_topic";
169
177 struct Item {
181 std::string name;
182
186 std::optional<TimeString> timestamp;
187
191 std::optional<uint64_t> sequence_id;
192
193 bool operator==(const Item&) const = default;
194 };
195
196 using ItemList = std::vector<Item>;
197
199
203 ConfigurationEvent(const std::string& origin, const Item& item, const std::string& state);
204
208 ConfigurationEvent(const std::string& origin,
209 const ItemList& item,
210 const std::string& state);
211
215 ConfigurationEvent(const std::string& origin,
216 const std::string& item,
217 const std::string& state);
218
222 ConfigurationEvent(const std::string& origin,
223 const std::vector<std::string>& items,
224 const std::string& state);
225
226 ItemList items; // what was configured
227 std::string state; // was configuration scheduled, started, finished, failed
228};
229
230// NOLINTBEGIN(readability-identifier-naming)
231void to_json(JsonPayload& j, const ConfigurationEvent& e);
232void from_json(const JsonPayload& j, ConfigurationEvent& e);
233// NOLINTEND(readability-identifier-naming)
234
236
243
247 ConfigurationUpdatedEvent(const std::string& origin, const Item& item);
248
252 ConfigurationUpdatedEvent(const std::string& origin, const ItemList& items);
253
257 ConfigurationUpdatedEvent(const std::string& origin, const std::string& item);
258
262 ConfigurationUpdatedEvent(const std::string& origin, const std::vector<std::string>& items);
263};
264
265// NOLINTBEGIN(readability-identifier-naming)
268// NOLINTEND(readability-identifier-naming)
269
271
278
282 ConfigurationRetrievedEvent(const std::string& origin, const Item& item);
283
287 ConfigurationRetrievedEvent(const std::string& origin, const ItemList& items);
288
292 ConfigurationRetrievedEvent(const std::string& origin, const std::string& item);
293
297 ConfigurationRetrievedEvent(const std::string& origin, const std::vector<std::string>& items);
298};
299
300// NOLINTBEGIN(readability-identifier-naming)
303// NOLINTEND(readability-identifier-naming)
304
306
314
318 HrtcConfigurationScheduledEvent(const std::string& origin,
319 const Item& item,
320 const std::string& hrtc_origin,
322 uint64_t hrtc_sample_id);
323
327 HrtcConfigurationScheduledEvent(const std::string& origin,
328 const ItemList& items,
329 const std::string& hrtc_origin,
331 uint64_t hrtc_sample_id);
332
333 std::string hrtc_origin; // from which hrtc instance, or functional unit within instance
334 TimeString hrtc_timestamp; // scheduled to be applied at which timestamp
335 uint64_t hrtc_sample_id; // scheduled to be applied at which sample_id
336};
337
338// NOLINTBEGIN(readability-identifier-naming)
341// NOLINTEND(readability-identifier-naming)
342
344
351
355 HrtcConfigurationAppliedEvent(const std::string& origin,
356 const Item& item,
357 const std::string& hrtc_origin,
359 uint64_t hrtc_sample_id);
360
364 HrtcConfigurationAppliedEvent(const std::string& origin,
365 const ItemList& items,
366 const std::string& hrtc_origin,
368 uint64_t hrtc_sample_id);
369
370 std::string hrtc_origin; // from which hrtc instance, or functional unit within instance
371 TimeString hrtc_timestamp; // applied at which timestamp
372 uint64_t hrtc_sample_id; // applied at which sample_id
373};
374
375// NOLINTBEGIN(readability-identifier-naming)
378// NOLINTEND(readability-identifier-naming)
379
381
387 inline static const std::string TOPIC_NAME = "coordination_topic";
388
389 CoordinationEvent() = default;
390
391 explicit CoordinationEvent(const std::string& origin);
392};
393
394// NOLINTBEGIN(readability-identifier-naming)
395void to_json(JsonPayload& j, const CoordinationEvent& e);
396void from_json(const JsonPayload& j, CoordinationEvent& e);
397// NOLINTEND(readability-identifier-naming)
398
400
406 StateChangedEvent() = default;
407
408 StateChangedEvent(const std::string& origin,
409 const std::string& entity,
410 const std::string& state);
411
412 StateChangedEvent(const std::string& origin, const std::string& state);
413
414 std::string entity; // name of the functional entity that changed its state
415 std::string state; // the actual state
416};
417
418// NOLINTBEGIN(readability-identifier-naming)
419void to_json(JsonPayload& j, const StateChangedEvent& e);
420void from_json(const JsonPayload& j, StateChangedEvent& e);
421// NOLINTEND(readability-identifier-naming)
422
424
431
432 HrtcStateChangedEvent(const std::string& origin,
433 const std::string& hrtc_entity,
434 const std::string& hrtc_state,
436 uint64_t hrtc_sample_id);
437
438 TimeString hrtc_timestamp; // when did the state change
439 uint64_t hrtc_sample_id; // at which sample_id did the state change
440};
441
442// NOLINTBEGIN(readability-identifier-naming)
443void to_json(JsonPayload& j, const HrtcStateChangedEvent& e);
445// NOLINTEND(readability-identifier-naming)
446
448
458 AlertStatusEvent() = default;
459
460 // cppcheck-suppress unusedStructMember
461 inline static const std::string TOPIC_NAME = "alert_status_topic";
462
469 struct Alert {
473 std::string origin;
474
478 std::string id;
479
483 std::string description;
484
489 };
490
494 AlertStatusEvent(bool st, std::vector<Alert> ac, const std::string& origin);
495
499 bool status;
500
504 std::vector<Alert> active_alerts;
505};
506
507// NOLINTBEGIN(readability-identifier-naming)
508void to_json(JsonPayload& j, const AlertStatusEvent& e);
509void from_json(const JsonPayload& j, AlertStatusEvent& e);
510// NOLINTEND(readability-identifier-naming)
511
512// cppcheck-suppress-end duplInheritedMember
513} // namespace rtctk::componentFramework
514
515#endif // RTCTK_COMPONENTFRAMEWORK_EVENTDEFINITIONS_HPP
Defines the JSON payload type JsonPayload.
Definition commandReplier.cpp:22
std::optional< EventType > ConvertTo(const JsonPayload &j)
Helper to convert to certain EventType if possible.
Definition eventDefinitions.hpp:60
bool ConvertibleTo(const JsonPayload &j)
Helper to check if JsonPayload is convertible to a certain EventType.
Definition eventDefinitions.hpp:42
void to_json(JsonPayload &j, const DataPointPath &v)
Definition dataPointPath.cpp:218
nlohmann::json JsonPayload
Type requirements:
Definition jsonPayload.hpp:25
void from_json(const JsonPayload &j, DataPointPath &v)
Definition dataPointPath.cpp:223
std::string PrettyTypeName()
Definition eventDefinitions.hpp:29
Abstract Event Type that is used as a base for all events.
Definition eventDefinitions.hpp:78
TimeString time
Definition eventDefinitions.hpp:88
std::string origin
Definition eventDefinitions.hpp:87
Represents an active alert originating from a component instance.
Definition eventDefinitions.hpp:469
std::string origin
Component instance origin.
Definition eventDefinitions.hpp:473
TimeString since
Timestamp when alert was first made active.
Definition eventDefinitions.hpp:488
std::string id
Alert identifier which is unique to the origin.
Definition eventDefinitions.hpp:478
std::string description
Description of alert.
Definition eventDefinitions.hpp:483
Event published when alert status is changed.
Definition eventDefinitions.hpp:457
static const std::string TOPIC_NAME
Definition eventDefinitions.hpp:461
bool status
Reduced alert status.
Definition eventDefinitions.hpp:499
std::vector< Alert > active_alerts
List of active alerts.
Definition eventDefinitions.hpp:504
Abstract Event Type that is used as a base for computation events.
Definition eventDefinitions.hpp:105
std::string item
Definition eventDefinitions.hpp:114
std::string state
Definition eventDefinitions.hpp:115
static const std::string TOPIC_NAME
Definition eventDefinitions.hpp:106
Event Type used to signal that a computation has finished.
Definition eventDefinitions.hpp:146
JsonPayload result
Definition eventDefinitions.hpp:153
Event Type used to signal that a computation has started.
Definition eventDefinitions.hpp:129
Represents a single configuration item.
Definition eventDefinitions.hpp:177
bool operator==(const Item &) const =default
std::string name
PathName of the configuration item.
Definition eventDefinitions.hpp:181
std::optional< TimeString > timestamp
(Optional) Timestamp of the configuration item.
Definition eventDefinitions.hpp:186
std::optional< uint64_t > sequence_id
(Optional) SequenceId of the configuration item.
Definition eventDefinitions.hpp:191
Abstract Event Type that is used as a base for configuration events.
Definition eventDefinitions.hpp:167
static const std::string TOPIC_NAME
Definition eventDefinitions.hpp:168
std::vector< Item > ItemList
Definition eventDefinitions.hpp:196
std::string state
Definition eventDefinitions.hpp:227
ItemList items
Definition eventDefinitions.hpp:226
Event Type used to signal that configuration data items were retrieved from RTR.
Definition eventDefinitions.hpp:276
Event Type used to signal that configuration data items were updated in RTR.
Definition eventDefinitions.hpp:241
Abstract Event Type that is used as a base for coordination events.
Definition eventDefinitions.hpp:386
static const std::string TOPIC_NAME
Definition eventDefinitions.hpp:387
Event Type used to signal that configuration data items were applied in HRTC.
Definition eventDefinitions.hpp:349
uint64_t hrtc_sample_id
Definition eventDefinitions.hpp:372
TimeString hrtc_timestamp
Definition eventDefinitions.hpp:371
std::string hrtc_origin
Definition eventDefinitions.hpp:370
Event Type used to signal that configuration data items were scheduled to be applied in HRTC.
Definition eventDefinitions.hpp:312
uint64_t hrtc_sample_id
Definition eventDefinitions.hpp:335
TimeString hrtc_timestamp
Definition eventDefinitions.hpp:334
std::string hrtc_origin
Definition eventDefinitions.hpp:333
Event Type used to signal that some entity in HRTC changed its state.
Definition eventDefinitions.hpp:429
TimeString hrtc_timestamp
Definition eventDefinitions.hpp:438
uint64_t hrtc_sample_id
Definition eventDefinitions.hpp:439
Event Type used to signal that some entity changed its state.
Definition eventDefinitions.hpp:405
std::string entity
Definition eventDefinitions.hpp:414
std::string state
Definition eventDefinitions.hpp:415
Represents an ISO 8601 time string in format: YYYY-MM-DDThh:mm:ss.sssZ.
Definition timeString.hpp:28
A timestring in ISO-8601 format.