2 * This file is part of the PulseView project.
4 * Copyright (C) 2017 Soeren Apel <soeren@apelpie.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "logicsegment.hpp"
22 #include "decodesignal.hpp"
23 #include "signaldata.hpp"
25 #include <pv/binding/decoder.hpp>
26 #include <pv/data/decode/decoder.hpp>
27 #include <pv/data/decode/row.hpp>
28 #include <pv/data/decoderstack.hpp>
29 #include <pv/session.hpp>
31 using std::make_shared;
32 using std::shared_ptr;
33 using pv::data::decode::Decoder;
34 using pv::data::decode::Row;
39 DecodeSignal::DecodeSignal(shared_ptr<pv::data::DecoderStack> decoder_stack) :
40 SignalBase(nullptr, SignalBase::DecodeChannel),
41 decoder_stack_(decoder_stack)
43 set_name(QString::fromUtf8(decoder_stack_->stack().front()->decoder()->name));
45 connect(decoder_stack_.get(), SIGNAL(new_annotations()),
46 this, SLOT(on_new_annotations()));
49 DecodeSignal::~DecodeSignal()
53 bool DecodeSignal::is_decode_signal() const
58 shared_ptr<pv::data::DecoderStack> DecodeSignal::decoder_stack() const
60 return decoder_stack_;
63 const list< shared_ptr<Decoder> >& DecodeSignal::decoder_stack_list() const
65 return decoder_stack_->stack();
68 void DecodeSignal::stack_decoder(srd_decoder *decoder)
71 assert(decoder_stack);
72 decoder_stack_->push(make_shared<data::decode::Decoder>(decoder));
73 decoder_stack_->begin_decode();
76 void DecodeSignal::remove_decoder(int index)
78 decoder_stack_->remove(index);
79 decoder_stack_->begin_decode();
82 bool DecodeSignal::toggle_decoder_visibility(int index)
84 const list< shared_ptr<Decoder> > stack(decoder_stack_->stack());
86 auto iter = stack.cbegin();
87 for (int i = 0; i < index; i++, iter++)
88 assert(iter != stack.end());
90 shared_ptr<Decoder> dec = *iter;
92 // Toggle decoder visibility
95 state = !dec->shown();
102 QString DecodeSignal::error_message() const
104 return decoder_stack_->error_message();
107 vector<Row> DecodeSignal::visible_rows() const
109 return decoder_stack_->get_visible_rows();
112 void DecodeSignal::get_annotation_subset(
113 vector<pv::data::decode::Annotation> &dest,
114 const decode::Row &row, uint64_t start_sample,
115 uint64_t end_sample) const
117 return decoder_stack_->get_annotation_subset(dest, row,
118 start_sample, end_sample);
121 void DecodeSignal::on_new_annotations()
123 // Forward the signal to the frontend