From 7cee56f37001640b88f4ac1249624c9c9758e844 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sun, 22 Feb 2015 20:52:20 +0100 Subject: Replace pointers by shared_ptr in all flowgraph --- src/EtiReader.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/EtiReader.cpp') diff --git a/src/EtiReader.cpp b/src/EtiReader.cpp index fe54f55..7e0df72 100644 --- a/src/EtiReader.cpp +++ b/src/EtiReader.cpp @@ -2,7 +2,7 @@ Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Her Majesty the Queen in Right of Canada (Communications Research Center Canada) - Copyright (C) 2014 + Copyright (C) 2014, 2015 Matthias P. Braendli, matthias.braendli@mpb.li http://opendigitalradio.org @@ -34,6 +34,7 @@ #include #include +using namespace boost; enum ETI_READER_STATE { EtiReaderStateNbFrame, @@ -69,9 +70,6 @@ EtiReader::~EtiReader() // if (myFicSource != NULL) { // delete myFicSource; // } -// for (unsigned i = 0; i < mySources.size(); ++i) { -// delete mySources[i]; -// } } @@ -93,13 +91,13 @@ unsigned EtiReader::getFp() } -const std::vector& EtiReader::getSubchannels() +const std::vector >& EtiReader::getSubchannels() { return mySources; } -int EtiReader::process(Buffer* dataIn) +int EtiReader::process(const Buffer* dataIn) { PDEBUG("EtiReader::process(dataIn: %p)\n", dataIn); PDEBUG(" state: %u\n", state); @@ -171,13 +169,12 @@ int EtiReader::process(Buffer* dataIn) (memcmp(&eti_stc[0], in, 4 * eti_fc.NST))) { PDEBUG("New stc!\n"); eti_stc.resize(eti_fc.NST); - for (unsigned i = 0; i < mySources.size(); ++i) { - delete mySources[i]; - } - mySources.resize(eti_fc.NST); memcpy(&eti_stc[0], in, 4 * eti_fc.NST); + + mySources.clear(); for (unsigned i = 0; i < eti_fc.NST; ++i) { - mySources[i] = new SubchannelSource(eti_stc[i]); + mySources.push_back(shared_ptr( + new SubchannelSource(eti_stc[i]))); PDEBUG("Sstc %u:\n", i); PDEBUG(" Stc%i.scid: %i\n", i, eti_stc[i].SCID); PDEBUG(" Stc%i.sad: %u\n", i, eti_stc[i].getStartAddress()); -- cgit v1.2.3 From e2d14763b766b2154940a47acb3dffb65d0973d3 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Fri, 10 Apr 2015 16:39:14 +0200 Subject: Add validity check for eti_fc --- src/EtiReader.cpp | 8 ++++++++ src/EtiReader.h | 1 + 2 files changed, 9 insertions(+) (limited to 'src/EtiReader.cpp') diff --git a/src/EtiReader.cpp b/src/EtiReader.cpp index 7e0df72..0e4182d 100644 --- a/src/EtiReader.cpp +++ b/src/EtiReader.cpp @@ -61,6 +61,7 @@ EtiReader::EtiReader(struct modulator_offset_config& modconf, PDEBUG("EtiReader::EtiReader()\n"); myCurrentFrame = 0; + eti_fc_valid = false; } EtiReader::~EtiReader() @@ -81,12 +82,18 @@ FicSource* EtiReader::getFic() unsigned EtiReader::getMode() { + if (not eti_fc_valid) { + throw std::runtime_error("Trying to access Mode before it is ready!"); + } return eti_fc.MID; } unsigned EtiReader::getFp() { + if (not eti_fc_valid) { + throw std::runtime_error("Trying to access FP before it is ready!"); + } return eti_fc.FP; } @@ -144,6 +151,7 @@ int EtiReader::process(const Buffer* dataIn) return dataIn->getLength() - input_size; } memcpy(&eti_fc, in, 4); + eti_fc_valid = true; input_size -= 4; framesize -= 4; in += 4; diff --git a/src/EtiReader.h b/src/EtiReader.h index 136bd1c..b893f01 100644 --- a/src/EtiReader.h +++ b/src/EtiReader.h @@ -91,6 +91,7 @@ private: size_t myCurrentFrame; bool time_ext_enabled; unsigned long timestamp_seconds; + bool eti_fc_valid; }; -- cgit v1.2.3