From: Soeren Apel Date: Sun, 22 Dec 2019 22:45:23 +0000 (+0100) Subject: Internal decoder class handling refactoring X-Git-Url: http://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=cbb2e4da8042495531b406f745ee9d9e20448ef6 Internal decoder class handling refactoring --- diff --git a/pv/data/decode/decoder.cpp b/pv/data/decode/decoder.cpp index 14d298d2..19f11399 100644 --- a/pv/data/decode/decoder.cpp +++ b/pv/data/decode/decoder.cpp @@ -37,7 +37,7 @@ namespace data { namespace decode { Decoder::Decoder(const srd_decoder *const dec) : - decoder_(dec), + srd_decoder_(dec), shown_(true), decoder_inst_(nullptr) { @@ -59,12 +59,12 @@ Decoder::~Decoder() const srd_decoder* Decoder::decoder() const { - return decoder_; + return srd_decoder_; } const char* Decoder::name() const { - return decoder_->name; + return srd_decoder_->name; } bool Decoder::shown() const @@ -144,7 +144,7 @@ srd_decoder_inst* Decoder::create_decoder_inst(srd_session *session) if (decoder_inst_) qDebug() << "WARNING: previous decoder instance" << decoder_inst_ << "exists"; - decoder_inst_ = srd_inst_new(session, decoder_->id, opt_hash); + decoder_inst_ = srd_inst_new(session, srd_decoder_->id, opt_hash); g_hash_table_destroy(opt_hash); if (!decoder_inst_) diff --git a/pv/data/decode/decoder.hpp b/pv/data/decode/decoder.hpp index bc1673c9..282cfe55 100644 --- a/pv/data/decode/decoder.hpp +++ b/pv/data/decode/decoder.hpp @@ -101,7 +101,7 @@ public: const DecodeBinaryClassInfo* get_binary_class(uint32_t id) const; private: - const srd_decoder *const decoder_; + const srd_decoder* const srd_decoder_; bool shown_; diff --git a/pv/data/decode/row.cpp b/pv/data/decode/row.cpp index a424881a..12951556 100644 --- a/pv/data/decode/row.cpp +++ b/pv/data/decode/row.cpp @@ -17,6 +17,7 @@ * along with this program; if not, see . */ +#include "decoder.hpp" #include "row.hpp" #include @@ -31,31 +32,31 @@ Row::Row() : { } -Row::Row(int index, const srd_decoder *decoder, const srd_decoder_annotation_row *row) : +Row::Row(int index, const Decoder* decoder, const srd_decoder_annotation_row* row) : index_(index), decoder_(decoder), row_(row) { } -const srd_decoder* Row::decoder() const +const Decoder* Row::decoder() const { return decoder_; } -const srd_decoder_annotation_row* Row::row() const +const srd_decoder_annotation_row* Row::srd_row() const { return row_; } const QString Row::title() const { - if (decoder_ && decoder_->name && row_ && row_->desc) + if (decoder_ && decoder_->name() && row_ && row_->desc) return QString("%1: %2") - .arg(QString::fromUtf8(decoder_->name), + .arg(QString::fromUtf8(decoder_->name()), QString::fromUtf8(row_->desc)); - if (decoder_ && decoder_->name) - return QString::fromUtf8(decoder_->name); + if (decoder_ && decoder_->name()) + return QString::fromUtf8(decoder_->name()); if (row_ && row_->desc) return QString::fromUtf8(row_->desc); return QString(); @@ -73,15 +74,15 @@ int Row::index() const return index_; } -bool Row::operator<(const Row &other) const +bool Row::operator<(const Row& other) const { return (decoder_ < other.decoder_) || (decoder_ == other.decoder_ && row_ < other.row_); } -bool Row::operator==(const Row &other) const +bool Row::operator==(const Row& other) const { - return ((decoder_ == other.decoder()) && (row_ == other.row())); + return ((decoder_ == other.decoder()) && (row_ == other.srd_row())); } } // namespace decode diff --git a/pv/data/decode/row.hpp b/pv/data/decode/row.hpp index 8486c507..25e6fcc4 100644 --- a/pv/data/decode/row.hpp +++ b/pv/data/decode/row.hpp @@ -31,28 +31,30 @@ namespace pv { namespace data { namespace decode { +class Decoder; + class Row { public: Row(); - Row(int index, const srd_decoder *decoder, - const srd_decoder_annotation_row *row = nullptr); + Row(int index, const Decoder* decoder, + const srd_decoder_annotation_row* row = nullptr); - const srd_decoder* decoder() const; - const srd_decoder_annotation_row* row() const; + const Decoder* decoder() const; + const srd_decoder_annotation_row* srd_row() const; const QString title() const; const QString class_name() const; int index() const; - bool operator<(const Row &other) const; - bool operator==(const Row &other) const; + bool operator<(const Row& other) const; + bool operator==(const Row& other) const; private: int index_; - const srd_decoder *decoder_; - const srd_decoder_annotation_row *row_; + const Decoder* decoder_; + const srd_decoder_annotation_row* row_; }; } // namespace decode diff --git a/pv/data/decodesignal.cpp b/pv/data/decodesignal.cpp index 2e9e38b8..593af02f 100644 --- a/pv/data/decodesignal.cpp +++ b/pv/data/decodesignal.cpp @@ -236,12 +236,11 @@ void DecodeSignal::begin_decode() (srd_decoder_annotation_row *)l->data; assert(ann_row); - const Row row(row_index++, decc, ann_row); + const Row row(row_index++, dec.get(), ann_row); for (const GSList *ll = ann_row->ann_classes; ll; ll = ll->next) - class_rows_[make_pair(decc, - GPOINTER_TO_INT(ll->data))] = row; + class_rows_[make_pair(decc, GPOINTER_TO_INT(ll->data))] = row; } } @@ -454,7 +453,7 @@ int64_t DecodeSignal::get_decoded_sample_count(uint32_t segment_id, return result; } -vector DecodeSignal::get_rows() const +vector DecodeSignal::get_rows(bool visible_only) const { lock_guard lock(output_mutex_); @@ -462,20 +461,23 @@ vector DecodeSignal::get_rows() const for (const shared_ptr& dec : stack_) { assert(dec); + if (visible_only && !dec->shown()) + continue; + const srd_decoder *const decc = dec->decoder(); assert(dec->decoder()); int row_index = 0; // Add a row for the decoder if it doesn't have a row list if (!decc->annotation_rows) - rows.emplace_back(row_index++, decc); + rows.emplace_back(row_index++, dec.get()); // Add the decoder rows for (const GSList *l = decc->annotation_rows; l; l = l->next) { const srd_decoder_annotation_row *const ann_row = (srd_decoder_annotation_row *)l->data; assert(ann_row); - rows.emplace_back(row_index++, decc, ann_row); + rows.emplace_back(row_index++, dec.get(), ann_row); } } @@ -1383,7 +1385,7 @@ void DecodeSignal::create_decode_segment() int row_index = 0; // Add a row for the decoder if it doesn't have a row list if (!decc->annotation_rows) - (segments_.back().annotation_rows)[Row(row_index++, decc)] = + (segments_.back().annotation_rows)[Row(row_index++, dec.get())] = decode::RowData(); // Add the decoder rows @@ -1392,11 +1394,10 @@ void DecodeSignal::create_decode_segment() (srd_decoder_annotation_row *)l->data; assert(ann_row); - const Row row(row_index++, decc, ann_row); + const Row row(row_index++, dec.get(), ann_row); // Add a new empty row data object - (segments_.back().annotation_rows)[row] = - decode::RowData(); + (segments_.back().annotation_rows)[row] = decode::RowData(); } } @@ -1442,7 +1443,9 @@ void DecodeSignal::annotation_callback(srd_proto_data *pdata, void *decode_signa row_iter = ds->segments_.at(ds->current_segment_id_).annotation_rows.find((*r).second); else { // Failing that, use the decoder as a key - row_iter = ds->segments_.at(ds->current_segment_id_).annotation_rows.find(Row(0, decc)); + for (const shared_ptr& dec : ds->decoder_stack()) + if (dec->decoder() == decc) + row_iter = ds->segments_.at(ds->current_segment_id_).annotation_rows.find(Row(0, dec.get())); } if (row_iter == ds->segments_.at(ds->current_segment_id_).annotation_rows.end()) { diff --git a/pv/data/decodesignal.hpp b/pv/data/decodesignal.hpp index 9a112e9b..f3ef9dfa 100644 --- a/pv/data/decodesignal.hpp +++ b/pv/data/decodesignal.hpp @@ -139,7 +139,7 @@ public: int64_t get_decoded_sample_count(uint32_t segment_id, bool include_processing) const; - vector get_rows() const; + vector get_rows(bool visible_only=false) const; uint64_t get_annotation_count(const decode::Row &row, uint32_t segment_id) const; diff --git a/pv/views/trace/decodetrace.cpp b/pv/views/trace/decodetrace.cpp index e3c1185e..cc4be9e3 100644 --- a/pv/views/trace/decodetrace.cpp +++ b/pv/views/trace/decodetrace.cpp @@ -1094,7 +1094,7 @@ void DecodeTrace::export_annotations(vector *annotations) const QString out_text = format; out_text = out_text.replace("%s", sample_range); out_text = out_text.replace("%d", - quote + QString::fromUtf8(ann.row()->decoder()->name) + quote); + quote + QString::fromUtf8(ann.row()->decoder()->name()) + quote); out_text = out_text.replace("%c", class_name); out_text = out_text.replace("%1", first_ann_text); out_text = out_text.replace("%a", all_ann_text);