UniRec 3.3.2
Loading...
Searching...
No Matches
outputInterface.cpp
Go to the documentation of this file.
1
8
9#include <libtrap/trap.h>
10#include <stdexcept>
11
12#include <memory>
13
14namespace Nemea {
15
17 : m_template(nullptr)
18 , m_interfaceID(interfaceID)
19 , m_sendEoFonExit(true)
20 , m_isInitialized(false)
21{
22}
23
32
38
44
46{
48 return false;
49 }
50 if (errorCode == TRAP_E_OK) {
51 return true;
52 }
54 throw std::runtime_error(
55 "UnirecOutputInterface::send() has failed. Trap interface is not initialized.");
56 }
58 throw std::runtime_error(
59 "UnirecOutputInterface::send() has failed. Trap interface is terminated.");
60 }
62 throw std::runtime_error(
63 "UnirecOutputInterface::send() has failed. Interface ID out of range.");
64 }
65 throw std::runtime_error(
66 "UnirecOutputInterface::send() has failed. Return code: " + std::to_string(errorCode)
67 + ", msg: " + trap_last_error_msg);
68}
69
74
79
84
89
91{
92 char dummy[1] = { 0 };
94}
95
97{
99 throw std::runtime_error(
100 "UnirecOutputInterface::changeTemplate() has failed. Template fields could not be "
101 "defined!");
102 }
103
104 std::unique_ptr<char*> fieldNames
105 = std::make_unique<char*>(ur_ifc_data_fmt_to_field_names(templateFields.c_str()));
106
107 if (!fieldNames) {
108 throw std::runtime_error(
109 "UnirecOutputInterface::changeTemplate() has failed. Field specs could not be "
110 "converted.");
111 }
114 if (!m_template) {
115 throw std::runtime_error(
116 "UnirecOutputInterface::changeTemplate() has failed. Output template could not be "
117 "created.");
118 }
120
121 m_isInitialized = true;
122}
123
128
129} // namespace Nemea
bool handleSendErrorCodes(int errorCode) const
~UnirecOutputInterface()
Destructor for the UnirecOutputInterface class.
void sendFlush() const
Flushes any pending UniRec records in the Trap interface.
void setTimeout(int timeout)
Sets the send timeout for the Trap interface.
UnirecOutputInterface(uint8_t interfaceID)
void doNotsendEoFOnExit()
Disables sending an end-of-file marker on exit.
UnirecRecord createUnirecRecord(size_t maxVariableFieldsSize=UR_MAX_SIZE)
Creates a new UniRec record with the specified maximum variable fields size.
bool send(UnirecRecord &unirecRecord) const
Sends a UniRec record through the Trap interface.
void changeTemplate(const std::string &templateFields="")
Changes the UniRec template for the Trap interface.
void setAutoflushTimeout(int timeout)
Sets the autoflush timeout for the Trap interface.
Provides a view into a UniRec record.
A class for working with UniRec records and their fields.
#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...
Definition unirec.h:806
void ur_free_template(ur_template_t *tmplt)
Destroy UniRec template Free all memory allocated for a template created previously by ur_create_temp...
Definition unirec.c:1094
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 ...
Definition unirec.c:438
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...
Definition unirec.c:564
constexpr ur_field_type_t getExpectedUnirecType()
Determines the expected UniRec field type for a given C++ type T.
Defines the UnirecOutputInterface class.
#define UR_OK
No problem.
Definition unirec.h:90