UniRec  3.2.0
Public Member Functions | Private Member Functions | Private Attributes | Friends
Nemea::UnirecBidirectionalInterface Class Reference

A class that provides a bidirectional interface for sending and receiving unirec records. More...

#include <bidirectionalInterface.hpp>

Public Member Functions

std::optional< UnirecRecordViewreceive ()
 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_tgetTemplate () 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...
 
UnirecRecordgetUnirecRecord () 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_tm_template
 
uint8_t m_inputInterfaceID
 
uint8_t m_outputInterfaceID
 
uint64_t m_sequenceNumber
 
const void * m_prioritizedDataPointer
 
bool m_sendEoFonExit
 
UnirecRecord m_unirecRecord
 

Friends

class Unirec
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ~UnirecBidirectionalInterface()

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 16 of file bidirectionalInterface.cpp.

◆ UnirecBidirectionalInterface()

Nemea::UnirecBidirectionalInterface::UnirecBidirectionalInterface ( uint8_t  inputInterfaceID,
uint8_t  outputInterfaceID 
)
private

Definition at line 25 of file bidirectionalInterface.cpp.

Member Function Documentation

◆ changeInternalTemplate()

void Nemea::UnirecBidirectionalInterface::changeInternalTemplate ( const std::string &  templateSpecification)
private

Definition at line 101 of file bidirectionalInterface.cpp.

◆ changeTemplate()

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.

Exceptions
std::runtime_errorif the data format was not loaded or the template could not be edited.

Definition at line 125 of file bidirectionalInterface.cpp.

◆ createUnirecRecord()

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.

Parameters
maxVariableFieldsSizeThe maximum size for variable fields in the new UniRec record.
Returns
A newly created UnirecRecord instance.

Definition at line 145 of file bidirectionalInterface.cpp.

◆ doNotsendEoFOnExit()

void Nemea::UnirecBidirectionalInterface::doNotsendEoFOnExit ( )

Disables sending an end-of-file marker on exit.

Definition at line 193 of file bidirectionalInterface.cpp.

◆ getInputInterfaceStats()

InputInteraceStats Nemea::UnirecBidirectionalInterface::getInputInterfaceStats ( ) const

Gets the statistics for the input interface.

This method returns the actual statistics for the input interface.

Returns
The statistics for the input interface.

Definition at line 214 of file bidirectionalInterface.cpp.

◆ getTemplate()

ur_template_t* Nemea::UnirecBidirectionalInterface::getTemplate ( ) const
inlinenoexcept

Gets the Unirec template used by the bidirectional interface.

This method returns a pointer to the Unirec template used by the bidirectional interface.

Returns
A pointer to the Unirec template used by the bidirectional interface.

Definition at line 141 of file bidirectionalInterface.hpp.

◆ getUnirecRecord()

UnirecRecord& Nemea::UnirecBidirectionalInterface::getUnirecRecord ( )
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.

Note
The record accessed through this function is specific to this instance of the UnirecOutputInterface and should not be shared across multiple instances or threads.
Returns
A reference to the pre-allocated UniRec record.

Definition at line 175 of file bidirectionalInterface.hpp.

◆ handleReceiveErrorCodes()

void Nemea::UnirecBidirectionalInterface::handleReceiveErrorCodes ( int  errorCode) const
private

Definition at line 66 of file bidirectionalInterface.cpp.

◆ handleSendErrorCodes()

bool Nemea::UnirecBidirectionalInterface::handleSendErrorCodes ( int  errorCode) const
private

Definition at line 163 of file bidirectionalInterface.cpp.

◆ isEoFReceived()

bool Nemea::UnirecBidirectionalInterface::isEoFReceived ( ) const
privatenoexcept

◆ receive()

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.

Returns
An optional UnirecRecordView object.
Exceptions
EoFExceptionif the end of the input stream is reached.
FormatChangeExceptionif the record format changes.

Definition at line 38 of file bidirectionalInterface.cpp.

◆ send() [1/2]

bool Nemea::UnirecBidirectionalInterface::send ( UnirecRecord unirecRecord) const

Sends a UniRec record through the Trap interface.

