UniRec  3.0.0
bidirectionalInterface.hpp
Go to the documentation of this file.
1 
13 #pragma once
14 
15 #include "unirecException.hpp"
16 #include "unirecRecord.hpp"
17 #include "unirecRecordView.hpp"
18 
19 #include <optional>
20 #include <stdexcept>
21 #include <string>
22 #include <unirec/unirec.h>
23 
24 namespace NemeaPlusPlus {
25 
34 public:
46  std::optional<UnirecRecordView> receive();
47 
55  bool send(UnirecRecord& unirecRecord) const;
56 
64  bool send(UnirecRecordView& unirecRecordView) const;
65 
69  void sendFlush() const;
70 
82  void changeTemplate();
83 
93  void setRequieredFormat(const std::string& templateSpecification);
94 
106  void setReceiveTimeout(int timeout);
107 
118  void setSendTimeout(int timeout);
119 
126  void setSendAutoflushTimeout(int timeout);
127 
131  void doNotsendEoFOnExit();
132 
140  ur_template_t* getTemplate() const noexcept { return m_template; }
141 
149 
166 
179  UnirecRecord createUnirecRecord(size_t maxVariableFieldsSize = UR_MAX_SIZE);
180 
181 private:
182  UnirecBidirectionalInterface(uint8_t inputInterfaceID, uint8_t outputInterfaceID);
183  void handleReceiveErrorCodes(int errorCode) const;
184  bool handleSendErrorCodes(int errorCode) const;
185  bool isEoFReceived() const noexcept;
186  void sendEoF() const;
187 
195 
196  friend class Unirec;
197 };
198 
199 } // namespace NemeaPlusPlus
A class that provides a bidirectional interface for sending and receiving unirec records.
ur_template_t * getTemplate() const noexcept
Gets the Unirec template used by the bidirectional interface.
UnirecBidirectionalInterface(uint8_t inputInterfaceID, uint8_t outputInterfaceID)
void sendFlush() const
Flushes any pending UniRec records in the Trap interface.
UnirecRecord createUnirecRecord(size_t maxVariableFieldsSize=UR_MAX_SIZE)
Creates a new UniRec record with the specified maximum variable fields size.
void setSendAutoflushTimeout(int timeout)
Sets the autoflush timeout for the output Trap interface.
~UnirecBidirectionalInterface()
Destructor for the UnirecBidirectionalInterface class.
std::optional< UnirecRecordView > receive()
Receives data from the interface and returns an optional UnirecRecordView object.
void setRequieredFormat(const std::string &templateSpecification)
Sets the required Unirec format specification.
UnirecRecord & getUnirecRecord() noexcept
Gets a reference to the pre-allocated UniRec record for efficient use.
void doNotsendEoFOnExit()
Disables sending an end-of-file marker on exit.
bool send(UnirecRecord &unirecRecord) const
Sends a UniRec record through the Trap interface.
void setSendTimeout(int timeout)
Sets the send timeout for the Trap interface.
void setReceiveTimeout(int timeout)
Sets the receive timeout for the interface. This method sets the timeout for receiving UniRec records...
void changeTemplate()
Changes the Unirec template used by the bidirectional interface.
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
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