9#include <libtrap/trap.h>
18 , m_interfaceID(interfaceID)
19 , m_sendEoFonExit(true)
46 if (errorCode == TRAP_E_TIMEOUT) {
49 if (errorCode == TRAP_E_OK) {
52 if (errorCode == TRAP_E_NOT_INITIALIZED) {
53 throw std::runtime_error(
54 "UnirecOutputInterface::send() has failed. Trap interface is not initialized.");
56 if (errorCode == TRAP_E_TERMINATED) {
57 throw std::runtime_error(
58 "UnirecOutputInterface::send() has failed. Trap interface is terminated.");
60 if (errorCode == TRAP_E_BAD_IFC_INDEX) {
61 throw std::runtime_error(
62 "UnirecOutputInterface::send() has failed. Interface ID out of range.");
64 throw std::runtime_error(
65 "UnirecOutputInterface::send() has failed. Return code: " + std::to_string(errorCode)
66 +
", msg: " + trap_last_error_msg);
81 trap_ifcctl(TRAPIFC_OUTPUT,
m_interfaceID, TRAPCTL_SETTIMEOUT, timeout);
86 trap_ifcctl(TRAPIFC_OUTPUT,
m_interfaceID, TRAPCTL_AUTOFLUSH_TIMEOUT, timeout);
98 throw std::runtime_error(
99 "UnirecOutputInterface::changeTemplate() has failed. Template fields could not be "
103 std::unique_ptr<char*> fieldNames
107 throw std::runtime_error(
108 "UnirecOutputInterface::changeTemplate() has failed. Field specs could not be "
114 throw std::runtime_error(
115 "UnirecOutputInterface::changeTemplate() has failed. Output template could not be "
void changeTemplate(const std::string &templateFields="")
Changes the UniRec template for the Trap interface.
bool send(UnirecRecord &unirecRecord) const
Sends a UniRec record through the Trap interface.
bool handleSendErrorCodes(int errorCode) const
UnirecOutputInterface(uint8_t interfaceID)
UnirecRecord createUnirecRecord(size_t maxVariableFieldsSize=UR_MAX_SIZE)
Creates a new UniRec record with the specified maximum variable fields size.
ur_template_t * m_template
void setTimeout(int timeout)
Sets the send timeout for the Trap interface.
UnirecRecord m_unirecRecord
void sendFlush() const
Flushes any pending UniRec records in the Trap interface.
void setAutoflushTimeout(int timeout)
Sets the autoflush timeout for the Trap interface.
~UnirecOutputInterface()
Destructor for the UnirecOutputInterface class.
void doNotsendEoFOnExit()
Disables sending an end-of-file marker on exit.
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.
size_t size() const noexcept
Returns the size of the UniRec record.
const void * data() const noexcept
Returns a pointer to the data of the UniRec record.
#define ur_create_output_template(ifc, fields, errstr)
Create UniRec template and set it to output interface Creates UniRec template (same like ur_create_te...
void ur_free_template(ur_template_t *tmplt)
Destroy UniRec template Free all memory allocated for a template created previously by ur_create_temp...
char * ur_ifc_data_fmt_to_field_names(const char *ifc_data_fmt)
Parses field names from data format Function parses field names from data format and returns pointer ...
int ur_define_set_of_fields(const char *ifc_data_fmt)
Define set of new UniRec fields Define new UniRec fields at run-time. It adds new fields into existin...
Defines the UnirecOutputInterface class.