UniRec 3.0.0
|
A class that provides a bidirectional interface for sending and receiving unirec records. More...
#include <bidirectionalInterface.hpp>
Public Member Functions | |
std::optional< UnirecRecordView > | receive () |
Receives data from the interface and returns an optional UnirecRecordView object. | |
bool | send (UnirecRecord &unirecRecord) const |
Sends a UniRec record through the Trap interface. | |
bool | send (UnirecRecordView &unirecRecordView) const |
Sends a UniRec record view through the Trap interface. | |
void | sendFlush () const |
Flushes any pending UniRec records in the Trap interface. | |
void | changeTemplate () |
Changes the Unirec template used by the bidirectional interface. | |
void | setRequieredFormat (const std::string &templateSpecification) |
Sets the required Unirec format specification. | |
void | setReceiveTimeout (int timeout) |
Sets the receive timeout for the interface. This method sets the timeout for receiving UniRec records on the interface. If no record is received within the specified timeout, the receive method returns an empty optional. | |
void | setSendTimeout (int timeout) |
Sets the send timeout for the Trap interface. | |
void | setSendAutoflushTimeout (int timeout) |
Sets the autoflush timeout for the output Trap interface. | |
void | doNotsendEoFOnExit () |
Disables sending an end-of-file marker on exit. | |
ur_template_t * | getTemplate () const noexcept |
Gets the Unirec template used by the bidirectional interface. | |
~UnirecBidirectionalInterface () | |
Destructor for the UnirecBidirectionalInterface class. | |
UnirecRecord & | getUnirecRecord () noexcept |
Gets a reference to the pre-allocated UniRec record for efficient use. | |
UnirecRecord | createUnirecRecord (size_t maxVariableFieldsSize=UR_MAX_SIZE) |
Creates a new UniRec record with the specified maximum variable fields size. | |
Private Member Functions | |
UnirecBidirectionalInterface (uint8_t inputInterfaceID, uint8_t outputInterfaceID) | |
void | handleReceiveErrorCodes (int errorCode) const |
bool | handleSendErrorCodes (int errorCode) const |
bool | isEoFReceived () const noexcept |
void | sendEoF () const |
Private Attributes | |
ur_template_t * | m_template |
uint8_t | m_inputInterfaceID |
uint8_t | m_outputInterfaceID |
const void * | m_prioritizedDataPointer |
bool | m_sendEoFonExit |
bool | m_EoFOnNextReceive |
UnirecRecord | m_unirecRecord |
Friends | |
class | Unirec |
A class that provides a bidirectional interface for sending and receiving unirec records.
This class wraps the TRAP interface provided by the UniRec library to provide a simple and easy-to-use bidirectional interface for sending and receiving unirec records with the SAME FORMAT.
Definition at line 33 of file bidirectionalInterface.hpp.
NemeaPlusPlus::UnirecBidirectionalInterface::~UnirecBidirectionalInterface | ( | ) |
Destructor for the UnirecBidirectionalInterface class.
Sends an end-of-file marker if m_sendEoFonExit is true, then frees the memory allocated for the UniRec template.
Definition at line 16 of file bidirectionalInterface.cpp.
|
private |
Definition at line 25 of file bidirectionalInterface.cpp.
void NemeaPlusPlus::UnirecBidirectionalInterface::changeTemplate | ( | ) |
Changes the Unirec template used by the bidirectional interface.
This method should be called every time when the FormatChangeException is thrown.
This method changes the UniRec record template used for decoding records received on the interface.
std::runtime_error | if the data format was not loaded or the template could not be edited. |
Definition at line 114 of file bidirectionalInterface.cpp.
UnirecRecord NemeaPlusPlus::UnirecBidirectionalInterface::createUnirecRecord | ( | size_t | maxVariableFieldsSize = UR_MAX_SIZE | ) |
Creates a new UniRec record with the specified maximum variable fields size.
This function generates a fresh UniRec record instance, ready to be populated with data before sending it through the TRAP interface. The maximum size of variable fields can be specified to suit your data insertion needs. Unlike using the pre-allocated record with the getUnirecRecord
function, this function involves memory allocation and may have a slightly higher overhead.
maxVariableFieldsSize | The maximum size for variable fields in the new UniRec record. |
Definition at line 149 of file bidirectionalInterface.cpp.
void NemeaPlusPlus::UnirecBidirectionalInterface::doNotsendEoFOnExit | ( | ) |
Disables sending an end-of-file marker on exit.
Definition at line 197 of file bidirectionalInterface.cpp.
|
inlinenoexcept |
Gets the Unirec template used by the bidirectional interface.
This method returns a pointer to the Unirec template used by the bidirectional interface.
Definition at line 140 of file bidirectionalInterface.hpp.
|
inlinenoexcept |
Gets a reference to the pre-allocated UniRec record for efficient use.
This function provides access to the UniRec record instance that has already been pre-allocated within the UnirecOutputInterface. It allows direct modification of the record's fields before sending it through the TRAP interface. Using the pre-allocated record can be faster compared to creating a new record, as there is no memory allocation involved. However, please note that using the same record in a multithreaded context may not be thread-safe.
Definition at line 165 of file bidirectionalInterface.hpp.
|
private |
Definition at line 75 of file bidirectionalInterface.cpp.
|
private |
Definition at line 167 of file bidirectionalInterface.cpp.
|
privatenoexcept |
Definition at line 70 of file bidirectionalInterface.cpp.
std::optional< UnirecRecordView > NemeaPlusPlus::UnirecBidirectionalInterface::receive | ( | ) |
Receives data from the interface and returns an optional UnirecRecordView object.
If data is received successfully, an UnirecRecordView object is returned that provides a view into the received data. If no data is available or a timeout occurs, std::nullopt is returned.
EoFException | if the end of the input stream is reached. |
FormatChangeException | if the record format changes. |
Definition at line 38 of file bidirectionalInterface.cpp.
bool NemeaPlusPlus::UnirecBidirectionalInterface::send | ( | UnirecRecord & | unirecRecord | ) | const |
Sends a UniRec record through the Trap interface.
unirecRecord | the Unirec record to send |
std::runtime_error | if an error occurs while sending the record |
Definition at line 154 of file bidirectionalInterface.cpp.
bool NemeaPlusPlus::UnirecBidirectionalInterface::send | ( | UnirecRecordView & | unirecRecordView | ) | const |
Sends a UniRec record view through the Trap interface.
unirecRecordView | The UniRec record view to send. |
std::runtime_error | if an error occurs while sending the record |
Definition at line 160 of file bidirectionalInterface.cpp.
|
private |
Definition at line 212 of file bidirectionalInterface.cpp.
void NemeaPlusPlus::UnirecBidirectionalInterface::sendFlush | ( | ) | const |
Flushes any pending UniRec records in the Trap interface.
Definition at line 192 of file bidirectionalInterface.cpp.
void NemeaPlusPlus::UnirecBidirectionalInterface::setReceiveTimeout | ( | int | timeout | ) |
Sets the receive timeout for the interface. This method sets the timeout for receiving UniRec records on the interface. If no record is received within the specified timeout, the receive method returns an empty optional.
timeout | The timeout value in microseconds.
|
Definition at line 109 of file bidirectionalInterface.cpp.
void NemeaPlusPlus::UnirecBidirectionalInterface::setRequieredFormat | ( | const std::string & | templateSpecification | ) |
Sets the required Unirec format specification.
This method sets the required Unirec format specification for the input interface. Format: "uint64 BYTES, string SNI" (unirecDataType NAME)
templateSpecification | The required Unirec format specification. |
std::runtime_error | if the required format could not be set. |
Definition at line 98 of file bidirectionalInterface.cpp.
void NemeaPlusPlus::UnirecBidirectionalInterface::setSendAutoflushTimeout | ( | int | timeout | ) |
Sets the autoflush timeout for the output Trap interface.
timeout | The timeout value in microseconds.
|
Definition at line 207 of file bidirectionalInterface.cpp.
void NemeaPlusPlus::UnirecBidirectionalInterface::setSendTimeout | ( | int | timeout | ) |
Sets the send timeout for the Trap interface.
timeout | The timeout value in microseconds.
|
Definition at line 202 of file bidirectionalInterface.cpp.
|
friend |
Definition at line 196 of file bidirectionalInterface.hpp.
|
private |
Definition at line 193 of file bidirectionalInterface.hpp.
|
private |
Definition at line 189 of file bidirectionalInterface.hpp.
|
private |
Definition at line 190 of file bidirectionalInterface.hpp.
|
private |
Definition at line 191 of file bidirectionalInterface.hpp.
|
private |
Definition at line 192 of file bidirectionalInterface.hpp.
|
private |
Definition at line 188 of file bidirectionalInterface.hpp.
|
private |
Definition at line 194 of file bidirectionalInterface.hpp.