]> sigrok.org Git - pulseview.git/commitdiff
Use SignalBase instead of LogicSignal for decoders
authorSoeren Apel <redacted>
Tue, 16 Aug 2016 19:30:46 +0000 (21:30 +0200)
committerUwe Hermann <redacted>
Thu, 18 Aug 2016 22:36:03 +0000 (00:36 +0200)
pv/data/decode/decoder.cpp
pv/data/decode/decoder.hpp
pv/data/decoderstack.cpp
pv/session.cpp
pv/view/decodetrace.cpp

index bd1d307fb5d00006bb4aa01d611d37467c681b82..3b75f88482e6ec3bc5613471f3dfde9d40a826e1 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "decoder.hpp"
 
-#include <pv/view/logicsignal.hpp>
+#include <pv/data/signalbase.hpp>
 
 using std::set;
 using std::map;
@@ -63,14 +63,14 @@ void Decoder::show(bool show)
        shown_ = show;
 }
 
-const map<const srd_channel*, shared_ptr<view::LogicSignal> >&
+const map<const srd_channel*, shared_ptr<data::SignalBase> >&
 Decoder::channels() const
 {
        return channels_;
 }
 
 void Decoder::set_channels(std::map<const srd_channel*,
-       std::shared_ptr<view::LogicSignal> > channels)
+       std::shared_ptr<data::SignalBase> > channels)
 {
        channels_ = channels;
 }
@@ -103,9 +103,9 @@ set< shared_ptr<pv::data::Logic> > Decoder::get_data()
 {
        set< shared_ptr<pv::data::Logic> > data;
        for (const auto& channel : channels_) {
-               shared_ptr<view::LogicSignal> signal(channel.second);
-               assert(signal);
-               data.insert(signal->logic_data());
+               shared_ptr<data::SignalBase> 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<view::LogicSignal> signal(channel.second);
-               GVariant *const gvar = g_variant_new_int32(
-                       signal->base()->index());
+               shared_ptr<data::SignalBase> 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);
        }
index 2d9fcc639591a5226101f40eb8ded32911447dbf..105c6f744b0cf897df19e64d7237a06ddf50fb67 100644 (file)
@@ -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<const srd_channel*,
-               std::shared_ptr<view::LogicSignal> >& channels() const;
+               std::shared_ptr<data::SignalBase> >& channels() const;
        void set_channels(std::map<const srd_channel*,
-               std::shared_ptr<view::LogicSignal> > channels);
+               std::shared_ptr<data::SignalBase> > channels);
 
        const std::map<std::string, GVariant*>& options() const;
 
@@ -77,7 +74,7 @@ private:
 
        bool shown_;
 
-       std::map<const srd_channel*, std::shared_ptr<pv::view::LogicSignal> >
+       std::map<const srd_channel*, std::shared_ptr<pv::data::SignalBase> >
                channels_;
        std::map<std::string, GVariant*> options_;
 };
index d4daa5902a1d2a47d9f727da8dda74c5c6f5ef9c..6f1eb1925dc3e34fe59e35e3343cb5f0e93e7fd0 100644 (file)
@@ -191,7 +191,7 @@ void DecoderStack::clear()
 
 void DecoderStack::begin_decode()
 {
-       shared_ptr<pv::view::LogicSignal> logic_signal;
+       shared_ptr<pv::data::SignalBase> signalbase;
        shared_ptr<pv::data::Logic> 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<decode::Decoder> &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)
index a61224048b018701cad13b891db4baf00a50a8b7..99dca2157e96641ed0fdbf7dd3100749dd35f963 100644 (file)
@@ -275,7 +275,7 @@ const unordered_set< shared_ptr<view::Signal> > Session::signals() const
 #ifdef ENABLE_DECODE
 bool Session::add_decoder(srd_decoder *const dec)
 {
-       map<const srd_channel*, shared_ptr<view::LogicSignal> > channels;
+       map<const srd_channel*, shared_ptr<data::SignalBase> > channels;
        shared_ptr<data::DecoderStack> 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<view::Signal> s : signals_) {
-                               shared_ptr<view::LogicSignal> l =
-                                       dynamic_pointer_cast<view::LogicSignal>(s);
-                               if (l && QString::fromUtf8(pdch->name).
-                                       toLower().contains(
-                                       s->base()->name().toLower()))
-                                       channels[pdch] = l;
+                       for (shared_ptr<data::SignalBase> b : signalbases_) {
+                               if (b->type() == ChannelType::LOGIC) {
+                                       if (QString::fromUtf8(pdch->name).toLower().
+                                               contains(b->name().toLower()))
+                                               channels[pdch] = b;
+                               }
                        }
 
                assert(decoder_stack);
index 2d9a6bf82227a3b50f59c3fa746a216fcc5e3ef5..b4201dd9c022005ce50d673c9ebc6747ee6c6d0a 100644 (file)
@@ -50,7 +50,7 @@ extern "C" {
 #include <pv/data/logic.hpp>
 #include <pv/data/logicsegment.hpp>
 #include <pv/data/decode/annotation.hpp>
-#include <pv/view/logicsignal.hpp>
+#include <pv/view/signal.hpp>
 #include <pv/view/view.hpp>
 #include <pv/view/viewport.hpp>
 #include <pv/widgets/decodergroupbox.hpp>
@@ -604,7 +604,7 @@ void DecodeTrace::draw_unresolved_period(QPainter &p, int h, int left,
        assert(decoder_stack_); 
 
        shared_ptr<Logic> data;
-       shared_ptr<LogicSignal> logic_signal;
+       shared_ptr<data::SignalBase> signalbase;
 
        const list< shared_ptr<Decoder> > &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<Decoder> &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<view::Signal> &s : sig_list) {
                assert(s);
-               if (dynamic_pointer_cast<LogicSignal>(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<data::decode::Decoder> &dec
 {
        assert(dec);
 
-       map<const srd_channel*, shared_ptr<LogicSignal> > channel_map;
+       map<const srd_channel*, shared_ptr<data::SignalBase> > channel_map;
 
        const unordered_set< shared_ptr<Signal> > sigs(session_.signals());
 
@@ -892,14 +892,13 @@ void DecodeTrace::commit_decoder_channels(shared_ptr<data::decode::Decoder> &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<void*>();
 
                for (shared_ptr<Signal> sig : sigs)
-                       if (sig.get() == selection) {
-                               channel_map[s.pdch_] =
-                                       dynamic_pointer_cast<LogicSignal>(sig);
+                       if (sig->base().get() == selection) {
+                               channel_map[s.pdch_] = sig->base();
                                break;
                        }
        }