diff --git a/unirec/include/unirec++/bidirectionalInterface.hpp b/unirec/include/unirec++/bidirectionalInterface.hpp index b616db10..85a0c2b4 100644 --- a/unirec/include/unirec++/bidirectionalInterface.hpp +++ b/unirec/include/unirec++/bidirectionalInterface.hpp @@ -202,6 +202,8 @@ class UnirecBidirectionalInterface { uint64_t m_sequenceNumber; const void* m_prioritizedDataPointer; bool m_sendEoFonExit; + bool m_isInitialized; + UnirecRecord m_unirecRecord; friend class Unirec; diff --git a/unirec/include/unirec++/outputInterface.hpp b/unirec/include/unirec++/outputInterface.hpp index 0c5b518e..ff4015c4 100644 --- a/unirec/include/unirec++/outputInterface.hpp +++ b/unirec/include/unirec++/outputInterface.hpp @@ -137,6 +137,7 @@ class UnirecOutputInterface { ur_template_t* m_template = nullptr; uint8_t m_interfaceID; bool m_sendEoFonExit; + bool m_isInitialized; UnirecRecord m_unirecRecord; friend class Unirec; diff --git a/unirec/unirec++/bidirectionalInterface.cpp b/unirec/unirec++/bidirectionalInterface.cpp index f67b2f7b..fb29bc12 100644 --- a/unirec/unirec++/bidirectionalInterface.cpp +++ b/unirec/unirec++/bidirectionalInterface.cpp @@ -13,15 +13,6 @@ namespace Nemea { -UnirecBidirectionalInterface::~UnirecBidirectionalInterface() -{ - if (m_sendEoFonExit) { - sendEoF(); - } - - ur_free_template(m_template); -} - UnirecBidirectionalInterface::UnirecBidirectionalInterface( uint8_t inputInterfaceID, uint8_t outputInterfaceID) @@ -31,10 +22,20 @@ UnirecBidirectionalInterface::UnirecBidirectionalInterface( , m_sequenceNumber(0) , m_prioritizedDataPointer(nullptr) , m_sendEoFonExit(true) + , m_isInitialized(false) { setRequieredFormat(""); } +UnirecBidirectionalInterface::~UnirecBidirectionalInterface() +{ + if (m_sendEoFonExit && m_isInitialized) { + sendEoF(); + } + + ur_free_template(m_template); +} + std::optional UnirecBidirectionalInterface::receive() { const void* receivedData; @@ -95,6 +96,10 @@ void UnirecBidirectionalInterface::setRequieredFormat(const std::string& templat "format."); } + if (templateSpecification.empty()) { + return; + } + changeInternalTemplate(templateSpecification); } @@ -120,6 +125,8 @@ void UnirecBidirectionalInterface::changeInternalTemplate(const std::string& tem } m_unirecRecord = createUnirecRecord(); + + m_isInitialized = true; } void UnirecBidirectionalInterface::changeTemplate() diff --git a/unirec/unirec++/outputInterface.cpp b/unirec/unirec++/outputInterface.cpp index a2e327b1..52413c78 100644 --- a/unirec/unirec++/outputInterface.cpp +++ b/unirec/unirec++/outputInterface.cpp @@ -17,12 +17,13 @@ UnirecOutputInterface::UnirecOutputInterface(uint8_t interfaceID) : m_template(nullptr) , m_interfaceID(interfaceID) , m_sendEoFonExit(true) + , m_isInitialized(false) { } UnirecOutputInterface::~UnirecOutputInterface() { - if (m_sendEoFonExit) { + if (m_sendEoFonExit && m_isInitialized) { sendEoF(); } @@ -88,7 +89,7 @@ void UnirecOutputInterface::setAutoflushTimeout(int timeout) void UnirecOutputInterface::sendEoF() const { - char dummy[1] = {0}; + char dummy[1] = { 0 }; trap_send(m_interfaceID, dummy, sizeof(dummy)); } @@ -116,6 +117,8 @@ void UnirecOutputInterface::changeTemplate(const std::string& templateFields) "created."); } m_unirecRecord = createUnirecRecord(); + + m_isInitialized = true; } UnirecRecord UnirecOutputInterface::createUnirecRecord(size_t maxVariableFieldsSize)