Renamed pv::data::Decoder to DecoderStack
authorJoel Holdsworth <joel@airwebreathe.org.uk>
Sun, 27 Oct 2013 13:15:16 +0000 (13:15 +0000)
committerJoel Holdsworth <joel@airwebreathe.org.uk>
Sat, 30 Nov 2013 18:12:58 +0000 (18:12 +0000)
13 files changed:
CMakeLists.txt
pv/data/decoder.cpp [deleted file]
pv/data/decoder.h [deleted file]
pv/data/decoderstack.cpp [new file with mode: 0644]
pv/data/decoderstack.h [new file with mode: 0644]
pv/prop/binding/decoderoptions.cpp
pv/prop/binding/decoderoptions.h
pv/sigsession.cpp
pv/view/decodetrace.cpp
pv/view/decodetrace.h
test/CMakeLists.txt
test/data/decoder.cpp [deleted file]
test/data/decoderstack.cpp [new file with mode: 0644]

index 51ba86ef31583d28470e4296cbf3b0b45f4e9649..0f7502a4e744c11c0390fb589e7b1178a787ddc5 100644 (file)
@@ -1,4 +1,4 @@
-##
+
 ## This file is part of the PulseView project.
 ##
 ## Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
@@ -107,7 +107,7 @@ set(pulseview_SOURCES
        pv/sigsession.cpp
        pv/data/analog.cpp
        pv/data/analogsnapshot.cpp
-       pv/data/decoder.cpp
+       pv/data/decoderstack.cpp
        pv/data/logic.cpp
        pv/data/logicsnapshot.cpp
        pv/data/signaldata.cpp
@@ -154,7 +154,7 @@ set(pulseview_SOURCES
 set(pulseview_HEADERS
        pv/mainwindow.h
        pv/sigsession.h
-       pv/data/decoder.h
+       pv/data/decoderstack.h
        pv/dialogs/about.h
        pv/dialogs/connect.h
        pv/popups/deviceoptions.h
diff --git a/pv/data/decoder.cpp b/pv/data/decoder.cpp
deleted file mode 100644 (file)
index a9168ae..0000000
+++ /dev/null
@@ -1,238 +0,0 @@
-/*
- * This file is part of the PulseView project.
- *
- * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
- */
-
-#include <libsigrokdecode/libsigrokdecode.h>
-
-#include <boost/thread/thread.hpp>
-
-#include <stdexcept>
-
-#include <QDebug>
-
-#include "decoder.h"
-
-#include <pv/data/logic.h>
-#include <pv/data/logicsnapshot.h>
-#include <pv/view/logicsignal.h>
-#include <pv/view/decode/annotation.h>
-
-using namespace boost;
-using namespace std;
-
-namespace pv {
-namespace data {
-
-const double Decoder::DecodeMargin = 1.0;
-const double Decoder::DecodeThreshold = 0.2;
-const int64_t Decoder::DecodeChunkLength = 4096;
-
-mutex Decoder::_global_decode_mutex;
-
-Decoder::Decoder(const srd_decoder *const dec) :
-       _decoder(dec),
-       _options(g_hash_table_new_full(g_str_hash,
-               g_str_equal, g_free, (GDestroyNotify)g_variant_unref))
-{
-}
-
-Decoder::~Decoder()
-{
-       _decode_thread.interrupt();
-       _decode_thread.join();
-
-       g_hash_table_destroy(_options);
-}
-
-const srd_decoder* Decoder::decoder() const
-{
-       return _decoder;
-}
-
-const map<const srd_probe*, shared_ptr<view::LogicSignal> >&
-Decoder::probes() const
-{
-       return _probes;
-}
-
-void Decoder::set_probes(std::map<const srd_probe*,
-       boost::shared_ptr<view::LogicSignal> > probes)
-{
-       _probes = probes;
-       begin_decode();
-}
-
-const GHashTable* Decoder::options() const
-{
-       return _options;
-}
-
-void Decoder::set_option(const char *id, GVariant *value)
-{
-       g_variant_ref(value);
-       g_hash_table_replace(_options, (void*)g_strdup(id), value);
-       begin_decode();
-}
-
-const vector< shared_ptr<view::decode::Annotation> >
-       Decoder::annotations() const
-{
-       lock_guard<mutex> lock(_mutex);
-       return _annotations;
-}
-
-QString Decoder::error_message()
-{
-       lock_guard<mutex> lock(_mutex);
-       return _error_message;
-}
-
-void Decoder::begin_decode()
-{
-       _decode_thread.interrupt();
-       _decode_thread.join();
-
-       _annotations.clear();
-
-       if (_probes.empty())
-               return;
-
-       // Get the samplerate and start time
-       shared_ptr<pv::view::LogicSignal> logic_signal =
-               dynamic_pointer_cast<pv::view::LogicSignal>(
-                       (*_probes.begin()).second);
-       if (logic_signal) {
-               shared_ptr<pv::data::Logic> data(
-                       logic_signal->data());
-               if (data) {
-                       _start_time = data->get_start_time();
-                       _samplerate = data->get_samplerate();
-                       if (_samplerate == 0.0)
-                               _samplerate = 1.0;
-               }
-       }
-
-       // 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::LogicSignal> sig = (*_probes.begin()).second;
-       assert(sig);
-       shared_ptr<data::Logic> data = sig->data();
-
-       _decode_thread = boost::thread(&Decoder::decode_proc, this,
-               data);
-}
-
-void Decoder::clear_snapshots()
-{
-}
-
-void Decoder::decode_proc(shared_ptr<data::Logic> data)
-{
-       srd_session *session;
-       uint8_t chunk[DecodeChunkLength];
-
-       assert(data);
-
-       const deque< shared_ptr<pv::data::LogicSnapshot> > &snapshots =
-               data->get_snapshots();
-       if (snapshots.empty())
-               return;
-
-       const shared_ptr<pv::data::LogicSnapshot> &snapshot =
-               snapshots.front();
-       const int64_t sample_count = snapshot->get_sample_count() - 1;
-
-       // Create the session
-       srd_session_new(&session);
-       assert(session);
-
-       srd_session_metadata_set(session, SRD_CONF_SAMPLERATE,
-               g_variant_new_uint64((uint64_t)_samplerate));
-
-       srd_pd_output_callback_add(session, SRD_OUTPUT_ANN,
-               Decoder::annotation_callback, this);
-
-       // Create the decoder instance
-       srd_decoder_inst *const decoder_inst = srd_inst_new(
-               session, _decoder->id, _options);
-       if(!decoder_inst) {
-               _error_message = tr("Failed to initialise decoder");
-               return;
-       }
-
-       // Setup the probes
-       GHashTable *const 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::LogicSignal> >::
-               const_iterator i = _probes.begin();
-               i != _probes.end(); i++)
-       {
-               shared_ptr<view::Signal> signal((*i).second);
-               GVariant *const gvar = g_variant_new_int32(
-                       signal->probe()->index);
-               g_variant_ref_sink(gvar);
-               g_hash_table_insert(probes, (*i).first->id, gvar);
-       }
-
-       srd_inst_probe_set_all(decoder_inst, probes);
-
-       // Start the session
-       srd_session_start(session);
-
-       for (int64_t i = 0;
-               !this_thread::interruption_requested() && i < sample_count;
-               i += DecodeChunkLength)
-       {
-               lock_guard<mutex> decode_lock(_global_decode_mutex);
-
-               const int64_t chunk_end = min(
-                       i + DecodeChunkLength, sample_count);
-               snapshot->get_samples(chunk, i, chunk_end);
-
-               if (srd_session_send(session, i, i + sample_count,
-                               chunk, chunk_end - i) != SRD_OK) {
-                       _error_message = tr("Failed to initialise decoder");
-                       break;
-               }
-       }
-
-       // Destroy the session
-       srd_session_destroy(session);
-}
-
-void Decoder::annotation_callback(srd_proto_data *pdata, void *decoder)
-{
-       using namespace pv::view::decode;
-
-       assert(pdata);
-       assert(decoder);
-
-       Decoder *const d = (Decoder*)decoder;
-
-       shared_ptr<Annotation> a(new Annotation(pdata));
-       lock_guard<mutex> lock(d->_mutex);
-       d->_annotations.push_back(a);
-
-       d->new_decode_data();
-}
-
-} // namespace data
-} // namespace pv
diff --git a/pv/data/decoder.h b/pv/data/decoder.h
deleted file mode 100644 (file)
index 72ccd2e..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * This file is part of the PulseView project.
- *
- * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
- */
-
-#ifndef PULSEVIEW_PV_DATA_DECODER_H
-#define PULSEVIEW_PV_DATA_DECODER_H
-
-#include "signaldata.h"
-
-#include <map>
-
-#include <boost/shared_ptr.hpp>
-#include <boost/thread.hpp>
-
-#include <QObject>
-#include <QString>
-
-#include <glib.h>
-
-struct srd_decoder;
-struct srd_probe;
-struct srd_proto_data;
-
-namespace DecoderTest {
-class TwoDecoder;
-}
-
-namespace pv {
-
-namespace view {
-class LogicSignal;
-
-namespace decode {
-class Annotation;
-}
-
-}
-
-namespace data {
-
-class Logic;
-
-class Decoder : public QObject, public SignalData
-{
-       Q_OBJECT
-
-private:
-       static const double DecodeMargin;
-       static const double DecodeThreshold;
-       static const int64_t DecodeChunkLength;
-
-public:
-       Decoder(const srd_decoder *const decoder);
-
-       virtual ~Decoder();
-
-       const srd_decoder* decoder() const;
-
-       const std::map<const srd_probe*, boost::shared_ptr<view::LogicSignal> >&
-               probes() const;
-       void set_probes(std::map<const srd_probe*,
-               boost::shared_ptr<view::LogicSignal> > probes);
-
-       const GHashTable* options() const;
-
-       void set_option(const char *id, GVariant *value);
-
-       const std::vector< boost::shared_ptr<pv::view::decode::Annotation> >
-               annotations() const;
-
-       QString error_message();
-
-       void clear_snapshots();
-
-private:
-       void begin_decode();
-
-       void decode_proc(boost::shared_ptr<data::Logic> data);
-
-       static void annotation_callback(srd_proto_data *pdata,
-               void *decoder);
-
-signals:
-       void new_decode_data();
-
-private:
-
-       /**
-        * This mutex prevents more than one decode operation occuring
-        * concurrently.
-        * @todo A proper solution should be implemented to allow multiple
-        * decode operations.
-        */
-       static boost::mutex _global_decode_mutex;
-
-       const srd_decoder *const _decoder;
-       std::map<const srd_probe*, boost::shared_ptr<view::LogicSignal> >
-               _probes;
-       GHashTable *_options;
-
-       mutable boost::mutex _mutex;
-       std::vector< boost::shared_ptr<pv::view::decode::Annotation> >
-               _annotations;
-       QString _error_message;
-
-       boost::thread _decode_thread;
-
-       friend class DecoderTest::TwoDecoder;
-};
-
-} // namespace data
-} // namespace pv
-
-#endif // PULSEVIEW_PV_DATA_DECODER_H
diff --git a/pv/data/decoderstack.cpp b/pv/data/decoderstack.cpp
new file mode 100644 (file)
index 0000000..d56422a
--- /dev/null
@@ -0,0 +1,238 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include <libsigrokdecode/libsigrokdecode.h>
+
+#include <boost/thread/thread.hpp>
+
+#include <stdexcept>
+
+#include <QDebug>
+
+#include "decoderstack.h"
+
+#include <pv/data/logic.h>
+#include <pv/data/logicsnapshot.h>
+#include <pv/view/logicsignal.h>
+#include <pv/view/decode/annotation.h>
+
+using namespace boost;
+using namespace std;
+
+namespace pv {
+namespace data {
+
+const double DecoderStack::DecodeMargin = 1.0;
+const double DecoderStack::DecodeThreshold = 0.2;
+const int64_t DecoderStack::DecodeChunkLength = 4096;
+
+mutex DecoderStack::_global_decode_mutex;
+
+DecoderStack::DecoderStack(const srd_decoder *const dec) :
+       _decoder(dec),
+       _options(g_hash_table_new_full(g_str_hash,
+               g_str_equal, g_free, (GDestroyNotify)g_variant_unref))
+{
+}
+
+DecoderStack::~DecoderStack()
+{
+       _decode_thread.interrupt();
+       _decode_thread.join();
+
+       g_hash_table_destroy(_options);
+}
+
+const srd_decoder* DecoderStack::decoder() const
+{
+       return _decoder;
+}
+
+const map<const srd_probe*, shared_ptr<view::LogicSignal> >&
+DecoderStack::probes() const
+{
+       return _probes;
+}
+
+void DecoderStack::set_probes(std::map<const srd_probe*,
+       boost::shared_ptr<view::LogicSignal> > probes)
+{
+       _probes = probes;
+       begin_decode();
+}
+
+const GHashTable* DecoderStack::options() const
+{
+       return _options;
+}
+
+void DecoderStack::set_option(const char *id, GVariant *value)
+{
+       g_variant_ref(value);
+       g_hash_table_replace(_options, (void*)g_strdup(id), value);
+       begin_decode();
+}
+
+const vector< shared_ptr<view::decode::Annotation> >
+       DecoderStack::annotations() const
+{
+       lock_guard<mutex> lock(_mutex);
+       return _annotations;
+}
+
+QString DecoderStack::error_message()
+{
+       lock_guard<mutex> lock(_mutex);
+       return _error_message;
+}
+
+void DecoderStack::begin_decode()
+{
+       _decode_thread.interrupt();
+       _decode_thread.join();
+
+       _annotations.clear();
+
+       if (_probes.empty())
+               return;
+
+       // Get the samplerate and start time
+       shared_ptr<pv::view::LogicSignal> logic_signal =
+               dynamic_pointer_cast<pv::view::LogicSignal>(
+                       (*_probes.begin()).second);
+       if (logic_signal) {
+               shared_ptr<pv::data::Logic> data(
+                       logic_signal->data());
+               if (data) {
+                       _start_time = data->get_start_time();
+                       _samplerate = data->get_samplerate();
+                       if (_samplerate == 0.0)
+                               _samplerate = 1.0;
+               }
+       }
+
+       // 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::LogicSignal> sig = (*_probes.begin()).second;
+       assert(sig);
+       shared_ptr<data::Logic> data = sig->data();
+
+       _decode_thread = boost::thread(&DecoderStack::decode_proc, this,
+               data);
+}
+
+void DecoderStack::clear_snapshots()
+{
+}
+
+void DecoderStack::decode_proc(shared_ptr<data::Logic> data)
+{
+       srd_session *session;
+       uint8_t chunk[DecodeChunkLength];
+
+       assert(data);
+
+       const deque< shared_ptr<pv::data::LogicSnapshot> > &snapshots =
+               data->get_snapshots();
+       if (snapshots.empty())
+               return;
+
+       const shared_ptr<pv::data::LogicSnapshot> &snapshot =
+               snapshots.front();
+       const int64_t sample_count = snapshot->get_sample_count() - 1;
+
+       // Create the session
+       srd_session_new(&session);
+       assert(session);
+
+       srd_session_metadata_set(session, SRD_CONF_SAMPLERATE,
+               g_variant_new_uint64((uint64_t)_samplerate));
+
+       srd_pd_output_callback_add(session, SRD_OUTPUT_ANN,
+               DecoderStack::annotation_callback, this);
+
+       // Create the decoder instance
+       srd_decoder_inst *const decoder_inst = srd_inst_new(
+               session, _decoder->id, _options);
+       if(!decoder_inst) {
+               _error_message = tr("Failed to initialise decoder");
+               return;
+       }
+
+       // Setup the probes
+       GHashTable *const 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::LogicSignal> >::
+               const_iterator i = _probes.begin();
+               i != _probes.end(); i++)
+       {
+               shared_ptr<view::Signal> signal((*i).second);
+               GVariant *const gvar = g_variant_new_int32(
+                       signal->probe()->index);
+               g_variant_ref_sink(gvar);
+               g_hash_table_insert(probes, (*i).first->id, gvar);
+       }
+
+       srd_inst_probe_set_all(decoder_inst, probes);
+
+       // Start the session
+       srd_session_start(session);
+
+       for (int64_t i = 0;
+               !this_thread::interruption_requested() && i < sample_count;
+               i += DecodeChunkLength)
+       {
+               lock_guard<mutex> decode_lock(_global_decode_mutex);
+
+               const int64_t chunk_end = min(
+                       i + DecodeChunkLength, sample_count);
+               snapshot->get_samples(chunk, i, chunk_end);
+
+               if (srd_session_send(session, i, i + sample_count,
+                               chunk, chunk_end - i) != SRD_OK) {
+                       _error_message = tr("Failed to initialise decoder");
+                       break;
+               }
+       }
+
+       // Destroy the session
+       srd_session_destroy(session);
+}
+
+void DecoderStack::annotation_callback(srd_proto_data *pdata, void *decoder)
+{
+       using namespace pv::view::decode;
+
+       assert(pdata);
+       assert(decoder);
+
+       DecoderStack *const d = (DecoderStack*)decoder;
+
+       shared_ptr<Annotation> a(new Annotation(pdata));
+       lock_guard<mutex> lock(d->_mutex);
+       d->_annotations.push_back(a);
+
+       d->new_decode_data();
+}
+
+} // namespace data
+} // namespace pv
diff --git a/pv/data/decoderstack.h b/pv/data/decoderstack.h
new file mode 100644 (file)
index 0000000..844a2b5
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#ifndef PULSEVIEW_PV_DATA_DECODERSTACK_H
+#define PULSEVIEW_PV_DATA_DECODERSTACK_H
+
+#include "signaldata.h"
+
+#include <map>
+
+#include <boost/shared_ptr.hpp>
+#include <boost/thread.hpp>
+
+#include <QObject>
+#include <QString>
+
+#include <glib.h>
+
+struct srd_decoder;
+struct srd_probe;
+struct srd_proto_data;
+
+namespace DecoderStackTest {
+class TwoDecoderStack;
+}
+
+namespace pv {
+
+namespace view {
+class LogicSignal;
+
+namespace decode {
+class Annotation;
+}
+
+}
+
+namespace data {
+
+class Logic;
+
+class DecoderStack : public QObject, public SignalData
+{
+       Q_OBJECT
+
+private:
+       static const double DecodeMargin;
+       static const double DecodeThreshold;
+       static const int64_t DecodeChunkLength;
+
+public:
+       DecoderStack(const srd_decoder *const decoder);
+
+       virtual ~DecoderStack();
+
+       const srd_decoder* decoder() const;
+
+       const std::map<const srd_probe*, boost::shared_ptr<view::LogicSignal> >&
+               probes() const;
+       void set_probes(std::map<const srd_probe*,
+               boost::shared_ptr<view::LogicSignal> > probes);
+
+       const GHashTable* options() const;
+
+       void set_option(const char *id, GVariant *value);
+
+       const std::vector< boost::shared_ptr<pv::view::decode::Annotation> >
+               annotations() const;
+
+       QString error_message();
+
+       void clear_snapshots();
+
+private:
+       void begin_decode();
+
+       void decode_proc(boost::shared_ptr<data::Logic> data);
+
+       static void annotation_callback(srd_proto_data *pdata,
+               void *decoder);
+
+signals:
+       void new_decode_data();
+
+private:
+
+       /**
+        * This mutex prevents more than one decode operation occuring
+        * concurrently.
+        * @todo A proper solution should be implemented to allow multiple
+        * decode operations.
+        */
+       static boost::mutex _global_decode_mutex;
+
+       const srd_decoder *const _decoder;
+       std::map<const srd_probe*, boost::shared_ptr<view::LogicSignal> >
+               _probes;
+       GHashTable *_options;
+
+       mutable boost::mutex _mutex;
+       std::vector< boost::shared_ptr<pv::view::decode::Annotation> >
+               _annotations;
+       QString _error_message;
+
+       boost::thread _decode_thread;
+
+       friend class DecoderStackTest::TwoDecoderStack;
+};
+
+} // namespace data
+} // namespace pv
+
+#endif // PULSEVIEW_PV_DATA_DECODERSTACK_H
index 5ad7e3562e6150e057c9299964069af1e931feba..0a6cd15c998604bdfad8ba9913c1fa640c6793b7 100644 (file)
@@ -25,7 +25,7 @@
 #include <boost/foreach.hpp>
 #include <boost/none_t.hpp>
 
-#include <pv/data/decoder.h>
+#include <pv/data/decoderstack.h>
 #include <pv/prop/int.h>
 #include <pv/prop/string.h>
 
@@ -36,7 +36,7 @@ namespace pv {
 namespace prop {
 namespace binding {
 
-DecoderOptions::DecoderOptions(shared_ptr<pv::data::Decoder> decoder) :
+DecoderOptions::DecoderOptions(shared_ptr<pv::data::DecoderStack> decoder) :
        _decoder(decoder)
 {
        assert(_decoder);
index 11b0be724afd9d738da6de3105640a72f401a8b5..e507e87c3accebafe17d356eace0a52dadc6defe 100644 (file)
@@ -28,7 +28,7 @@
 namespace pv {
 
 namespace data {
-class Decoder;
+class DecoderStack;
 }
 
 namespace prop {
@@ -37,7 +37,7 @@ namespace binding {
 class DecoderOptions : public Binding
 {
 public:
-       DecoderOptions(boost::shared_ptr<pv::data::Decoder> decoder);
+       DecoderOptions(boost::shared_ptr<pv::data::DecoderStack> decoder);
 
 private:
        GVariant* getter(const char *id);
@@ -45,7 +45,7 @@ private:
        void setter(const char *id, GVariant *value);
 
 private:
-       boost::shared_ptr<pv::data::Decoder> _decoder;
+       boost::shared_ptr<pv::data::DecoderStack> _decoder;
 };
 
 } // binding
index 24a059ea8a35f03340461aac434047231087ec05..a6a2875e62657ca7dacc458808f854fc6dfbe88c 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "data/analog.h"
 #include "data/analogsnapshot.h"
-#include "data/decoder.h"
+#include "data/decoderstack.h"
 #include "data/logic.h"
 #include "data/logicsnapshot.h"
 
@@ -208,7 +208,7 @@ bool SigSession::add_decoder(srd_decoder *const dec)
                lock_guard<mutex> lock(_signals_mutex);
 
                // Create the decoder
-               shared_ptr<data::Decoder> decoder(new data::Decoder(dec));
+               shared_ptr<data::DecoderStack> decoder(new data::DecoderStack(dec));
 
                // Auto select the initial probes
                for(const GSList *i = dec->probes; i; i = i->next)
index 29c4a6e9b1476c613ac9d9f062be96570c5403fc..51b17e5e14269d236acdde3dba578d39b36c47f5 100644 (file)
@@ -36,7 +36,7 @@ extern "C" {
 #include "decodetrace.h"
 
 #include <pv/sigsession.h>
-#include <pv/data/decoder.h>
+#include <pv/data/decoderstack.h>
 #include <pv/view/logicsignal.h>
 #include <pv/view/view.h>
 #include <pv/view/decode/annotation.h>
@@ -58,16 +58,16 @@ const QColor DecodeTrace::DecodeColours[4] = {
 const QColor DecodeTrace::ErrorBgColour = QColor(0xEF, 0x29, 0x29);
 
 DecodeTrace::DecodeTrace(pv::SigSession &session,
-       boost::shared_ptr<pv::data::Decoder> decoder, int index) :
-       Trace(session, QString(decoder->decoder()->name)),
-       _decoder(decoder),
-       _binding(decoder)
+       boost::shared_ptr<pv::data::DecoderStack> decoder_stack, int index) :
+       Trace(session, QString(decoder_stack->decoder()->name)),
+       _decoder_stack(decoder_stack),
+       _binding(decoder_stack)
 {
-       assert(_decoder);
+       assert(_decoder_stack);
 
        _colour = DecodeColours[index % countof(DecodeColours)];
 
-       connect(_decoder.get(), SIGNAL(new_decode_data()),
+       connect(_decoder_stack.get(), SIGNAL(new_decode_data()),
                this, SLOT(on_new_decode_data()));
 }
 
@@ -76,9 +76,9 @@ bool DecodeTrace::enabled() const
        return true;
 }
 
-const boost::shared_ptr<pv::data::Decoder>& DecodeTrace::decoder() const
+const boost::shared_ptr<pv::data::DecoderStack>& DecodeTrace::decoder() const
 {
-       return _decoder;
+       return _decoder_stack;
 }
 
 void DecodeTrace::set_view(pv::view::View *view)
@@ -96,8 +96,8 @@ void DecodeTrace::paint_mid(QPainter &p, int left, int right)
 {
        using namespace pv::view::decode;
 
-       assert(_decoder);
-       const QString err = _decoder->error_message();
+       assert(_decoder_stack);
+       const QString err = _decoder_stack->error_message();
        if (!err.isEmpty()) {
                draw_error(p, err, left, right);
                return;
@@ -109,18 +109,18 @@ void DecodeTrace::paint_mid(QPainter &p, int left, int right)
        const double scale = _view->scale();
        assert(scale > 0);
 
-       double samplerate = _decoder->get_samplerate();
+       double samplerate = _decoder_stack->get_samplerate();
 
        // Show sample rate as 1Hz when it is unknown
        if (samplerate == 0.0)
                samplerate = 1.0;
 
        const double pixels_offset = (_view->offset() -
-               _decoder->get_start_time()) / scale;
+               _decoder_stack->get_start_time()) / scale;
        const double samples_per_pixel = samplerate * scale;
 
-       assert(_decoder);
-       vector< shared_ptr<Annotation> > annotations(_decoder->annotations());
+       assert(_decoder_stack);
+       vector< shared_ptr<Annotation> > annotations(_decoder_stack->annotations());
        BOOST_FOREACH(shared_ptr<Annotation> a, annotations) {
                assert(a);
                a->paint(p, get_text_colour(), _text_size.height(),
@@ -134,9 +134,9 @@ void DecodeTrace::populate_popup_form(QWidget *parent, QFormLayout *form)
 
        assert(form);
        assert(parent);
-       assert(_decoder);
+       assert(_decoder_stack);
 
-       const srd_decoder *const decoder = _decoder->decoder();
+       const srd_decoder *const decoder = _decoder_stack->decoder();
 
        assert(decoder);
 
@@ -184,7 +184,7 @@ void DecodeTrace::populate_popup_form(QWidget *parent, QFormLayout *form)
 
        // Add stacking button
        QPushButton *const stack_button =
-               new QPushButton(tr("Stack Decoder"), parent);
+               new QPushButton(tr("Stack DecoderStack"), parent);
        pv::widgets::DecoderMenu *const decoder_menu =
                new pv::widgets::DecoderMenu(parent);
        stack_button->setMenu(decoder_menu);
@@ -234,16 +234,16 @@ QComboBox* DecodeTrace::create_probe_selector(
 {
        const vector< shared_ptr<Signal> > sigs = _session.get_signals();
 
-       assert(_decoder);
+       assert(_decoder_stack);
        const map<const srd_probe*,
                shared_ptr<LogicSignal> >::const_iterator probe_iter =
-               _decoder->probes().find(probe);
+               _decoder_stack->probes().find(probe);
 
        QComboBox *selector = new QComboBox(parent);
 
        selector->addItem("-", qVariantFromValue((void*)NULL));
 
-       if (probe_iter == _decoder->probes().end())
+       if (probe_iter == _decoder_stack->probes().end())
                selector->setCurrentIndex(0);
 
        for(size_t i = 0; i < sigs.size(); i++) {
@@ -264,7 +264,7 @@ QComboBox* DecodeTrace::create_probe_selector(
 
 void DecodeTrace::commit_probes()
 {
-       assert(_decoder);
+       assert(_decoder_stack);
 
        map<const srd_probe*, shared_ptr<LogicSignal> > probe_map;
        const vector< shared_ptr<Signal> > sigs = _session.get_signals();
@@ -286,7 +286,7 @@ void DecodeTrace::commit_probes()
                        }
        }
 
-       _decoder->set_probes(probe_map);
+       _decoder_stack->set_probes(probe_map);
 }
 
 void DecodeTrace::on_new_decode_data()
index 6f7182f4ebd618f583cc6972b4f8d38b191218cb..229df86d3aaa6756ae20192603ace403ca386b34 100644 (file)
@@ -36,7 +36,7 @@ class QComboBox;
 namespace pv {
 
 namespace data {
-class Decoder;
+class DecoderStack;
 }
 
 namespace view {
@@ -51,11 +51,12 @@ private:
 
 public:
        DecodeTrace(pv::SigSession &session,
-               boost::shared_ptr<pv::data::Decoder> decoder, int index);
+               boost::shared_ptr<pv::data::DecoderStack> decoder_stack,
+               int index);
 
        bool enabled() const;
 
-       const boost::shared_ptr<pv::data::Decoder>& decoder() const;
+       const boost::shared_ptr<pv::data::DecoderStack>& decoder() const;
 
        void set_view(pv::view::View *view);
 
@@ -98,7 +99,7 @@ private slots:
        void on_probe_selected(int);
 
 private:
-       boost::shared_ptr<pv::data::Decoder> _decoder;
+       boost::shared_ptr<pv::data::DecoderStack> _decoder_stack;
 
        uint64_t _decode_start, _decode_end;
 
index afe26a16fd8a24f772663480302258f7d0cc196b..5cc18c1627de2f737301f5da8002a32fb0e09dc8 100644 (file)
@@ -41,7 +41,7 @@ set(pulseview_TEST_SOURCES
        ${PROJECT_SOURCE_DIR}/pv/view/cursorpair.cpp
        ${PROJECT_SOURCE_DIR}/pv/data/analog.cpp
        ${PROJECT_SOURCE_DIR}/pv/data/analogsnapshot.cpp
-       ${PROJECT_SOURCE_DIR}/pv/data/decoder.cpp
+       ${PROJECT_SOURCE_DIR}/pv/data/decoderstack.cpp
        ${PROJECT_SOURCE_DIR}/pv/data/logic.cpp
        ${PROJECT_SOURCE_DIR}/pv/data/logicsnapshot.cpp
        ${PROJECT_SOURCE_DIR}/pv/data/snapshot.cpp
@@ -73,7 +73,7 @@ set(pulseview_TEST_SOURCES
        ${PROJECT_SOURCE_DIR}/pv/widgets/popup.cpp
        ${PROJECT_SOURCE_DIR}/pv/widgets/wellarray.cpp
        data/analogsnapshot.cpp
-       data/decoder.cpp
+       data/decoderstack.cpp
        data/logicsnapshot.cpp
        test.cpp
 )
@@ -81,7 +81,7 @@ set(pulseview_TEST_SOURCES
 # This list includes only QObject derrived class headers
 set(pulseview_TEST_HEADERS
        ${PROJECT_SOURCE_DIR}/pv/sigsession.h
-       ${PROJECT_SOURCE_DIR}/pv/data/decoder.h
+       ${PROJECT_SOURCE_DIR}/pv/data/decoderstack.h
        ${PROJECT_SOURCE_DIR}/pv/prop/int.h
        ${PROJECT_SOURCE_DIR}/pv/prop/property.h
        ${PROJECT_SOURCE_DIR}/pv/prop/string.h
diff --git a/test/data/decoder.cpp b/test/data/decoder.cpp
deleted file mode 100644 (file)
index 6a48fb0..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * This file is part of the PulseView project.
- *
- * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
- */
-
-#include <libsigrokdecode/libsigrokdecode.h> /* First, so we avoid a _POSIX_C_SOURCE warning. */
-#include <boost/test/unit_test.hpp>
-
-#include <libsigrok/libsigrok.h>
-
-#include "../../pv/data/decoder.h"
-#include "../../pv/devicemanager.h"
-#include "../../pv/sigsession.h"
-#include "../../pv/view/decodetrace.h"
-
-using namespace boost;
-using namespace std;
-
-BOOST_AUTO_TEST_SUITE(DecoderTest)
-
-BOOST_AUTO_TEST_CASE(TwoDecoder)
-{
-       using namespace pv;
-
-       sr_context *ctx = NULL;
-
-       BOOST_REQUIRE(sr_init(&ctx) == SR_OK);
-       BOOST_REQUIRE(ctx);
-
-       BOOST_REQUIRE(srd_init(NULL) == SRD_OK);
-
-       srd_decoder_load_all();
-
-       {
-               pv::DeviceManager dm(ctx);
-               pv::SigSession ss(dm);
-
-               const GSList *l = srd_decoder_list();
-               BOOST_REQUIRE(l);
-               srd_decoder *const dec = (struct srd_decoder*)l->data;
-               BOOST_REQUIRE(dec);
-
-               ss.add_decoder(dec);
-               ss.add_decoder(dec);
-
-               // Check the signals were created
-               const vector< shared_ptr<view::DecodeTrace> > sigs =
-                       ss.get_decode_signals();
-
-               shared_ptr<data::Decoder> dec0 = sigs[0]->decoder();
-               BOOST_REQUIRE(dec0);
-
-               shared_ptr<data::Decoder> dec1 = sigs[0]->decoder();
-               BOOST_REQUIRE(dec1);
-
-               // Wait for the decode threads to complete
-               dec0->_decode_thread.join();
-               dec1->_decode_thread.join();
-
-               // Check there were no errors
-               BOOST_CHECK_EQUAL(dec0->error_message().isEmpty(), true);
-               BOOST_CHECK_EQUAL(dec1->error_message().isEmpty(), true);
-       }
-
-
-       srd_exit();
-       sr_exit(ctx);
-}
-
-BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/data/decoderstack.cpp b/test/data/decoderstack.cpp
new file mode 100644 (file)
index 0000000..84a496f
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include <libsigrokdecode/libsigrokdecode.h> /* First, so we avoid a _POSIX_C_SOURCE warning. */
+#include <boost/test/unit_test.hpp>
+
+#include <libsigrok/libsigrok.h>
+
+#include "../../pv/data/decoderstack.h"
+#include "../../pv/devicemanager.h"
+#include "../../pv/sigsession.h"
+#include "../../pv/view/decodetrace.h"
+
+using namespace boost;
+using namespace std;
+
+BOOST_AUTO_TEST_SUITE(DecoderStackTest)
+
+BOOST_AUTO_TEST_CASE(TwoDecoderStack)
+{
+       using namespace pv;
+
+       sr_context *ctx = NULL;
+
+       BOOST_REQUIRE(sr_init(&ctx) == SR_OK);
+       BOOST_REQUIRE(ctx);
+
+       BOOST_REQUIRE(srd_init(NULL) == SRD_OK);
+
+       srd_decoder_load_all();
+
+       {
+               pv::DeviceManager dm(ctx);
+               pv::SigSession ss(dm);
+
+               const GSList *l = srd_decoder_list();
+               BOOST_REQUIRE(l);
+               srd_decoder *const dec = (struct srd_decoder*)l->data;
+               BOOST_REQUIRE(dec);
+
+               ss.add_decoder(dec);
+               ss.add_decoder(dec);
+
+               // Check the signals were created
+               const vector< shared_ptr<view::DecodeTrace> > sigs =
+                       ss.get_decode_signals();
+
+               shared_ptr<data::DecoderStack> dec0 = sigs[0]->decoder();
+               BOOST_REQUIRE(dec0);
+
+               shared_ptr<data::DecoderStack> dec1 = sigs[0]->decoder();
+               BOOST_REQUIRE(dec1);
+
+               // Wait for the decode threads to complete
+               dec0->_decode_thread.join();
+               dec1->_decode_thread.join();
+
+               // Check there were no errors
+               BOOST_CHECK_EQUAL(dec0->error_message().isEmpty(), true);
+               BOOST_CHECK_EQUAL(dec1->error_message().isEmpty(), true);
+       }
+
+
+       srd_exit();
+       sr_exit(ctx);
+}
+
+BOOST_AUTO_TEST_SUITE_END()