UniRec  3.0.0
Public Member Functions | Private Member Functions | Private Attributes | Friends
NemeaPlusPlus::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...
 
 ~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
 
bool isEoFReceived () const noexcept
 
void sendEoF () const
 

Private Attributes

ur_template_tm_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
 

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 33 of file bidirectionalInterface.hpp.

Constructor & Destructor Documentation

◆ ~UnirecBidirectionalInterface()

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.

◆ UnirecBidirectionalInterface()

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

Definition at line 25 of file bidirectionalInterface.cpp.

Member Function Documentation

◆ changeTemplate()

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.

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

Definition at line 114 of file bidirectionalInterface.cpp.

◆ createUnirecRecord()

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.

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

Definition at line 149 of file bidirectionalInterface.cpp.

◆ doNotsendEoFOnExit()

void NemeaPlusPlus::UnirecBidirectionalInterface::doNotsendEoFOnExit ( )

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

Definition at line 197 of file bidirectionalInterface.cpp.

◆ getTemplate()

ur_template_t* NemeaPlusPlus::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 140 of file bidirectionalInterface.hpp.

◆ getUnirecRecord()

UnirecRecord& NemeaPlusPlus::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 165 of file bidirectionalInterface.hpp.

◆ handleReceiveErrorCodes()

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

Definition at line 75 of file bidirectionalInterface.cpp.

◆ handleSendErrorCodes()

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

Definition at line 167 of file bidirectionalInterface.cpp.

◆ isEoFReceived()

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

Definition at line 70 of file bidirectionalInterface.cpp.

◆ receive()

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.

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 NemeaPlusPlus::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 154 of file bidirectionalInterface.cpp.

◆ send() [2/2]

bool NemeaPlusPlus::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 160 of file bidirectionalInterface.cpp.

◆ sendEoF()

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

Definition at line 212 of file bidirectionalInterface.cpp.

◆ sendFlush()

void NemeaPlusPlus::UnirecBidirectionalInterface::sendFlush ( ) const

Flushes any pending UniRec records in the Trap interface.

Definition at line 192 of file bidirectionalInterface.cpp.

◆ setReceiveTimeout()

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.

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

◆ setRequieredFormat()

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)

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

Definition at line 98 of file bidirectionalInterface.cpp.

◆ setSendAutoflushTimeout()

void NemeaPlusPlus::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 207 of file bidirectionalInterface.cpp.

◆ setSendTimeout()

void NemeaPlusPlus::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 202 of file bidirectionalInterface.cpp.

Friends And Related Function Documentation

◆ Unirec

friend class Unirec
friend

Definition at line 196 of file bidirectionalInterface.hpp.

Field Documentation

◆ m_EoFOnNextReceive

bool NemeaPlusPlus::UnirecBidirectionalInterface::m_EoFOnNextReceive
private

Definition at line 193 of file bidirectionalInterface.hpp.

◆ m_inputInterfaceID

uint8_t NemeaPlusPlus::UnirecBidirectionalInterface::m_inputInterfaceID
private

Definition at line 189 of file bidirectionalInterface.hpp.

◆ m_outputInterfaceID

uint8_t NemeaPlusPlus::UnirecBidirectionalInterface::m_outputInterfaceID
private

Definition at line 190 of file bidirectionalInterface.hpp.

◆ m_prioritizedDataPointer

const void* NemeaPlusPlus::UnirecBidirectionalInterface::m_prioritizedDataPointer
private

Definition at line 191 of file bidirectionalInterface.hpp.

◆ m_sendEoFonExit

bool NemeaPlusPlus::UnirecBidirectionalInterface::m_sendEoFonExit
private

Definition at line 192 of file bidirectionalInterface.hpp.

◆ m_template

ur_template_t* NemeaPlusPlus::UnirecBidirectionalInterface::m_template
private

Definition at line 188 of file bidirectionalInterface.hpp.

◆ m_unirecRecord

UnirecRecord NemeaPlusPlus::UnirecBidirectionalInterface::m_unirecRecord
private

Definition at line 194 of file bidirectionalInterface.hpp.


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