From: Soeren Apel Date: Tue, 20 Jun 2017 20:38:51 +0000 (+0200) Subject: Session: Break up add_decoder() X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=e771b42d654ecb1e8e4d6ca60687c545461e3750;p=pulseview.git Session: Break up add_decoder() --- diff --git a/pv/session.cpp b/pv/session.cpp index b022bd02..4edba0f7 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -682,31 +682,27 @@ const unordered_set< shared_ptr > Session::signalbases() const } #ifdef ENABLE_DECODE -bool Session::add_decoder(srd_decoder *const dec) +shared_ptr Session::add_decode_signal() { - if (!dec) - return false; + shared_ptr signal; try { // Create the decode signal - shared_ptr signal = - make_shared(*this); + signal = make_shared(*this); signalbases_.insert(signal); // Add the decode signal to all views for (shared_ptr view : views_) view->add_decode_signal(signal); - - // Add decoder - signal->stack_decoder(dec); } catch (runtime_error e) { - return false; + remove_decode_signal(signal); + return nullptr; } signals_changed(); - return true; + return signal; } void Session::remove_decode_signal(shared_ptr signal) diff --git a/pv/session.hpp b/pv/session.hpp index 5a54d83a..424bf637 100644 --- a/pv/session.hpp +++ b/pv/session.hpp @@ -170,7 +170,7 @@ public: const unordered_set< shared_ptr > signalbases() const; #ifdef ENABLE_DECODE - bool add_decoder(srd_decoder *const dec); + shared_ptr add_decode_signal(); void remove_decode_signal(shared_ptr signal); #endif diff --git a/pv/toolbars/mainbar.cpp b/pv/toolbars/mainbar.cpp index 22ed3988..272e844f 100644 --- a/pv/toolbars/mainbar.cpp +++ b/pv/toolbars/mainbar.cpp @@ -35,6 +35,7 @@ #include +#include #include #include #include @@ -575,7 +576,9 @@ void MainBar::add_decoder(srd_decoder *decoder) { #ifdef ENABLE_DECODE assert(decoder); - session_.add_decoder(decoder); + shared_ptr signal = session_.add_decode_signal(); + if (signal) + signal->stack_decoder(decoder); #else (void)decoder; #endif