UniRec 3.3.2
Loading...
Searching...
No Matches
bidirectionalInterface.cpp
Go to the documentation of this file.
1
11
12#include <libtrap/trap.h>
13
14namespace Nemea {
15
19 : m_template(nullptr)
20 , m_inputInterfaceID(inputInterfaceID)
21 , m_outputInterfaceID(outputInterfaceID)
22 , m_sequenceNumber(0)
23 , m_prioritizedDataPointer(nullptr)
24 , m_sendEoFonExit(true)
25 , m_isInitialized(false)
26{
28}
29
38
66
68{
69 if (errorCode == TRAP_E_OK) {
70 return;
71 }
73 throw std::runtime_error(
74 "UnirecBidirectionalInterface::receive() has failed. Trap interface is not "
75 "initialized.");
76 }
78 throw std::runtime_error(
79 "UnirecBidirectionalInterface::receive() has failed. Trap interface is terminated.");
80 }
82 throw std::runtime_error(
83 "UnirecBidirectionalInterface::receive() has failed. Interface ID out of range.");
84 }
85 throw std::runtime_error(
86 "UnirecBidirectionalInterface::receive() has failed. Return code: "
87 + std::to_string(errorCode) + ", msg: " + trap_last_error_msg);
88}
89
91{
93 if (ret != TRAP_E_OK) {
94 throw std::runtime_error(
95 "UnirecBidirectionalInterface::setRequieredFormat() has failed. Unable to set required "
96 "format.");
97 }
98
99 if (templateSpecification.empty()) {
100 return;
101 }
102
104}
105
107{
109 if (m_template == nullptr) {
110 throw std::runtime_error(
111 "UnirecBidirectionalInterface::changeTemplate() has failed. Template could not be "
112 "edited.");
113 }
114
116
118 if (ret != TRAP_E_OK) {
119 throw std::runtime_error("UnirecBidirectionalInterface::changeTemplate() has failed.");
120 }
121
123 if (ret != TRAP_E_OK) {
124 throw std::runtime_error("UnirecBidirectionalInterface::changeTemplate() has failed.");
125 }
126
128
129 m_isInitialized = true;
130}
131
133{
135 const char* spec = nullptr;
136
138 if (ret != TRAP_E_OK) {
139 throw std::runtime_error(
140 "UnirecBidirectionalInterface::changeTemplate() has failed. Data format was not "
141 "loaded.");
142 }
143
145}
146
151
156
162
169
171{
172 if (errorCode == TRAP_E_TIMEOUT) {
173 return false;
174 }
175 if (errorCode == TRAP_E_OK) {
176 return true;
177 }
179 throw std::runtime_error(
180 "UnirecBidirectionalInterface::send() has failed. Trap interface is not initialized.");
181 }
183 throw std::runtime_error(
184 "UnirecBidirectionalInterface::send() has failed. Trap interface is terminated.");
185 }
187 throw std::runtime_error(
188 "UnirecBidirectionalInterface::send() has failed. Interface ID out of range.");
189 }
190 throw std::runtime_error(
191 "UnirecBidirectionalInterface::send() has failed. Return code: " + std::to_string(errorCode)
192 + ", msg: " + trap_last_error_msg);
193}
194
199
204
209
214
216{
217 char dummy[1] = { 0 };
219}
220
222{
224
225 struct input_ifc_stats ifcStats = {};
227
228 inputStats.receivedBytes = ifcStats.received_bytes;
229 inputStats.receivedRecords = ifcStats.received_records;
230 inputStats.missedRecords = ifcStats.missed_records;
231 return inputStats;
232}
233
234} // namespace Nemea
Defines a bidirectional interface for sending and receiving unirec records using the TRAP interface p...
An exception that is thrown when the end of the input stream is reached.
An exception that is thrown when the record format changes.
void setSendAutoflushTimeout(int timeout)
Sets the autoflush timeout for the output Trap interface.
~UnirecBidirectionalInterface()
Destructor for the UnirecBidirectionalInterface class.
void handleReceiveErrorCodes(int errorCode) const
void sendFlush() const
Flushes any pending UniRec records in the Trap interface.
void changeTemplate()
Changes the Unirec template used by the bidirectional interface.
void changeInternalTemplate(const std::string &templateSpecification)
InputInteraceStats getInputInterfaceStats() const
Gets the statistics for the input interface.
void setReceiveTimeout(int timeout)
Sets the receive timeout for the interface. This method sets the timeout for receiving UniRec records...
UnirecRecord createUnirecRecord(size_t maxVariableFieldsSize=UR_MAX_SIZE)
Creates a new UniRec record with the specified maximum variable fields size.
void doNotsendEoFOnExit()
Disables sending an end-of-file marker on exit.
void setSendTimeout(int timeout)
Sets the send timeout for the Trap interface.
std::optional< UnirecRecordView > receive()
Receives data from the interface and returns an optional UnirecRecordView object.
void setRequieredFormat(const std::string &templateSpecification)
Sets the required Unirec format specification.
bool send(UnirecRecord &unirecRecord) const
Sends a UniRec record through the Trap interface.
UnirecBidirectionalInterface(uint8_t inputInterfaceID, uint8_t outputInterfaceID)
Provides a view into a UniRec record.
A class for working with UniRec records and their fields.
ur_template_t * ur_define_fields_and_update_template(const char *ifc_data_fmt, ur_template_t *tmplt)
Defined new fields and expand an UniRec template Define new fields (function ur_define_set_of_fields)...
Definition unirec.c:616
#define ur_set_output_template(ifc, tmplt)
Set UniRec template to ouput interface.
Definition unirec.h:847
void ur_free_template(ur_template_t *tmplt)
Destroy UniRec template Free all memory allocated for a template created previously by ur_create_temp...
Definition unirec.c:1094
#define ur_set_input_template(ifc, tmplt)
Set UniRec template to input interface.
Definition unirec.h:863
constexpr ur_field_type_t getExpectedUnirecType()
Determines the expected UniRec field type for a given C++ type T.
Structure to store statistics related to an input interface.