Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unirec++ - output/bidirectional interface update #224

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions unirec/include/unirec++/bidirectionalInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions unirec/include/unirec++/outputInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 16 additions & 9 deletions unirec/unirec++/bidirectionalInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<UnirecRecordView> UnirecBidirectionalInterface::receive()
{
const void* receivedData;
Expand Down Expand Up @@ -95,6 +96,10 @@ void UnirecBidirectionalInterface::setRequieredFormat(const std::string& templat
"format.");
}

if (templateSpecification.empty()) {
return;
}

changeInternalTemplate(templateSpecification);
}

Expand All @@ -120,6 +125,8 @@ void UnirecBidirectionalInterface::changeInternalTemplate(const std::string& tem
}

m_unirecRecord = createUnirecRecord();

m_isInitialized = true;
}

void UnirecBidirectionalInterface::changeTemplate()
Expand Down
7 changes: 5 additions & 2 deletions unirec/unirec++/outputInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -116,6 +117,8 @@ void UnirecOutputInterface::changeTemplate(const std::string& templateFields)
"created.");
}
m_unirecRecord = createUnirecRecord();

m_isInitialized = true;
}

UnirecRecord UnirecOutputInterface::createUnirecRecord(size_t maxVariableFieldsSize)
Expand Down
Loading