UniRec
3.3.2
|
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. More... | |
bool | send (UnirecRecord &unirecRecord) const |
Sends a UniRec record through the Trap interface. More... | |
bool | send (UnirecRecordView &unirecRecordView) const |
Sends a UniRec record view through the Trap interface. More... | |
void | sendFlush () const |
Flushes any pending UniRec records in the Trap interface. More... | |
void | changeTemplate () |
Changes the Unirec template used by the bidirectional interface. More... | |
void | setRequieredFormat (const std::string &templateSpecification) |
Sets the required Unirec format specification. More... | |
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. More... | |
void | setSendTimeout (int timeout) |
Sets the send timeout for the Trap interface. More... | |
void | setSendAutoflushTimeout (int timeout) |
Sets the autoflush timeout for the output Trap interface. More... | |
void | doNotsendEoFOnExit () |
Disables sending an end-of-file marker on exit. More... | |
ur_template_t * | getTemplate () const noexcept |
Gets the Unirec template used by the bidirectional interface. More... | |
InputInteraceStats | getInputInterfaceStats () const |
Gets the statistics for the input interface. More... | |
~UnirecBidirectionalInterface () | |
Destructor for the UnirecBidirectionalInterface class. More... | |
UnirecRecord & | getUnirecRecord () noexcept |
Gets a reference to the pre-allocated UniRec record for efficient use. More... | |
UnirecRecord | createUnirecRecord (size_t maxVariableFieldsSize=UR_MAX_SIZE) |
Creates a new UniRec record with the specified maximum variable fields size. More... | |
Private Member Functions | |
UnirecBidirectionalInterface (uint8_t inputInterfaceID, uint8_t outputInterfaceID) | |
void | handleReceiveErrorCodes (int errorCode) const |
bool | handleSendErrorCodes (int errorCode) const |
void | changeInternalTemplate (const std::string &templateSpecification) |
bool | isEoFReceived () const noexcept |
void | sendEoF () const |
Private Attributes | |
ur_template_t * | m_template |
uint8_t | m_inputInterfaceID |
uint8_t | m_outputInterfaceID |
uint64_t | m_sequenceNumber |
const void * | m_prioritizedDataPointer |
bool | m_sendEoFonExit |
bool | m_isInitialized |
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 34 of file bidirectionalInterface.hpp.
Nemea::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 30 of file bidirectionalInterface.cpp.
|
private |
Definition at line 16 of file bidirectionalInterface.cpp.
|
private |
Definition at line 106 of file bidirectionalInterface.cpp.
void Nemea::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 132 of file bidirectionalInterface.cpp.
UnirecRecord Nemea::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 152 of file bidirectionalInterface.cpp.
void Nemea::UnirecBidirectionalInterface::doNotsendEoFOnExit | ( | ) |
Disables sending an end-of-file marker on exit.
Definition at line 200 of file bidirectionalInterface.cpp.
InputInteraceStats Nemea::UnirecBidirectionalInterface::getInputInterfaceStats | ( | ) | const |
Gets the statistics for the input interface.
This method returns the actual statistics for the input interface.
Definition at line 221 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 141 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 175 of file bidirectionalInterface.hpp.
|
private |
Definition at line 67 of file bidirectionalInterface.cpp.
|
private |
Definition at line 170 of file bidirectionalInterface.cpp.
|
privatenoexcept |
std::optional< UnirecRecordView > Nemea::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 39 of file bidirectionalInterface.cpp.
bool Nemea::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 157 of file bidirectionalInterface.cpp.
bool Nemea::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 163 of file bidirectionalInterface.cpp.
|
private |
Definition at line 215 of file bidirectionalInterface.cpp.
void Nemea::UnirecBidirectionalInterface::sendFlush | ( | ) | const |
Flushes any pending UniRec records in the Trap interface.
Definition at line 195 of file bidirectionalInterface.cpp.
void Nemea::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 147 of file bidirectionalInterface.cpp.
void Nemea::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 90 of file bidirectionalInterface.cpp.
void Nemea::UnirecBidirectionalInterface::setSendAutoflushTimeout | ( | int | timeout | ) |
Sets the autoflush timeout for the output Trap interface.
timeout | The timeout value in microseconds.
|
Definition at line 210 of file bidirectionalInterface.cpp.
void Nemea::UnirecBidirectionalInterface::setSendTimeout | ( | int | timeout | ) |
Sets the send timeout for the Trap interface.
timeout | The timeout value in microseconds.
|
Definition at line 205 of file bidirectionalInterface.cpp.
|
friend |
Definition at line 209 of file bidirectionalInterface.hpp.
|
private |
Definition at line 200 of file bidirectionalInterface.hpp.
|
private |
Definition at line 205 of file bidirectionalInterface.hpp.
|
private |
Definition at line 201 of file bidirectionalInterface.hpp.
|
private |
Definition at line 203 of file bidirectionalInterface.hpp.
|
private |
Definition at line 204 of file bidirectionalInterface.hpp.
|
private |
Definition at line 202 of file bidirectionalInterface.hpp.
|
private |
Definition at line 199 of file bidirectionalInterface.hpp.
|
private |
Definition at line 207 of file bidirectionalInterface.hpp.