RTC Toolkit 5.0.0
Loading...
Searching...
No Matches
mudpiProcessingError.hpp
Go to the documentation of this file.
1
12#ifndef RTCTK_REUSABLECOMPONENT_TELREPUB_MUDPIPROCESSORERROR_HPP
13#define RTCTK_REUSABLECOMPONENT_TELREPUB_MUDPIPROCESSORERROR_HPP
14
15#include "llnetio/mudpi/mudpi.hpp"
16#include <cstdint>
17#include <optional>
18#include <string>
19#include <system_error>
20#include <variant>
21
22#include <fmt/format.h>
23#include <fmt/ostream.h>
24
25namespace rtctk::telRepub {
26
27template <class ErrorStruct>
28struct ErrorCode {
29 ErrorCode() = default;
30
31 // We want the implicit conversion. The thing stored inside the class is what is being passed
32 // as the argument to the constructor. Therefore it is OK to have the implicit constructor in
33 // this case.
34 // cppcheck-suppress noExplicitConstructor
35 ErrorCode(typename ErrorStruct::VariantType err) : m_error_info(err) {
36 }
37
38 bool HasError() const {
39 return m_error_info.has_value();
40 }
41
42 template <typename E>
43 bool HasError() const {
44 return HasError() and std::holds_alternative<E>(*m_error_info);
45 }
46
47 template <typename E>
48 E GetError() const {
49 if (not HasError<E>()) {
50 throw std::logic_error("bad error access");
51 }
52 return std::get<E>(*m_error_info);
53 }
54
55 std::string What() const {
56 if (not HasError()) {
57 throw std::logic_error("bad error access");
58 }
59 std::string msg;
60 std::visit([&](auto&& arg) { msg = arg.What(); }, *m_error_info);
61 return msg;
62 }
63
64private:
65 std::optional<typename ErrorStruct::VariantType> m_error_info;
66};
67
77 std::string_view dds_topic;
78 llnetio::mudpi::TopicId topic_id;
79 llnetio::mudpi::SampleId sample_id;
80 llnetio::mudpi::FrameId frame_id;
81 llnetio::mudpi::NumFrames num_frames;
82 inline std::string What() const {
83 return fmt::format(
84 "DDS Topic: \"{}\" MUDPI Topic [{}] SampleId: {} FrameId: {:2}. FrameId out of "
85 "range (1..{}).",
91 }
92 };
93
98 std::string_view dds_topic;
99 llnetio::mudpi::TopicId topic_id;
100 llnetio::mudpi::SampleId sample_id;
101 llnetio::mudpi::FrameId frame_id;
102 llnetio::mudpi::SampleId expected_sample_id;
103 inline std::string What() const {
104 return fmt::format(
105 "DDS Topic: \"{}\" MUDPI Topic [{}] SampleId: {} FrameId: {:2} Expected SampleId "
106 "{}. Unexpected SampleId, frame rejected.",
107 dds_topic,
108 topic_id,
109 sample_id,
110 frame_id,
112 }
113 };
114
119 std::string_view dds_topic;
120 llnetio::mudpi::TopicId topic_id;
121 llnetio::mudpi::SampleId sample_id;
122 llnetio::mudpi::FrameId frame_id;
123 llnetio::mudpi::FrameId expected_frame_id;
124 inline std::string What() const {
125 return fmt::format(
126 "DDS Topic: \"{}\" MUDPI Topic [{}] SampleId: {} FrameId: {:2} Expected FrameId "
127 "{:2}. Unexpected FrameId, frame rejected.",
128 dds_topic,
129 topic_id,
130 sample_id,
131 frame_id,
133 }
134 };
135
140 std::string_view dds_topic;
141 llnetio::mudpi::TopicId topic_id;
142 llnetio::mudpi::SampleId sample_id;
143 llnetio::mudpi::FrameId frame_id;
144 inline std::string What() const {
145 return fmt::format(
146 "DDS Topic: \"{}\" MUDPI Topic [{}] SampleId: {} FrameId: {:2}. Synchronising: "
147 "frame rejected.",
148 dds_topic,
149 topic_id,
150 sample_id,
151 frame_id);
152 }
153 };
154
159 std::string_view dds_topic;
160 llnetio::mudpi::TopicId topic_id;
161 llnetio::mudpi::SampleId sample_id;
162 std::error_code error;
163 inline std::string What() const {
164 return fmt::format(
165 "DDS Topic: \"{}\" MUDPI Topic [{}] SampleId: {}. Wrangler Error: {}",
166 dds_topic,
167 topic_id,
168 sample_id,
169 error.message());
170 }
171 };
172
178 std::string_view dds_topic;
179 llnetio::mudpi::TopicId topic_id;
180 llnetio::mudpi::SampleId sample_id;
181 llnetio::mudpi::FrameId frame_id;
184 inline std::string What() const {
185 return fmt::format(
186 "DDS Topic: \"{}\" MUDPI Topic [{}] SampleId: {} FrameId: {:2}. Packet Size "
187 "mismatch: actual size {} expected size {}",
188 dds_topic,
189 topic_id,
190 sample_id,
191 frame_id,
194 }
195 };
196
202 std::string_view dds_topic;
203 llnetio::mudpi::TopicId topic_id;
204 llnetio::mudpi::SampleId sample_id;
205 llnetio::mudpi::FrameId frame_id;
208 inline std::string What() const {
209 return fmt::format(
210 "DDS Topic: \"{}\" MUDPI Topic [{}] SampleId: {} FrameId: {:2}. Wrong MUDPI "
211 "Checksum: {} should be: {}",
212 dds_topic,
213 topic_id,
214 sample_id,
215 frame_id,
218 }
219 };
220
221 using VariantType = std::variant<FrameIdOutOfRange,
228};
229
230} // namespace rtctk::telRepub
231
232#endif // RTCTK_REUSABLECOMPONENT_TELREPUB_MUDPIPROCESSORERROR_HPP
elt::mal::future< std::string > InjectReqRepEvent(StateMachineEngine &engine)
Definition malEventInjector.hpp:23
Definition ddsPubThread.cpp:17
Definition mudpiProcessingError.hpp:28
ErrorCode(typename ErrorStruct::VariantType err)
Definition mudpiProcessingError.hpp:35
bool HasError() const
Definition mudpiProcessingError.hpp:43
E GetError() const
Definition mudpiProcessingError.hpp:48
bool HasError() const
Definition mudpiProcessingError.hpp:38
std::string What() const
Definition mudpiProcessingError.hpp:55
MUDPI Checksum error.
Definition mudpiProcessingError.hpp:201
llnetio::mudpi::TopicId topic_id
Definition mudpiProcessingError.hpp:203
std::string_view dds_topic
Definition mudpiProcessingError.hpp:202
std::string What() const
Definition mudpiProcessingError.hpp:208
llnetio::mudpi::SampleId sample_id
Definition mudpiProcessingError.hpp:204
uint16_t actual_checksum
Definition mudpiProcessingError.hpp:206
llnetio::mudpi::FrameId frame_id
Definition mudpiProcessingError.hpp:205
uint16_t expected_checksum
Definition mudpiProcessingError.hpp:207
FrameId out of range.
Definition mudpiProcessingError.hpp:76
std::string_view dds_topic
Definition mudpiProcessingError.hpp:77
std::string What() const
Definition mudpiProcessingError.hpp:82
llnetio::mudpi::NumFrames num_frames
Definition mudpiProcessingError.hpp:81
llnetio::mudpi::SampleId sample_id
Definition mudpiProcessingError.hpp:79
llnetio::mudpi::FrameId frame_id
Definition mudpiProcessingError.hpp:80
llnetio::mudpi::TopicId topic_id
Definition mudpiProcessingError.hpp:78
(UDP) Packet Size error.
Definition mudpiProcessingError.hpp:177
llnetio::mudpi::SampleId sample_id
Definition mudpiProcessingError.hpp:180
std::string What() const
Definition mudpiProcessingError.hpp:184
llnetio::mudpi::FrameId frame_id
Definition mudpiProcessingError.hpp:181
std::string_view dds_topic
Definition mudpiProcessingError.hpp:178
llnetio::mudpi::TopicId topic_id
Definition mudpiProcessingError.hpp:179
size_t expected_packet_size
Definition mudpiProcessingError.hpp:183
size_t actual_packet_size
Definition mudpiProcessingError.hpp:182
Synchronising.
Definition mudpiProcessingError.hpp:139
std::string What() const
Definition mudpiProcessingError.hpp:144
llnetio::mudpi::FrameId frame_id
Definition mudpiProcessingError.hpp:143
llnetio::mudpi::TopicId topic_id
Definition mudpiProcessingError.hpp:141
std::string_view dds_topic
Definition mudpiProcessingError.hpp:140
llnetio::mudpi::SampleId sample_id
Definition mudpiProcessingError.hpp:142
unexpected frame id inside a sample
Definition mudpiProcessingError.hpp:118
llnetio::mudpi::FrameId frame_id
Definition mudpiProcessingError.hpp:122
std::string_view dds_topic
Definition mudpiProcessingError.hpp:119
llnetio::mudpi::SampleId sample_id
Definition mudpiProcessingError.hpp:121
llnetio::mudpi::TopicId topic_id
Definition mudpiProcessingError.hpp:120
llnetio::mudpi::FrameId expected_frame_id
Definition mudpiProcessingError.hpp:123
std::string What() const
Definition mudpiProcessingError.hpp:124
unexpected sample id, so we need to resynchronize
Definition mudpiProcessingError.hpp:97
llnetio::mudpi::FrameId frame_id
Definition mudpiProcessingError.hpp:101
llnetio::mudpi::SampleId expected_sample_id
Definition mudpiProcessingError.hpp:102
llnetio::mudpi::SampleId sample_id
Definition mudpiProcessingError.hpp:100
std::string_view dds_topic
Definition mudpiProcessingError.hpp:98
llnetio::mudpi::TopicId topic_id
Definition mudpiProcessingError.hpp:99
std::string What() const
Definition mudpiProcessingError.hpp:103
Wrangler Error.
Definition mudpiProcessingError.hpp:158
llnetio::mudpi::TopicId topic_id
Definition mudpiProcessingError.hpp:160
std::string_view dds_topic
Definition mudpiProcessingError.hpp:159
llnetio::mudpi::SampleId sample_id
Definition mudpiProcessingError.hpp:161
std::error_code error
Definition mudpiProcessingError.hpp:162
std::string What() const
Definition mudpiProcessingError.hpp:163
MUDPI Processor errors.
Definition mudpiProcessingError.hpp:72
std::variant< FrameIdOutOfRange, UnexpectedSampleId, UnexpectedFrameId, Synchronising, WranglerError, PacketSizeError, ChecksumError > VariantType
Definition mudpiProcessingError.hpp:221