]> sigrok.org Git - pulseview.git/commitdiff
Modified Decode to only use LogicSignals
authorJoel Holdsworth <redacted>
Sun, 20 Oct 2013 10:15:53 +0000 (11:15 +0100)
committerJoel Holdsworth <redacted>
Wed, 23 Oct 2013 23:12:24 +0000 (00:12 +0100)
pv/data/decoder.cpp
pv/data/decoder.h
pv/dialogs/decoder.cpp
pv/dialogs/decoder.h
pv/mainwindow.cpp
pv/sigsession.cpp
pv/sigsession.h
test/data/decoder.cpp

index d8a538cbec9368ddffde92d474e2478d9027adbc..923140397ef528d02b9bb2ea84f2849f2d8573d0 100644 (file)
@@ -45,7 +45,7 @@ const int64_t Decoder::DecodeChunkLength = 4096;
 
 Decoder::Decoder(const srd_decoder *const dec,
        std::map<const srd_probe*,
-               boost::shared_ptr<pv::view::Signal> > probes,
+               boost::shared_ptr<pv::view::LogicSignal> > probes,
        GHashTable *options) :
        _decoder(dec),
        _probes(probes),
@@ -93,12 +93,9 @@ void Decoder::begin_decode()
        // We get the logic data of the first probe in the list.
        // This works because we are currently assuming all
        // LogicSignals have the same data/snapshot
-       shared_ptr<pv::view::Signal> sig = (*_probes.begin()).second;
+       shared_ptr<pv::view::LogicSignal> sig = (*_probes.begin()).second;
        assert(sig);
-       const pv::view::LogicSignal *const l =
-               dynamic_cast<pv::view::LogicSignal*>(sig.get());
-       assert(l);
-       shared_ptr<data::Logic> data = l->data();
+       shared_ptr<data::Logic> data = sig->data();
 
        _decode_thread = boost::thread(&Decoder::decode_proc, this,
                data);
@@ -139,7 +136,7 @@ bool Decoder::init_decoder()
        GHashTable *probes = g_hash_table_new_full(g_str_hash,
                g_str_equal, g_free, (GDestroyNotify)g_variant_unref);
 
