From: Joel Holdsworth Date: Tue, 15 Oct 2013 22:09:35 +0000 (+0100) Subject: Added error handling to SigSession::add_decoder X-Git-Tag: pulseview-0.2.0~244 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=e92cd4e4cddac2639c1a5e278124b5bb22ace10f;p=pulseview.git Added error handling to SigSession::add_decoder --- diff --git a/pv/data/decoder.cpp b/pv/data/decoder.cpp index 65fc8fff..292430b6 100644 --- a/pv/data/decoder.cpp +++ b/pv/data/decoder.cpp @@ -22,6 +22,8 @@ #include +#include + #include #include "decoder.h" @@ -51,7 +53,9 @@ Decoder::Decoder(const srd_decoder *const dec, _session(NULL), _decoder_inst(NULL) { - init_decoder(); + if (!init_decoder()) + throw runtime_error("Failed to initialise decoder."); + begin_decode(); } @@ -101,7 +105,7 @@ void Decoder::clear_snapshots() { } -void Decoder::init_decoder() +bool Decoder::init_decoder() { if (!_probes.empty()) { @@ -124,7 +128,7 @@ void Decoder::init_decoder() _decoder_inst = srd_inst_new(_session, _decoder->id, _options); if(!_decoder_inst) { qDebug() << "Failed to initialise decoder"; - return; + return false; } _decoder_inst->data_samplerate = _samplerate; @@ -144,6 +148,8 @@ void Decoder::init_decoder() } srd_inst_probe_set_all(_decoder_inst, probes); + + return true; } void Decoder::decode_proc(shared_ptr data) diff --git a/pv/data/decoder.h b/pv/data/decoder.h index 93d8fa6a..264920a7 100644 --- a/pv/data/decoder.h +++ b/pv/data/decoder.h @@ -80,7 +80,7 @@ public: private: void begin_decode(); - void init_decoder(); + bool init_decoder(); void decode_proc(boost::shared_ptr data); diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index a69f068e..e81d3605 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -34,6 +34,8 @@ #include +#include + #include #include @@ -193,11 +195,12 @@ boost::shared_ptr SigSession::get_data() return _logic_data; } -void SigSession::add_decoder(srd_decoder *const dec, +bool SigSession::add_decoder(srd_decoder *const dec, std::map > probes, GHashTable *options) { + try { lock_guard lock(_signals_mutex); @@ -208,7 +211,14 @@ void SigSession::add_decoder(srd_decoder *const dec, _decode_traces.size())); _decode_traces.push_back(d); } + catch(std::runtime_error e) + { + return false; + } + signals_changed(); + + return true; } vector< shared_ptr > SigSession::get_decode_signals() const diff --git a/pv/sigsession.h b/pv/sigsession.h index e0eb4938..499814ca 100644 --- a/pv/sigsession.h +++ b/pv/sigsession.h @@ -93,7 +93,7 @@ public: boost::shared_ptr get_data(); - void add_decoder(srd_decoder *const dec, + bool add_decoder(srd_decoder *const dec, std::map > probes, GHashTable *options);