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