12 #include <libtrap/trap.h> 17 uint8_t inputInterfaceID,
18 uint8_t outputInterfaceID)
20 , m_inputInterfaceID(inputInterfaceID)
21 , m_outputInterfaceID(outputInterfaceID)
23 , m_prioritizedDataPointer(nullptr)
24 , m_sendEoFonExit(true)
25 , m_isInitialized(false)
41 const void* receivedData;
42 uint16_t dataSize = 0;
51 if (errorCode == TRAP_E_TIMEOUT) {
54 if (errorCode == TRAP_E_FORMAT_CHANGED) {
69 if (errorCode == TRAP_E_OK) {
72 if (errorCode == TRAP_E_NOT_INITIALIZED) {
73 throw std::runtime_error(
74 "UnirecBidirectionalInterface::receive() has failed. Trap interface is not " 77 if (errorCode == TRAP_E_TERMINATED) {
78 throw std::runtime_error(
79 "UnirecBidirectionalInterface::receive() has failed. Trap interface is terminated.");
81 if (errorCode == TRAP_E_NOT_SELECTED) {
82 throw std::runtime_error(
83 "UnirecBidirectionalInterface::receive() has failed. Interface ID out of range.");
85 throw std::runtime_error(
86 "UnirecBidirectionalInterface::receive() has failed. Return code: " 87 + std::to_string(errorCode) +
", msg: " + trap_last_error_msg);
92 int ret = trap_set_required_fmt(
m_inputInterfaceID, TRAP_FMT_UNIREC, templateSpecification.c_str());
93 if (ret != TRAP_E_OK) {
94 throw std::runtime_error(
95 "UnirecBidirectionalInterface::setRequieredFormat() has failed. Unable to set required " 99 if (templateSpecification.empty()) {
110 throw std::runtime_error(
111 "UnirecBidirectionalInterface::changeTemplate() has failed. Template could not be " 118 if (ret != TRAP_E_OK) {
119 throw std::runtime_error(
"UnirecBidirectionalInterface::changeTemplate() has failed.");
123 if (ret != TRAP_E_OK) {
124 throw std::runtime_error(
"UnirecBidirectionalInterface::changeTemplate() has failed.");
135 const char* spec =
nullptr;
138 if (ret != TRAP_E_OK) {
139 throw std::runtime_error(
140 "UnirecBidirectionalInterface::changeTemplate() has failed. Data format was not " 172 if (errorCode == TRAP_E_TIMEOUT) {
175 if (errorCode == TRAP_E_OK) {
178 if (errorCode == TRAP_E_NOT_INITIALIZED) {
179 throw std::runtime_error(
180 "UnirecBidirectionalInterface::send() has failed. Trap interface is not initialized.");
182 if (errorCode == TRAP_E_TERMINATED) {
183 throw std::runtime_error(
184 "UnirecBidirectionalInterface::send() has failed. Trap interface is terminated.");
186 if (errorCode == TRAP_E_BAD_IFC_INDEX) {
187 throw std::runtime_error(
188 "UnirecBidirectionalInterface::send() has failed. Interface ID out of range.");
190 throw std::runtime_error(
191 "UnirecBidirectionalInterface::send() has failed. Return code: " + std::to_string(errorCode)
192 +
", msg: " + trap_last_error_msg);
217 char dummy[1] = { 0 };
225 struct input_ifc_stats ifcStats = {};
uint64_t m_sequenceNumber
InputInteraceStats getInputInterfaceStats() const
Gets the statistics for the input interface.
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_set_output_template(ifc, tmplt)
Set UniRec template to ouput interface.
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)
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)...
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.
const void * m_prioritizedDataPointer
UnirecRecord m_unirecRecord
ur_template_t * m_template
void setRequieredFormat(const std::string &templateSpecification)
Sets the required Unirec format specification.
void changeTemplate()
Changes the Unirec template used by the bidirectional interface.
const void * data() const noexcept
Returns a pointer to the data of the UniRec record.
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.
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.
void doNotsendEoFOnExit()
Disables sending an end-of-file marker on exit.
uint8_t m_outputInterfaceID
void setSendAutoflushTimeout(int timeout)
Sets the autoflush timeout for the output Trap interface.
An exception that is thrown when the end of the input stream is reached.
uint8_t m_inputInterfaceID
Defines a bidirectional interface for sending and receiving unirec records using the TRAP interface p...
Provides a view into a UniRec record.
size_t size() const noexcept
Returns the size of the UniRec record.
void sendFlush() const
Flushes any pending UniRec records in the Trap interface.
void handleReceiveErrorCodes(int errorCode) const
~UnirecBidirectionalInterface()
Destructor for the UnirecBidirectionalInterface class.