12 #include <libtrap/trap.h>
26 uint8_t inputInterfaceID,
27 uint8_t outputInterfaceID)
29 , m_inputInterfaceID(inputInterfaceID)
30 , m_outputInterfaceID(outputInterfaceID)
32 , m_prioritizedDataPointer(nullptr)
33 , m_sendEoFonExit(true)
40 const void* receivedData;
41 uint16_t dataSize = 0;
50 if (errorCode == TRAP_E_TIMEOUT) {
53 if (errorCode == TRAP_E_FORMAT_CHANGED) {
68 if (errorCode == TRAP_E_OK) {
71 if (errorCode == TRAP_E_NOT_INITIALIZED) {
72 throw std::runtime_error(
73 "UnirecBidirectionalInterface::receive() has failed. Trap interface is not "
76 if (errorCode == TRAP_E_TERMINATED) {
77 throw std::runtime_error(
78 "UnirecBidirectionalInterface::receive() has failed. Trap interface is terminated.");
80 if (errorCode == TRAP_E_NOT_SELECTED) {
81 throw std::runtime_error(
82 "UnirecBidirectionalInterface::receive() has failed. Interface ID out of range.");
84 throw std::runtime_error(
85 "UnirecBidirectionalInterface::receive() has failed. Return code: "
86 + std::to_string(errorCode) +
", msg: " + trap_last_error_msg);
91 int ret = trap_set_required_fmt(
m_inputInterfaceID, TRAP_FMT_UNIREC, templateSpecification.c_str());
92 if (ret != TRAP_E_OK) {
93 throw std::runtime_error(
94 "UnirecBidirectionalInterface::setRequieredFormat() has failed. Unable to set required "
105 throw std::runtime_error(
106 "UnirecBidirectionalInterface::changeTemplate() has failed. Template could not be "
113 if (ret != TRAP_E_OK) {
114 throw std::runtime_error(
"UnirecBidirectionalInterface::changeTemplate() has failed.");
118 if (ret != TRAP_E_OK) {
119 throw std::runtime_error(
"UnirecBidirectionalInterface::changeTemplate() has failed.");
128 const char* spec =
nullptr;
131 if (ret != TRAP_E_OK) {
132 throw std::runtime_error(
133 "UnirecBidirectionalInterface::changeTemplate() has failed. Data format was not "
165 if (errorCode == TRAP_E_TIMEOUT) {
168 if (errorCode == TRAP_E_OK) {
171 if (errorCode == TRAP_E_NOT_INITIALIZED) {
172 throw std::runtime_error(
173 "UnirecBidirectionalInterface::send() has failed. Trap interface is not initialized.");
175 if (errorCode == TRAP_E_TERMINATED) {
176 throw std::runtime_error(
177 "UnirecBidirectionalInterface::send() has failed. Trap interface is terminated.");
179 if (errorCode == TRAP_E_BAD_IFC_INDEX) {
180 throw std::runtime_error(
181 "UnirecBidirectionalInterface::send() has failed. Interface ID out of range.");
183 throw std::runtime_error(
184 "UnirecBidirectionalInterface::send() has failed. Return code: " + std::to_string(errorCode)
185 +
", msg: " + trap_last_error_msg);
210 char dummy[1] = { 0 };
218 struct input_ifc_stats ifcStats = {};
Defines a bidirectional interface for sending and receiving unirec records using the TRAP interface p...
An exception that is thrown when the end of the input stream is reached.
ur_template_t * m_template
void setSendAutoflushTimeout(int timeout)
Sets the autoflush timeout for the output Trap interface.
~UnirecBidirectionalInterface()
Destructor for the UnirecBidirectionalInterface class.
bool handleSendErrorCodes(int errorCode) const
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...
const void * m_prioritizedDataPointer
UnirecRecord createUnirecRecord(size_t maxVariableFieldsSize=UR_MAX_SIZE)
Creates a new UniRec record with the specified maximum variable fields size.
UnirecRecord m_unirecRecord
void doNotsendEoFOnExit()
Disables sending an end-of-file marker on exit.
void setSendTimeout(int timeout)
Sets the send timeout for the Trap interface.
uint8_t m_inputInterfaceID
uint8_t m_outputInterfaceID
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.
uint64_t m_sequenceNumber
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.
size_t size() const noexcept
Returns the size of the UniRec record.
const void * data() const noexcept
Returns a const pointer to the data of the UniRec record.
A class for working with UniRec records and their fields.
const void * data() const noexcept
Returns a pointer to the data of the UniRec record.
size_t size() const noexcept
Returns the size of the UniRec record.
ur_template_t * ur_define_fields_and_update_template(const char *ifc_data_fmt, ur_template_t *tmplt)
Defined new fields and expand an UniRec template Define new fields (function ur_define_set_of_fields)...
#define ur_set_output_template(ifc, tmplt)
Set UniRec template to ouput interface.
void ur_free_template(ur_template_t *tmplt)
Destroy UniRec template Free all memory allocated for a template created previously by ur_create_temp...
#define ur_set_input_template(ifc, tmplt)
Set UniRec template to input interface.