summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/edi/STIWriter.cpp44
-rw-r--r--lib/edi/STIWriter.hpp11
-rw-r--r--lib/edi/common.hpp1
3 files changed, 21 insertions, 35 deletions
diff --git a/lib/edi/STIWriter.cpp b/lib/edi/STIWriter.cpp
index ea3bfe8..b0e2bc2 100644
--- a/lib/edi/STIWriter.cpp
+++ b/lib/edi/STIWriter.cpp
@@ -34,6 +34,11 @@ namespace EdiDecoder {
using namespace std;
+STIWriter::STIWriter(std::function<void(sti_frame_t&&)>&& frame_callback) :
+ m_frame_callback(move(frame_callback))
+{
+}
+
void STIWriter::update_protocol(
const std::string& proto,
uint16_t major,
@@ -46,16 +51,6 @@ void STIWriter::update_protocol(
}
}
-void STIWriter::reinit()
-{
- m_proto_valid = false;
- m_management_data_valid = false;
- m_stat_valid = false;
- m_time_valid = false;
- m_payload_valid = false;
- m_audio_levels = audio_level_data();
- m_stiFrame.frame.clear();
-}
void STIWriter::update_stat(uint8_t stat, uint16_t spid)
{
@@ -127,26 +122,19 @@ void STIWriter::assemble()
// TODO check time validity
- // Do copies so as to preserve existing payload data
- m_stiFrame.frame = m_payload.istd;
- m_stiFrame.audio_levels = m_audio_levels;
- m_stiFrame.version_data = m_version_data;
- m_stiFrame.timestamp.seconds = m_seconds;
- m_stiFrame.timestamp.utco = m_utco;
- m_stiFrame.timestamp.tsta = m_management_data.tsta;
-}
+ sti_frame_t stiFrame;
+ stiFrame.frame = move(m_payload.istd);
+ stiFrame.timestamp.seconds = m_seconds;
+ stiFrame.timestamp.utco = m_utco;
+ stiFrame.timestamp.tsta = m_management_data.tsta;
-sti_frame_t STIWriter::getFrame()
-{
- if (m_stiFrame.frame.empty()) {
- return {};
- }
+ m_frame_callback(move(stiFrame));
- sti_frame_t sti;
- swap(sti, m_stiFrame);
- reinit();
- return sti;
+ m_proto_valid = false;
+ m_management_data_valid = false;
+ m_stat_valid = false;
+ m_time_valid = false;
+ m_payload_valid = false;
}
}
-
diff --git a/lib/edi/STIWriter.hpp b/lib/edi/STIWriter.hpp
index 16cbfe8..fc08e97 100644
--- a/lib/edi/STIWriter.hpp
+++ b/lib/edi/STIWriter.hpp
@@ -23,6 +23,7 @@
#include "common.hpp"
#include "STIDecoder.hpp"
#include <cstdint>
+#include <functional>
#include <string>
#include <vector>
#include <list>
@@ -38,6 +39,9 @@ struct sti_frame_t {
class STIWriter : public STIDataCollector {
public:
+ // The callback gets called for every STI frame that gets assembled
+ STIWriter(std::function<void(sti_frame_t&&)>&& frame_callback);
+
// Tell the ETIWriter what EDI protocol we receive in *ptr.
// This is not part of the ETI data, but is used as check
virtual void update_protocol(
@@ -59,12 +63,8 @@ class STIWriter : public STIDataCollector {
virtual void update_odr_version(const odr_version_data& data);
virtual void assemble(void);
-
- // Return the assembled frame or an empty frame if not ready
- sti_frame_t getFrame();
-
private:
- void reinit(void);
+ std::function<void(sti_frame_t&&)> m_frame_callback;
bool m_proto_valid = false;
@@ -84,7 +84,6 @@ class STIWriter : public STIDataCollector {
audio_level_data m_audio_levels;
odr_version_data m_version_data;
- sti_frame_t m_stiFrame;
};
}
diff --git a/lib/edi/common.hpp b/lib/edi/common.hpp
index 5d15f8d..8252a7a 100644
--- a/lib/edi/common.hpp
+++ b/lib/edi/common.hpp
@@ -46,7 +46,6 @@ struct frame_timestamp_t {
static frame_timestamp_t from_unix_epoch(std::time_t time, uint32_t tai_utc_offset, uint32_t tsta);
};
-
struct decode_state_t {
decode_state_t(bool _complete, size_t _num_bytes_consumed) :
complete(_complete), num_bytes_consumed(_num_bytes_consumed) {}