From: Joel Holdsworth Date: Sun, 27 Oct 2013 13:15:16 +0000 (+0000) Subject: Renamed pv::data::Decoder to DecoderStack X-Git-Tag: pulseview-0.2.0~220 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=6e89374a6796f8d5d9cc61b0a2f7e98562a034ae;p=pulseview.git Renamed pv::data::Decoder to DecoderStack --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 51ba86ef..0f7502a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -## + ## This file is part of the PulseView project. ## ## Copyright (C) 2012 Joel Holdsworth @@ -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 index a9168ae2..00000000 --- a/pv/data/decoder.cpp +++ /dev/null @@ -1,238 +0,0 @@ -/* - * This file is part of the PulseView project. - * - * Copyright (C) 2012 Joel Holdsworth - * - * 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 - -#include - -#include - -#include - -#include "decoder.h" - -#include -#include -#include -#include - -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 >& -Decoder::probes() const -{ - return _probes; -} - -void Decoder::set_probes(std::map > 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 > - Decoder::annotations() const -{ - lock_guard lock(_mutex); - return _annotations; -} - -QString Decoder::error_message() -{ - lock_guard 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 logic_signal = - dynamic_pointer_cast( - (*_probes.begin()).second); - if (logic_signal) { - shared_ptr 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 sig = (*_probes.begin()).second; - assert(sig); - shared_ptr data = sig->data(); - - _decode_thread = boost::thread(&Decoder::decode_proc, this, - data); -} - -void Decoder::clear_snapshots() -{ -} - -void Decoder::decode_proc(shared_ptr data) -{ - srd_session *session; - uint8_t chunk[DecodeChunkLength]; - - assert(data); - - const deque< shared_ptr > &snapshots = - data->get_snapshots(); - if (snapshots.empty()) - return; - - const shared_ptr &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_iterator i = _probes.begin(); - i != _probes.end(); i++) - { - shared_ptr 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 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 a(new Annotation(pdata)); - lock_guard 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 index 72ccd2ec..00000000 --- a/pv/data/decoder.h +++ /dev/null @@ -1,130 +0,0 @@ -/* - * This file is part of the PulseView project. - * - * Copyright (C) 2012 Joel Holdsworth - * - * 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 - -#include -#include - -#include -#include - -#include - -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 >& - probes() const; - void set_probes(std::map > probes); - - const GHashTable* options() const; - - void set_option(const char *id, GVariant *value); - - const std::vector< boost::shared_ptr > - annotations() const; - - QString error_message(); - - void clear_snapshots(); - -private: - void begin_decode(); - - void decode_proc(boost::shared_ptr 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 > - _probes; - GHashTable *_options; - - mutable boost::mutex _mutex; - std::vector< boost::shared_ptr > - _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 index 00000000..d56422a9 --- /dev/null +++ b/pv/data/decoderstack.cpp @@ -0,0 +1,238 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * 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 + +#include + +#include + +#include + +#include "decoderstack.h" + +#include +#include +#include +#include + +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 >& +DecoderStack::probes() const +{ + return _probes; +} + +void DecoderStack::set_probes(std::map > 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 > + DecoderStack::annotations() const +{ + lock_guard lock(_mutex); + return _annotations; +} + +QString DecoderStack::error_message() +{ + lock_guard 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 logic_signal = + dynamic_pointer_cast( + (*_probes.begin()).second); + if (logic_signal) { + shared_ptr 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 sig = (*_probes.begin()).second; + assert(sig); + shared_ptr data = sig->data(); + + _decode_thread = boost::thread(&DecoderStack::decode_proc, this, + data); +} + +void DecoderStack::clear_snapshots() +{ +} + +void DecoderStack::decode_proc(shared_ptr data) +{ + srd_session *session; + uint8_t chunk[DecodeChunkLength]; + + assert(data); + + const deque< shared_ptr > &snapshots = + data->get_snapshots(); + if (snapshots.empty()) + return; + + const shared_ptr &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_iterator i = _probes.begin(); + i != _probes.end(); i++) + { + shared_ptr 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 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 a(new Annotation(pdata)); + lock_guard 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 index 00000000..844a2b54 --- /dev/null +++ b/pv/data/decoderstack.h @@ -0,0 +1,130 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * 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 + +#include +#include + +#include +#include + +#include + +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 >& + probes() const; + void set_probes(std::map > probes); + + const GHashTable* options() const; + + void set_option(const char *id, GVariant *value); + + const std::vector< boost::shared_ptr > + annotations() const; + + QString error_message(); + + void clear_snapshots(); + +private: + void begin_decode(); + + void decode_proc(boost::shared_ptr 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 > + _probes; + GHashTable *_options; + + mutable boost::mutex _mutex; + std::vector< boost::shared_ptr > + _annotations; + QString _error_message; + + boost::thread _decode_thread; + + friend class DecoderStackTest::TwoDecoderStack; +}; + +} // namespace data +} // namespace pv + +#endif // PULSEVIEW_PV_DATA_DECODERSTACK_H diff --git a/pv/prop/binding/decoderoptions.cpp b/pv/prop/binding/decoderoptions.cpp index 5ad7e356..0a6cd15c 100644 --- a/pv/prop/binding/decoderoptions.cpp +++ b/pv/prop/binding/decoderoptions.cpp @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include @@ -36,7 +36,7 @@ namespace pv { namespace prop { namespace binding { -DecoderOptions::DecoderOptions(shared_ptr decoder) : +DecoderOptions::DecoderOptions(shared_ptr decoder) : _decoder(decoder) { assert(_decoder); diff --git a/pv/prop/binding/decoderoptions.h b/pv/prop/binding/decoderoptions.h index 11b0be72..e507e87c 100644 --- a/pv/prop/binding/decoderoptions.h +++ b/pv/prop/binding/decoderoptions.h @@ -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 decoder); + DecoderOptions(boost::shared_ptr decoder); private: GVariant* getter(const char *id); @@ -45,7 +45,7 @@ private: void setter(const char *id, GVariant *value); private: - boost::shared_ptr _decoder; + boost::shared_ptr _decoder; }; } // binding diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index 24a059ea..a6a2875e 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -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 lock(_signals_mutex); // Create the decoder - shared_ptr decoder(new data::Decoder(dec)); + shared_ptr decoder(new data::DecoderStack(dec)); // Auto select the initial probes for(const GSList *i = dec->probes; i; i = i->next) diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index 29c4a6e9..51b17e5e 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -36,7 +36,7 @@ extern "C" { #include "decodetrace.h" #include -#include +#include #include #include #include @@ -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 decoder, int index) : - Trace(session, QString(decoder->decoder()->name)), - _decoder(decoder), - _binding(decoder) + boost::shared_ptr 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& DecodeTrace::decoder() const +const boost::shared_ptr& 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 > annotations(_decoder->annotations()); + assert(_decoder_stack); + vector< shared_ptr > annotations(_decoder_stack->annotations()); BOOST_FOREACH(shared_ptr 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 > sigs = _session.get_signals(); - assert(_decoder); + assert(_decoder_stack); const map >::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 > probe_map; const vector< shared_ptr > 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() diff --git a/pv/view/decodetrace.h b/pv/view/decodetrace.h index 6f7182f4..229df86d 100644 --- a/pv/view/decodetrace.h +++ b/pv/view/decodetrace.h @@ -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 decoder, int index); + boost::shared_ptr decoder_stack, + int index); bool enabled() const; - const boost::shared_ptr& decoder() const; + const boost::shared_ptr& decoder() const; void set_view(pv::view::View *view); @@ -98,7 +99,7 @@ private slots: void on_probe_selected(int); private: - boost::shared_ptr _decoder; + boost::shared_ptr _decoder_stack; uint64_t _decode_start, _decode_end; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index afe26a16..5cc18c16 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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 index 6a48fb04..00000000 --- a/test/data/decoder.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * This file is part of the PulseView project. - * - * Copyright (C) 2013 Joel Holdsworth - * - * 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 /* First, so we avoid a _POSIX_C_SOURCE warning. */ -#include - -#include - -#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 > sigs = - ss.get_decode_signals(); - - shared_ptr dec0 = sigs[0]->decoder(); - BOOST_REQUIRE(dec0); - - shared_ptr 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 index 00000000..84a496f1 --- /dev/null +++ b/test/data/decoderstack.cpp @@ -0,0 +1,85 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2013 Joel Holdsworth + * + * 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 /* First, so we avoid a _POSIX_C_SOURCE warning. */ +#include + +#include + +#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 > sigs = + ss.get_decode_signals(); + + shared_ptr dec0 = sigs[0]->decoder(); + BOOST_REQUIRE(dec0); + + shared_ptr 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()