-       for(map<const srd_probe*, shared_ptr<view::Signal> >::
+       for(map<const srd_probe*, shared_ptr<view::LogicSignal> >::
                const_iterator i = _probes.begin();
                i != _probes.end(); i++)
        {
index 264920a723422c9bf51f5e1fb6947e9f5e03f759..cdeb7e7a59adc0a449937a7df5ec51a02d73f601 100644 (file)
@@ -41,7 +41,7 @@ struct srd_session;
 namespace pv {
 
 namespace view {
-class Signal;
+class LogicSignal;
 
 namespace decode {
 class Annotation;
@@ -65,7 +65,7 @@ private:
 public:
        Decoder(const srd_decoder *const decoder,
                std::map<const srd_probe*,
-                       boost::shared_ptr<pv::view::Signal> > probes,
+                       boost::shared_ptr<pv::view::LogicSignal> > probes,
                GHashTable *options);
 
        virtual ~Decoder();
@@ -92,7 +92,7 @@ signals:
 
 private:
        const srd_decoder *const _decoder;
-       std::map<const srd_probe*, boost::shared_ptr<view::Signal> >
+       std::map<const srd_probe*, boost::shared_ptr<view::LogicSignal> >
                _probes;
        GHashTable *_options;
 
index 88ccf76021f9acc7b7888695257cacc6f673c684..07375f649b35a883efa8b65991f5f1d300d8a88c 100644 (file)
@@ -40,7 +40,8 @@ namespace pv {
 namespace dialogs {
 
 Decoder::Decoder(QWidget *parent, const srd_decoder *decoder,
-       const vector< shared_ptr<view::Signal> > &sigs, GHashTable *options) :
+       const vector< shared_ptr<view::LogicSignal> > &sigs,
+       GHashTable *options) :
        QDialog(parent),
        _sigs(sigs),
        _binding(decoder, options),
@@ -121,10 +122,11 @@ QComboBox* Decoder::create_probe_selector(
        selector->setCurrentIndex(0);
 
        for(size_t i = 0; i < _sigs.size(); i++) {
-               const shared_ptr<view::Signal> s(_sigs[i]);
+               const shared_ptr<view::LogicSignal> s(_sigs[i]);
                assert(s);
 
-               if (s->enabled()) {
+               if (s->enabled())
+               {
                        selector->addItem(s->get_name(), qVariantFromValue(i));
                        if(s->get_name().toLower().contains(
                                QString(name).toLower()))
@@ -135,9 +137,9 @@ QComboBox* Decoder::create_probe_selector(
        return selector;
 }
 
-map<const srd_probe*, shared_ptr<view::Signal> > Decoder::get_probes()
+map<const srd_probe*, shared_ptr<view::LogicSignal> > Decoder::get_probes()
 {
-       map<const srd_probe*, shared_ptr<view::Signal> > probe_map;
+       map<const srd_probe*, shared_ptr<view::LogicSignal> > probe_map;
        for(map<const srd_probe*, QComboBox*>::const_iterator i =
                _probe_selector_map.begin();
                i != _probe_selector_map.end(); i++)
@@ -146,12 +148,8 @@ map<const srd_probe*, shared_ptr<view::Signal> > Decoder::get_probes()
                const int probe_index =
                        combo->itemData(combo->currentIndex()).value<int>();
                if(probe_index >= 0) {
-                       shared_ptr<view::Signal> sig = _sigs[probe_index];
-                       if(dynamic_cast<pv::view::LogicSignal*>(sig.get()))
-                               probe_map[(*i).first] = sig;
-                       else
-                               qDebug() << "Currently only logic signals "
-                                       "are supported for decoding";
+                       shared_ptr<view::LogicSignal> sig = _sigs[probe_index];
+                       probe_map[(*i).first] = sig;
                }
        }
 
index 56f02aa4480bf627d52d66883ed6cfc2ae8940ec..926d015b6a6f953448339a7d0f7d6556d7083518 100644 (file)
@@ -40,7 +40,7 @@ struct srd_decoder;
 namespace pv {
 
 namespace view {
-class Signal;
+class LogicSignal;
 }
 
 namespace dialogs {
@@ -49,12 +49,12 @@ class Decoder : public QDialog
 {
 public:
        Decoder(QWidget *parent, const srd_decoder *decoder,
-               const std::vector< boost::shared_ptr<view::Signal> > &sigs,
+               const std::vector< boost::shared_ptr<view::LogicSignal> > &sigs,
                GHashTable *options);
 
        void accept();
 
-       std::map<const srd_probe*, boost::shared_ptr<view::Signal> >
+       std::map<const srd_probe*, boost::shared_ptr<view::LogicSignal> >
                get_probes();
 
 private:
@@ -62,7 +62,7 @@ private:
                QWidget *parent, const char *name);
 
 private:
-       const std::vector< boost::shared_ptr<view::Signal> > &_sigs;
+       const std::vector< boost::shared_ptr<view::LogicSignal> > &_sigs;
 
        std::map<const srd_probe*, QComboBox*> _probe_selector_map;
 
index f7b8612054ff058997a8cd0f2cd3f75b8310f5a0..183e841e804c3c6f48d37949268ec3227a0c70be 100644 (file)
@@ -41,6 +41,7 @@
 #include "dialogs/connect.h"
 #include "dialogs/decoder.h"
 #include "toolbars/samplingbar.h"
+#include "view/logicsignal.h"
 #include "view/view.h"
 
 /* __STDC_FORMAT_MACROS is required for PRIu64 and friends (in C++). */
@@ -375,13 +376,21 @@ void MainWindow::add_decoder(QObject *action)
                (srd_decoder*)((QAction*)action)->data().value<void*>();
        assert(dec);
 
-       const std::vector< boost::shared_ptr<view::Signal> > &sigs =
+       vector< shared_ptr<view::LogicSignal> > logic_sigs;
+       const vector< shared_ptr<view::Signal> > &sigs =
                _session.get_signals();
+       BOOST_FOREACH(shared_ptr<view::Signal> s, sigs) {
+               assert(s);
+               shared_ptr<view::LogicSignal> l =
+                       dynamic_pointer_cast<view::LogicSignal>(s);
+               if (l)
+                       logic_sigs.push_back(l);
+       }
 
        GHashTable *const options = g_hash_table_new_full(g_str_hash,
                g_str_equal, g_free, (GDestroyNotify)g_variant_unref);
 
-       dialogs::Decoder dlg(this, dec, sigs, options);
+       dialogs::Decoder dlg(this, dec, logic_sigs, options);
        if(dlg.exec() != QDialog::Accepted) {
                g_hash_table_destroy(options);
                return;
index e81d36051fa068e361eafb01c18ef3aeee02caaa..aadaf45011451bc21bad01045f7781347cd1aaaa 100644 (file)
@@ -197,7 +197,7 @@ boost::shared_ptr<data::Logic> SigSession::get_data()
 
 bool SigSession::add_decoder(srd_decoder *const dec,
        std::map<const srd_probe*,
-               boost::shared_ptr<view::Signal> > probes,
+               boost::shared_ptr<view::LogicSignal> > probes,
        GHashTable *options)
 {
        try
index 499814cadbb4c223294382aa520c19d80bc9a091..5c69a9bc3a1aa428982ce64b15bf240bda08d322 100644 (file)
@@ -50,6 +50,7 @@ class LogicSnapshot;
 
 namespace view {
 class DecodeSignal;
+class LogicSignal;
 class Signal;
 }
 
@@ -95,7 +96,7 @@ public:
 
        bool add_decoder(srd_decoder *const dec,
                std::map<const srd_probe*,
-                       boost::shared_ptr<view::Signal> > probes,
+                       boost::shared_ptr<view::LogicSignal> > probes,
                GHashTable *options);
 
        std::vector< boost::shared_ptr<view::DecodeSignal> >
index 4a74c417e0d4ac467dfbc7de2b5ac13448b09aa7..641064da23f56dd8786f40a3c853a54bc9f6f33b 100644 (file)
@@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE(TwoDecoder)
                srd_decoder *const dec = (struct srd_decoder*)l->data;
                BOOST_REQUIRE(dec);
 
-               map<const srd_probe*, shared_ptr<pv::view::Signal> > probes;
+               map<const srd_probe*, shared_ptr<pv::view::LogicSignal> > probes;
                BOOST_CHECK (ss.add_decoder(dec, probes,
                        g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
                                (GDestroyNotify)g_variant_unref)));