UniRec  3.3.2
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 
208 
209  friend class Unirec;
210 };
211 
212 } // namespace Nemea
InputInteraceStats getInputInterfaceStats() const
Gets the statistics for the input interface.
Defines custom exception classes.
bool send(UnirecRecord &unirecRecord) const
Sends a UniRec record through the Trap interface.
void setReceiveTimeout(int timeout)
Sets the receive timeout for the interface. This method sets the timeout for receiving UniRec records...
#define UR_MAX_SIZE
Definition: unirec.h:1013
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. ...
UnirecBidirectionalInterface(uint8_t inputInterfaceID, uint8_t outputInterfaceID)
bool handleSendErrorCodes(int errorCode) const
void changeInternalTemplate(const std::string &templateSpecification)
This file contains the declarations of the interface stats structure.
UnirecRecord createUnirecRecord(size_t maxVariableFieldsSize=UR_MAX_SIZE)
Creates a new UniRec record with the specified maximum variable fields size.
A class for working with UniRec records and their fields.
Structure to store statistics related to an input interface.
Defines the UnirecRecord class.
Provides a view into a UniRec record.
bool isEoFReceived() const noexcept
void setRequieredFormat(const std::string &templateSpecification)
Sets the required Unirec format specification.
A class that provides a bidirectional interface for sending and receiving unirec records.
void changeTemplate()
Changes the Unirec template used by the bidirectional interface.
Definition of UniRec structures and functions.
void doNotsendEoFOnExit()
Disables sending an end-of-file marker on exit.
void setSendAutoflushTimeout(int timeout)
Sets the autoflush timeout for the output Trap interface.
Provides a view into a UniRec record.
UniRec template. It contains a table mapping a field to its position in an UniRec record...
Definition: unirec.h:191
ur_template_t * getTemplate() const noexcept
Gets the Unirec template used by the bidirectional interface.
UnirecRecord & getUnirecRecord() noexcept
Gets a reference to the pre-allocated UniRec record for efficient use.
void sendFlush() const
Flushes any pending UniRec records in the Trap interface.
void handleReceiveErrorCodes(int errorCode) const
~UnirecBidirectionalInterface()
Destructor for the UnirecBidirectionalInterface class.