UniRec  3.3.1
Public Member Functions | Private Member Functions | Private Attributes | Friends
Nemea::UnirecOutputInterface Class Reference

A class for sending UniRec records through a Trap interface. More...

#include <outputInterface.hpp>

Public Member Functions

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 setTimeout (int timeout)
 Sets the send timeout for the Trap interface. More...
 
void setAutoflushTimeout (int timeout)
 Sets the autoflush timeout for the Trap interface. More...
 
void changeTemplate (const std::string &templateFields="")
 Changes the UniRec template for the 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 output interface. More...
 
 ~UnirecOutputInterface ()
 Destructor for the UnirecOutputInterface 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

 UnirecOutputInterface (uint8_t interfaceID)
 
bool handleSendErrorCodes (int errorCode) const
 
void sendEoF () const
 

Private Attributes

ur_template_tm_template = nullptr
 
uint8_t m_interfaceID
 
bool m_sendEoFonExit
 
bool m_isInitialized
 
UnirecRecord m_unirecRecord
 

Friends

class Unirec
 

Detailed Description

A class for sending UniRec records through a Trap interface.

Definition at line 24 of file outputInterface.hpp.

Constructor & Destructor Documentation

◆ ~UnirecOutputInterface()

Nemea::UnirecOutputInterface::~UnirecOutputInterface ( )

Destructor for the UnirecOutputInterface class.

Sends an end-of-file marker if m_sendEoFonExit is true, then frees the memory allocated for the UniRec template.

Definition at line 24 of file outputInterface.cpp.

◆ UnirecOutputInterface()

Nemea::UnirecOutputInterface::UnirecOutputInterface ( uint8_t  interfaceID)
private

Definition at line 16 of file outputInterface.cpp.

Member Function Documentation

◆ changeTemplate()

void Nemea::UnirecOutputInterface::changeTemplate ( const std::string &  templateFields = "")

Changes the UniRec template for the Trap interface.

Format: "uint64 BYTES, string SNI" (unirecDataType NAME)

Parameters
templateFieldsA string containing the UniRec template fields.
Exceptions
std::runtime_errorif the template could not be created.

Definition at line 96 of file outputInterface.cpp.

◆ createUnirecRecord()

UnirecRecord Nemea::UnirecOutputInterface::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 124 of file outputInterface.cpp.

◆ doNotsendEoFOnExit()

void Nemea::UnirecOutputInterface::doNotsendEoFOnExit ( )

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

Definition at line 75 of file outputInterface.cpp.

◆ getTemplate()

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

Gets the Unirec template used by the output interface.

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

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

Definition at line 91 of file outputInterface.hpp.

◆ getUnirecRecord()

UnirecRecord& Nemea::UnirecOutputInterface::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 116 of file outputInterface.hpp.

◆ handleSendErrorCodes()

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

Definition at line 45 of file outputInterface.cpp.

◆ send() [1/2]

bool Nemea::UnirecOutputInterface::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 33 of file outputInterface.cpp.

◆ send() [2/2]

bool Nemea::UnirecOutputInterface::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 39 of file outputInterface.cpp.

◆ sendEoF()

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

Definition at line 90 of file outputInterface.cpp.

◆ sendFlush()

void Nemea::UnirecOutputInterface::sendFlush ( ) const

Flushes any pending UniRec records in the Trap interface.

Definition at line 70 of file outputInterface.cpp.

◆ setAutoflushTimeout()

void Nemea::UnirecOutputInterface::setAutoflushTimeout ( int  timeout)

Sets the autoflush timeout for the Trap interface.

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

Definition at line 85 of file outputInterface.cpp.

◆ setTimeout()

void Nemea::UnirecOutputInterface::setTimeout ( 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 80 of file outputInterface.cpp.

Friends And Related Function Documentation

◆ Unirec

friend class Unirec
friend

Definition at line 143 of file outputInterface.hpp.

Field Documentation

◆ m_interfaceID

uint8_t Nemea::UnirecOutputInterface::m_interfaceID
private

Definition at line 138 of file outputInterface.hpp.

◆ m_isInitialized

bool Nemea::UnirecOutputInterface::m_isInitialized
private

Definition at line 140 of file outputInterface.hpp.

◆ m_sendEoFonExit

bool Nemea::UnirecOutputInterface::m_sendEoFonExit
private

Definition at line 139 of file outputInterface.hpp.

◆ m_template

ur_template_t* Nemea::UnirecOutputInterface::m_template = nullptr
private

Definition at line 137 of file outputInterface.hpp.

◆ m_unirecRecord

UnirecRecord Nemea::UnirecOutputInterface::m_unirecRecord
private

Definition at line 141 of file outputInterface.hpp.


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