Parameters
unirecRecordthe Unirec record to send
Exceptions
std::runtime_errorif an error occurs while sending the record
Returns
true if the record was sent successfully, false if a timeout occurred

Definition at line 150 of file bidirectionalInterface.cpp.

◆ send() [2/2]

bool Nemea::UnirecBidirectionalInterface::send ( UnirecRecordView unirecRecordView) const

Sends a UniRec record view through the Trap interface.

Parameters
unirecRecordViewThe UniRec record view to send.
Exceptions
std::runtime_errorif an error occurs while sending the record
Returns
true if the record was sent successfully, false if a timeout occurred

Definition at line 156 of file bidirectionalInterface.cpp.

◆ sendEoF()

void Nemea::UnirecBidirectionalInterface::sendEoF ( ) const
private

Definition at line 208 of file bidirectionalInterface.cpp.

◆ sendFlush()

void Nemea::UnirecBidirectionalInterface::sendFlush ( ) const

Flushes any pending UniRec records in the Trap interface.

Definition at line 188 of file bidirectionalInterface.cpp.

◆ setReceiveTimeout()

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.

Parameters
timeoutThe timeout value in microseconds.
  • TRAP_WAIT: Blocking mode, wait for client's connection, for message transport to/from internal system buffer.
  • TRAP_NO_WAIT: Non-Blocking mode, do not wait ever.
  • timeout: Wait max for specific time.

Definition at line 140 of file bidirectionalInterface.cpp.

◆ setRequieredFormat()

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)

Parameters
templateSpecificationThe required Unirec format specification.
Exceptions
std::runtime_errorif the required format could not be set.

Definition at line 89 of file bidirectionalInterface.cpp.

◆ setSendAutoflushTimeout()

void Nemea::UnirecBidirectionalInterface::setSendAutoflushTimeout ( int  timeout)

Sets the autoflush timeout for the output Trap interface.

Parameters
timeoutThe timeout value in microseconds.
  • TRAP_NO_AUTO_FLUSH: Do not autoflush trap buffers

Definition at line 203 of file bidirectionalInterface.cpp.

◆ setSendTimeout()

void Nemea::UnirecBidirectionalInterface::setSendTimeout ( int  timeout)

Sets the send timeout for the Trap interface.

Parameters
timeoutThe timeout value in microseconds.
  • TRAP_WAIT: Blocking mode, wait for client's connection, for message transport to/from internal system buffer.
  • TRAP_HALFWAIT: Blocking only if any client is connected.
  • TRAP_NO_WAIT: Non-Blocking mode, do not wait ever.
  • timeout: Wait max for specific time.

Definition at line 198 of file bidirectionalInterface.cpp.

Friends And Related Function Documentation

◆ Unirec

friend class Unirec
friend

Definition at line 207 of file bidirectionalInterface.hpp.

Field Documentation

◆ m_inputInterfaceID

uint8_t Nemea::UnirecBidirectionalInterface::m_inputInterfaceID
private

Definition at line 200 of file bidirectionalInterface.hpp.

◆ m_outputInterfaceID

uint8_t Nemea::UnirecBidirectionalInterface::m_outputInterfaceID
private

Definition at line 201 of file bidirectionalInterface.hpp.

◆ m_prioritizedDataPointer

const void* Nemea::UnirecBidirectionalInterface::m_prioritizedDataPointer
private

Definition at line 203 of file bidirectionalInterface.hpp.

◆ m_sendEoFonExit

bool Nemea::UnirecBidirectionalInterface::m_sendEoFonExit
private

Definition at line 204 of file bidirectionalInterface.hpp.

◆ m_sequenceNumber

uint64_t Nemea::UnirecBidirectionalInterface::m_sequenceNumber
private

Definition at line 202 of file bidirectionalInterface.hpp.

◆ m_template

ur_template_t* Nemea::UnirecBidirectionalInterface::m_template
private

Definition at line 199 of file bidirectionalInterface.hpp.

◆ m_unirecRecord

UnirecRecord Nemea::UnirecBidirectionalInterface::m_unirecRecord
private

Definition at line 205 of file bidirectionalInterface.hpp.


The documentation for this class was generated from the following files: