]> sigrok.org Git - pulseview.git/commitdiff
Internal decoder class handling refactoring
authorSoeren Apel <redacted>
Sun, 22 Dec 2019 22:45:23 +0000 (23:45 +0100)
committerSoeren Apel <redacted>
Mon, 23 Dec 2019 00:04:04 +0000 (01:04 +0100)
pv/data/decode/decoder.cpp
pv/data/decode/decoder.hpp
pv/data/decode/row.cpp
pv/data/decode/row.hpp
pv/data/decodesignal.cpp
pv/data/decodesignal.hpp
pv/views/trace/decodetrace.cpp

index 14d298d24fd41b4835a9d0f9dc8ddc0222949805..19f11399fec78bae58fc809d71bfb6b0aded71d1 100644 (file)
@@ -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_)
index bc1673c97e032cc59ab900cd35cd1a926de7ad6a..282cfe557d0740682ef17d82318ea4d9443463c8 100644 (file)
@@ -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_;
 
index a424881a8ff0c75a2b0615c8c726948b1e648455..12951556390c15f2a0ed5e2e647365cb567fb675 100644 (file)
@@ -17,6 +17,7 @@
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "decoder.hpp"
 #include "row.hpp"
 
 #include <libsigrokdecode/libsigrokdecode.h>
@@ -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 Rowother) const
 {
        return (decoder_ < other.decoder_) ||
                (decoder_ == other.decoder_ && row_ < other.row_);
 }
 
-bool Row::operator==(const Row &other) const
+bool Row::operator==(const Rowother) const
 {
-       return ((decoder_ == other.decoder()) && (row_ == other.row()));
+       return ((decoder_ == other.decoder()) && (row_ == other.srd_row()));
 }
 
 }  // namespace decode
index 8486c5075fe0bd39d09736c750ace8bf5e2109f8..25e6fcc492863f90ac97b2ae23a9a73d3b51a39c 100644 (file)
@@ -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_rowrow = 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 Rowother) const;
+       bool operator==(const Rowother) const;
 
 private:
        int index_;
-       const srd_decoder *decoder_;
-       const srd_decoder_annotation_row *row_;
+       const Decoder* decoder_;
+       const srd_decoder_annotation_rowrow_;
 };
 
 }  // namespace decode
index 2e9e38b842718f5d5c43e56df8d88525b1cf8461..593af02fdd796348aac72d3b621fa13239cffa3f 100644 (file)
@@ -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<Row> DecodeSignal::get_rows() const
+vector<Row> DecodeSignal::get_rows(bool visible_only) const
 {
        lock_guard<mutex> lock(output_mutex_);
 
@@ -462,20 +461,23 @@ vector<Row> DecodeSignal::get_rows() const
 
        for (const shared_ptr<decode::Decoder>& 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<decode::Decoder>& 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()) {
index 9a112e9ba6342183b50a9c8c0678f492593ff27c..f3ef9dfaad15a73fe5147c69dbae844647b4e67c 100644 (file)
@@ -139,7 +139,7 @@ public:
        int64_t get_decoded_sample_count(uint32_t segment_id,
                bool include_processing) const;
 
-       vector<decode::Row> get_rows() const;
+       vector<decode::Row> get_rows(bool visible_only=false) const;
 
        uint64_t get_annotation_count(const decode::Row &row, uint32_t segment_id) const;
 
index e3c1185e75fdcdf853071b09a59871c10d698c46..cc4be9e389671728e7f11f20da22c93808a2292b 100644 (file)
@@ -1094,7 +1094,7 @@ void DecodeTrace::export_annotations(vector<Annotation> *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);