From: Soeren Apel Date: Tue, 16 Aug 2016 19:30:46 +0000 (+0200) Subject: Use SignalBase instead of LogicSignal for decoders X-Git-Tag: pulseview-0.4.0~272 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=04394ded8776d2163c1e815ccc8170b81d76b028;p=pulseview.git Use SignalBase instead of LogicSignal for decoders --- diff --git a/pv/data/decode/decoder.cpp b/pv/data/decode/decoder.cpp index bd1d307f..3b75f884 100644 --- a/pv/data/decode/decoder.cpp +++ b/pv/data/decode/decoder.cpp @@ -25,7 +25,7 @@ #include "decoder.hpp" -#include +#include using std::set; using std::map; @@ -63,14 +63,14 @@ void Decoder::show(bool show) shown_ = show; } -const map >& +const map >& Decoder::channels() const { return channels_; } void Decoder::set_channels(std::map > channels) + std::shared_ptr > channels) { channels_ = channels; } @@ -103,9 +103,9 @@ set< shared_ptr > Decoder::get_data() { set< shared_ptr > data; for (const auto& channel : channels_) { - shared_ptr signal(channel.second); - assert(signal); - data.insert(signal->logic_data()); + shared_ptr b(channel.second); + assert(b); + data.insert(b->logic_data()); } return data; @@ -135,9 +135,8 @@ srd_decoder_inst* Decoder::create_decoder_inst(srd_session *session) const g_str_equal, g_free, (GDestroyNotify)g_variant_unref); for (const auto& channel : channels_) { - shared_ptr signal(channel.second); - GVariant *const gvar = g_variant_new_int32( - signal->base()->index()); + shared_ptr b(channel.second); + GVariant *const gvar = g_variant_new_int32(b->index()); g_variant_ref_sink(gvar); g_hash_table_insert(channels, channel.first->id, gvar); } diff --git a/pv/data/decode/decoder.hpp b/pv/data/decode/decoder.hpp index 2d9fcc63..105c6f74 100644 --- a/pv/data/decode/decoder.hpp +++ b/pv/data/decode/decoder.hpp @@ -34,13 +34,10 @@ struct srd_session; namespace pv { -namespace view { -class LogicSignal; -} - namespace data { class Logic; +class SignalBase; namespace decode { @@ -57,9 +54,9 @@ public: void show(bool show = true); const std::map >& channels() const; + std::shared_ptr >& channels() const; void set_channels(std::map > channels); + std::shared_ptr > channels); const std::map& options() const; @@ -77,7 +74,7 @@ private: bool shown_; - std::map > + std::map > channels_; std::map options_; }; diff --git a/pv/data/decoderstack.cpp b/pv/data/decoderstack.cpp index d4daa590..6f1eb192 100644 --- a/pv/data/decoderstack.cpp +++ b/pv/data/decoderstack.cpp @@ -191,7 +191,7 @@ void DecoderStack::clear() void DecoderStack::begin_decode() { - shared_ptr logic_signal; + shared_ptr signalbase; shared_ptr data; if (decode_thread_.joinable()) { @@ -241,11 +241,11 @@ void DecoderStack::begin_decode() // We get the logic data of the first channel in the list. // This works because we are currently assuming all - // LogicSignals have the same data/segment + // logic signals have the same data/segment for (const shared_ptr &dec : stack_) if (dec && !dec->channels().empty() && - ((logic_signal = (*dec->channels().begin()).second)) && - ((data = logic_signal->logic_data()))) + ((signalbase = (*dec->channels().begin()).second)) && + ((data = signalbase->logic_data()))) break; if (!data) diff --git a/pv/session.cpp b/pv/session.cpp index a6122404..99dca215 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -275,7 +275,7 @@ const unordered_set< shared_ptr > Session::signals() const #ifdef ENABLE_DECODE bool Session::add_decoder(srd_decoder *const dec) { - map > channels; + map > channels; shared_ptr decoder_stack; try { @@ -294,13 +294,12 @@ bool Session::add_decoder(srd_decoder *const dec) // Auto select the initial channels for (const srd_channel *pdch : all_channels) - for (shared_ptr s : signals_) { - shared_ptr l = - dynamic_pointer_cast(s); - if (l && QString::fromUtf8(pdch->name). - toLower().contains( - s->base()->name().toLower())) - channels[pdch] = l; + for (shared_ptr b : signalbases_) { + if (b->type() == ChannelType::LOGIC) { + if (QString::fromUtf8(pdch->name).toLower(). + contains(b->name().toLower())) + channels[pdch] = b; + } } assert(decoder_stack); diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index 2d9a6bf8..b4201dd9 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -50,7 +50,7 @@ extern "C" { #include #include #include -#include +#include #include #include #include @@ -604,7 +604,7 @@ void DecodeTrace::draw_unresolved_period(QPainter &p, int h, int left, assert(decoder_stack_); shared_ptr data; - shared_ptr logic_signal; + shared_ptr signalbase; const list< shared_ptr > &stack = decoder_stack_->stack(); @@ -613,8 +613,8 @@ void DecodeTrace::draw_unresolved_period(QPainter &p, int h, int left, // LogicSignals have the same data/segment for (const shared_ptr &dec : stack) if (dec && !dec->channels().empty() && - ((logic_signal = (*dec->channels().begin()).second)) && - ((data = logic_signal->logic_data()))) + ((signalbase = (*dec->channels().begin()).second)) && + ((data = signalbase->logic_data()))) break; if (!data || data->logic_segments().empty()) @@ -866,12 +866,12 @@ QComboBox* DecodeTrace::create_channel_selector( for (const shared_ptr &s : sig_list) { assert(s); - if (dynamic_pointer_cast(s) && s->enabled()) { + if (s->base()->type() == sigrok::ChannelType::LOGIC && s->enabled()) { selector->addItem(s->base()->name(), - qVariantFromValue((void*)s.get())); + qVariantFromValue((void*)s->base().get())); if (channel_iter != dec->channels().end() && - (*channel_iter).second == s) + (*channel_iter).second == s->base()) selector->setCurrentIndex( selector->count() - 1); } @@ -884,7 +884,7 @@ void DecodeTrace::commit_decoder_channels(shared_ptr &dec { assert(dec); - map > channel_map; + map > channel_map; const unordered_set< shared_ptr > sigs(session_.signals()); @@ -892,14 +892,13 @@ void DecodeTrace::commit_decoder_channels(shared_ptr &dec if (s.decoder_ != dec) break; - const LogicSignal *const selection = - (LogicSignal*)s.combo_->itemData( + const data::SignalBase *const selection = + (data::SignalBase*)s.combo_->itemData( s.combo_->currentIndex()).value(); for (shared_ptr sig : sigs) - if (sig.get() == selection) { - channel_map[s.pdch_] = - dynamic_pointer_cast(sig); + if (sig->base().get() == selection) { + channel_map[s.pdch_] = sig->base(); break; } }