RTC Toolkit 6.0.0
Loading...
Searching...
No Matches
eventDefinitions.hpp
Go to the documentation of this file.
1
11
12#ifndef RTCTK_COMPONENTFRAMEWORK_EVENTDEFINITIONS_HPP
13#define RTCTK_COMPONENTFRAMEWORK_EVENTDEFINITIONS_HPP
14
17
18#include <boost/core/demangle.hpp>
19
20#include <chrono>
21#include <set>
22
24// Suppressing warnings about duplicate ToJson methods. We are not using polymorphism on purpose.
25// cppcheck-suppress-begin duplInheritedMember
26
27template <typename T>
28std::string PrettyTypeName() {
29 return boost::core::demangle((typeid(T).name()));
30}
31
40template <typename EventType>
41bool ConvertibleTo(const JsonPayload& j) {
42 if (j.contains("type")) {
43 if (j.at("type").get<std::set<std::string>>().contains(PrettyTypeName<EventType>())) {
44 return true;
45 }
46 }
47 return false;
48}
49
58template <typename EventType>
59std::optional<EventType> ConvertTo(const JsonPayload& j) {
61 EventType e;
62 from_json(j, e);
63 return e;
64 }
65 return {};
66}
67
69
78 AbstractEvent() = default;
79
80 virtual ~AbstractEvent() = default;
81
82 explicit AbstractEvent(const std::string& origin);
83
84 AbstractEvent(const std::string& origin, const TimeString& time);
85
86 std::string origin; // from which srtc-component does the event come from
87 TimeString time; // when was event created
88};
89
90// The function names below do not follow our conventions. However, these names are required by the
91// nlohmann/json.hpp API. Therefore the linter warnings are being suppressed. This is applicable to
92// all subsequent to_json/from_json functions in this file.
93// NOLINTBEGIN(readability-identifier-naming)
94void to_json(JsonPayload& j, const AbstractEvent& e);
95void from_json(const JsonPayload& j, AbstractEvent& e);
96// NOLINTEND(readability-identifier-naming)
97
99
105 inline static const std::string TOPIC_NAME = "computation_topic";
106
107 ComputationEvent() = default;
108
109 ComputationEvent(const std::string& origin, const std::string& item, const std::string& state);
110
111 ComputationEvent(const std::string& origin, const std::string& item);
112
113 std::string item; // what was computed
114 std::string state; // was computaton started, finished, failed
115};
116
117// NOLINTBEGIN(readability-identifier-naming)
118void to_json(JsonPayload& j, const ComputationEvent& e);
119void from_json(const JsonPayload& j, ComputationEvent& e);
120// NOLINTEND(readability-identifier-naming)
121
123
130
131 ComputationStartedEvent(const std::string& origin, const std::string& item);
132};
133
134// NOLINTBEGIN(readability-identifier-naming)
137// NOLINTEND(readability-identifier-naming)
138
140
147
148 ComputationFinishedEvent(const std::string& origin,
149 const std::string& item,
150 const JsonPayload& result = nullptr);
151
152 JsonPayload result; // result of the computation
153};
154
155// NOLINTBEGIN(readability-identifier-naming)
158// NOLINTEND(readability-identifier-naming)
159
161
167 inline static const std::string TOPIC_NAME = "configuration_topic";
168
176 struct Item {
180 std::string name;
181
185 std::optional<TimeString> timestamp;
186
190 std::optional<uint64_t> sequence_id;
191
192 bool operator==(const Item&) const = default;
193 };
194
195 using ItemList = std::vector<Item>;
196
198
202 ConfigurationEvent(const std::string& origin, const Item& item, const std::string& state);
203
207 ConfigurationEvent(const std::string& origin, const ItemList& item, const std::string& state);
208
212 ConfigurationEvent(const std::string& origin,
213 const std::string& item,
214 const std::string& state);
215
219 ConfigurationEvent(const std::string& origin,
220 const std::vector<std::string>& items,
221 const std::string& state);
222
223 ItemList items; // what was configured
224 std::string state; // was configuration scheduled, started, finished, failed
225};
226
227// NOLINTBEGIN(readability-identifier-naming)
228void to_json(JsonPayload& j, const ConfigurationEvent& e);
229void from_json(const JsonPayload& j, ConfigurationEvent& e);
230// NOLINTEND(readability-identifier-naming)
231
233
240
244 ConfigurationUpdatedEvent(const std::string& origin, const Item& item);
245
249 ConfigurationUpdatedEvent(const std::string& origin, const ItemList& items);
250
254 ConfigurationUpdatedEvent(const std::string& origin, const std::string& item);
255
259 ConfigurationUpdatedEvent(const std::string& origin, const std::vector<std::string>& items);
260};
261
262// NOLINTBEGIN(readability-identifier-naming)
265// NOLINTEND(readability-identifier-naming)
266
268
275
279 ConfigurationRetrievedEvent(const std::string& origin, const Item& item);
280
284 ConfigurationRetrievedEvent(const std::string& origin, const ItemList& items);
285
289 ConfigurationRetrievedEvent(const std::string& origin, const std::string& item);
290
294 ConfigurationRetrievedEvent(const std::string& origin, const std::vector<std::string>& items);
295};
296
297// NOLINTBEGIN(readability-identifier-naming)
300// NOLINTEND(readability-identifier-naming)
301
303
310 // cppcheck-suppress uninitMemberVar
312
316 HrtcConfigurationScheduledEvent(const std::string& origin,
317 const Item& item,
318 const std::string& hrtc_origin,
320 uint64_t hrtc_sample_id);
321
325 HrtcConfigurationScheduledEvent(const std::string& origin,
326 const ItemList& items,
327 const std::string& hrtc_origin,
329 uint64_t hrtc_sample_id);
330
331 std::string hrtc_origin; // from which hrtc instance, or functional unit within instance
332 TimeString hrtc_timestamp; // scheduled to be applied at which timestamp
333 uint64_t hrtc_sample_id; // scheduled to be applied at which sample_id
334};
335
336// NOLINTBEGIN(readability-identifier-naming)
339// NOLINTEND(readability-identifier-naming)
340
342
348 // cppcheck-suppress uninitMemberVar
350
354 HrtcConfigurationAppliedEvent(const std::string& origin,
355 const Item& item,
356 const std::string& hrtc_origin,
358 uint64_t hrtc_sample_id);
359
363 HrtcConfigurationAppliedEvent(const std::string& origin,
364 const ItemList& items,
365 const std::string& hrtc_origin,
367 uint64_t hrtc_sample_id);
368
369 std::string hrtc_origin; // from which hrtc instance, or functional unit within instance
370 TimeString hrtc_timestamp; // applied at which timestamp
371 uint64_t hrtc_sample_id; // applied at which sample_id
372};
373
374// NOLINTBEGIN(readability-identifier-naming)
377// NOLINTEND(readability-identifier-naming)
378
380
386 inline static const std::string TOPIC_NAME = "coordination_topic";
387
388 CoordinationEvent() = default;
389
390 explicit CoordinationEvent(const std::string& origin);
391};
392
393// NOLINTBEGIN(readability-identifier-naming)
394void to_json(JsonPayload& j, const CoordinationEvent& e);
395void from_json(const JsonPayload& j, CoordinationEvent& e);
396// NOLINTEND(readability-identifier-naming)
397
399
405 StateChangedEvent() = default;
406
407 StateChangedEvent(const std::string& origin,
408 const std::string& entity,
409 const std::string& state);
410
411 StateChangedEvent(const std::string& origin, const std::string& state);
412
413 std::string entity; // name of the functional entity that changed its state
414 std::string state; // the actual state
415};
416
417// NOLINTBEGIN(readability-identifier-naming)
418void to_json(JsonPayload& j, const StateChangedEvent& e);
419void from_json(const JsonPayload& j, StateChangedEvent& e);
420// NOLINTEND(readability-identifier-naming)
421
423
429 // cppcheck-suppress uninitMemberVar
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 // cppcheck-suppress uninitMemberVar
459 AlertStatusEvent() = default;
460
461 // cppcheck-suppress unusedStructMember
462 inline static const std::string TOPIC_NAME = "alert_status_topic";
463
470 struct Alert {
474 std::string origin;
475
479 std::string id;
480
484 std::string description;
485
490 };
491
495 AlertStatusEvent(bool st, std::vector<Alert> ac, const std::string& origin);
496
500 bool status;
501
505 std::vector<Alert> active_alerts;
506};
507
508// NOLINTBEGIN(readability-identifier-naming)
509void to_json(JsonPayload& j, const AlertStatusEvent& e);
510void from_json(const JsonPayload& j, AlertStatusEvent& e);
511// NOLINTEND(readability-identifier-naming)
512
513// cppcheck-suppress-end duplInheritedMember
514} // namespace rtctk::componentFramework
515
516#endif // RTCTK_COMPONENTFRAMEWORK_EVENTDEFINITIONS_HPP
Defines the JSON payload type JsonPayload.
Definition commandReplier.cpp:21
std::optional< EventType > ConvertTo(const JsonPayload &j)
Helper to convert to certain EventType if possible.
Definition eventDefinitions.hpp:59
bool ConvertibleTo(const JsonPayload &j)
Helper to check if JsonPayload is convertible to a certain EventType.
Definition eventDefinitions.hpp:41
void to_json(JsonPayload &j, const DataPointPath &v)
Definition dataPointPath.cpp:217
nlohmann::json JsonPayload
Type requirements:
Definition jsonPayload.hpp:24
void from_json(const JsonPayload &j, DataPointPath &v)
Definition dataPointPath.cpp:222
std::string PrettyTypeName()
Definition eventDefinitions.hpp:28
Abstract Event Type that is used as a base for all events.
Definition eventDefinitions.hpp:77
TimeString time
Definition eventDefinitions.hpp:87
std::string origin
Definition eventDefinitions.hpp:86
Represents an active alert originating from a component instance.
Definition eventDefinitions.hpp:470
std::string origin
Component instance origin.
Definition eventDefinitions.hpp:474
TimeString since
Timestamp when alert was first made active.
Definition eventDefinitions.hpp:489
std::string id
Alert identifier which is unique to the origin.
Definition eventDefinitions.hpp:479
std::string description
Description of alert.
Definition eventDefinitions.hpp:484
Event published when alert status is changed.
Definition eventDefinitions.hpp:457
static const std::string TOPIC_NAME
Definition eventDefinitions.hpp:462
bool status
Reduced alert status.
Definition eventDefinitions.hpp:500
std::vector< Alert > active_alerts
List of active alerts.
Definition eventDefinitions.hpp:505
Abstract Event Type that is used as a base for computation events.
Definition eventDefinitions.hpp:104
std::string item
Definition eventDefinitions.hpp:113
std::string state
Definition eventDefinitions.hpp:114
static const std::string TOPIC_NAME
Definition eventDefinitions.hpp:105
Event Type used to signal that a computation has finished.
Definition eventDefinitions.hpp:145
JsonPayload result
Definition eventDefinitions.hpp:152
Event Type used to signal that a computation has started.
Definition eventDefinitions.hpp:128
Represents a single configuration item.
Definition eventDefinitions.hpp:176
bool operator==(const Item &) const =default
std::string name
PathName of the configuration item.
Definition eventDefinitions.hpp:180
std::optional< TimeString > timestamp
(Optional) Timestamp of the configuration item.
Definition eventDefinitions.hpp:185
std::optional< uint64_t > sequence_id
(Optional) SequenceId of the configuration item.
Definition eventDefinitions.hpp:190
Abstract Event Type that is used as a base for configuration events.
Definition eventDefinitions.hpp:166
static const std::string TOPIC_NAME
Definition eventDefinitions.hpp:167
std::vector< Item > ItemList
Definition eventDefinitions.hpp:195
std::string state
Definition eventDefinitions.hpp:224
ItemList items
Definition eventDefinitions.hpp:223
Event Type used to signal that configuration data items were retrieved from RTR.
Definition eventDefinitions.hpp:273
Event Type used to signal that configuration data items were updated in RTR.
Definition eventDefinitions.hpp:238
Abstract Event Type that is used as a base for coordination events.
Definition eventDefinitions.hpp:385
static const std::string TOPIC_NAME
Definition eventDefinitions.hpp:386
Event Type used to signal that configuration data items were applied in HRTC.
Definition eventDefinitions.hpp:347
uint64_t hrtc_sample_id
Definition eventDefinitions.hpp:371
TimeString hrtc_timestamp
Definition eventDefinitions.hpp:370
std::string hrtc_origin
Definition eventDefinitions.hpp:369
Event Type used to signal that configuration data items were scheduled to be applied in HRTC.
Definition eventDefinitions.hpp:309
uint64_t hrtc_sample_id
Definition eventDefinitions.hpp:333
TimeString hrtc_timestamp
Definition eventDefinitions.hpp:332
std::string hrtc_origin
Definition eventDefinitions.hpp:331
Event Type used to signal that some entity in HRTC changed its state.
Definition eventDefinitions.hpp:428
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:404
std::string entity
Definition eventDefinitions.hpp:413
std::string state
Definition eventDefinitions.hpp:414
Represents an ISO 8601 time string in format: YYYY-MM-DDThh:mm:ss.sssZ.
Definition timeString.hpp:27
A timestring in ISO-8601 format.