UniRec  3.2.0
bidirectionalInterface.hpp
Go to the documentation of this file.
1 
13 #pragma once
14 
15 #include "interfaceStats.hpp"
16 #include "unirecException.hpp"
17 #include "unirecRecord.hpp"
18 #include "unirecRecordView.hpp"
19 
20 #include <optional>
21 #include <stdexcept>
22 #include <string>
23 #include <unirec/unirec.h>
24 
25 namespace Nemea {
26 
35 public:
47  std::optional<UnirecRecordView> receive();
48 
56  bool send(UnirecRecord& unirecRecord) const;
57 
65  bool send(UnirecRecordView& unirecRecordView) const;
66 
70  void sendFlush() const;
71 
83  void changeTemplate();
84 
94  void setRequieredFormat(const std::string& templateSpecification);
95 
107  void setReceiveTimeout(int timeout);
108 
119  void setSendTimeout(int timeout);
120 
127  void setSendAutoflushTimeout(int timeout);
128 
132  void doNotsendEoFOnExit();
133 
141  ur_template_t* getTemplate() const noexcept { return m_template; }
142 
151 
159 
176 
189  UnirecRecord createUnirecRecord(size_t maxVariableFieldsSize = UR_MAX_SIZE);
190 
191 private:
192  UnirecBidirectionalInterface(uint8_t inputInterfaceID, uint8_t outputInterfaceID);
193  void handleReceiveErrorCodes(int errorCode) const;
194  bool handleSendErrorCodes(int errorCode) const;
195  void changeInternalTemplate(const std::string& templateSpecification);
196  bool isEoFReceived() const noexcept;
197  void sendEoF() const;
198 
206 
207  friend class Unirec;
208 };
209 
210 } // namespace Nemea
A class that provides a bidirectional interface for sending and receiving unirec records.
void setSendAutoflushTimeout(int timeout)
Sets the autoflush timeout for the output Trap interface.
~UnirecBidirectionalInterface()
Destructor for the UnirecBidirectionalInterface class.
bool handleSendErrorCodes(int errorCode) const
ur_template_t * getTemplate() const noexcept
Gets the Unirec template used by the bidirectional interface.
void handleReceiveErrorCodes(int errorCode) const
void sendFlush() const
Flushes any pending UniRec records in the Trap interface.
void changeTemplate()
Changes the Unirec template used by the bidirectional interface.
void changeInternalTemplate(const std::string &templateSpecification)
InputInteraceStats getInputInterfaceStats() const
Gets the statistics for the input interface.
void setReceiveTimeout(int timeout)
Sets the receive timeout for the interface. This method sets the timeout for receiving UniRec records...
UnirecRecord createUnirecRecord(size_t maxVariableFieldsSize=UR_MAX_SIZE)
Creates a new UniRec record with the specified maximum variable fields size.
void doNotsendEoFOnExit()
Disables sending an end-of-file marker on exit.
bool isEoFReceived() const noexcept
void setSendTimeout(int timeout)
Sets the send timeout for the Trap interface.
std::optional< UnirecRecordView > receive()
Receives data from the interface and returns an optional UnirecRecordView object.
UnirecRecord & getUnirecRecord() noexcept
Gets a reference to the pre-allocated UniRec record for efficient use.
void setRequieredFormat(const std::string &templateSpecification)
Sets the required Unirec format specification.
bool send(UnirecRecord &unirecRecord) const
Sends a UniRec record through the Trap interface.
UnirecBidirectionalInterface(uint8_t inputInterfaceID, uint8_t outputInterfaceID)
Provides a view into a UniRec record.
A class for working with UniRec records and their fields.
#define UR_MAX_SIZE
Definition: unirec.h:1013
This file contains the declarations of the interface stats structure.
Structure to store statistics related to an input interface.
Defines custom exception classes.
Provides a view into a UniRec record.
Defines the UnirecRecord class.
Definition of UniRec structures and functions.
UniRec template. It contains a table mapping a field to its position in an UniRec record.
Definition: unirec.h:191