]> sigrok.org Git - pulseview.git/commitdiff
Session: Break up add_decoder()
authorSoeren Apel <redacted>
Tue, 20 Jun 2017 20:38:51 +0000 (22:38 +0200)
committerUwe Hermann <redacted>
Wed, 5 Jul 2017 22:37:08 +0000 (00:37 +0200)
pv/session.cpp
pv/session.hpp
pv/toolbars/mainbar.cpp

index b022bd02c0c02681bd576a06fff085b89f27e0c8..4edba0f7a2de9c5f428e9f07fe38d7532e69ad1e 100644 (file)
@@ -682,31 +682,27 @@ const unordered_set< shared_ptr<data::SignalBase> > Session::signalbases() const
 }
 
 #ifdef ENABLE_DECODE
-bool Session::add_decoder(srd_decoder *const dec)
+shared_ptr<data::DecodeSignal> Session::add_decode_signal()
 {
-       if (!dec)
-               return false;
+       shared_ptr<data::DecodeSignal> signal;
 
        try {
                // Create the decode signal
-               shared_ptr<data::DecodeSignal> signal =
-                       make_shared<data::DecodeSignal>(*this);
+               signal = make_shared<data::DecodeSignal>(*this);
 
                signalbases_.insert(signal);
 
                // Add the decode signal to all views
                for (shared_ptr<views::ViewBase> 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<data::DecodeSignal> signal)
index 5a54d83aa047a0f245457eae0eb8832f67bc98ba..424bf6375cd0d14850df3714ad0d1f41c87cc9b4 100644 (file)
@@ -170,7 +170,7 @@ public:
        const unordered_set< shared_ptr<data::SignalBase> > signalbases() const;
 
 #ifdef ENABLE_DECODE
-       bool add_decoder(srd_decoder *const dec);
+       shared_ptr<data::DecodeSignal> add_decode_signal();
 
        void remove_decode_signal(shared_ptr<data::DecodeSignal> signal);
 #endif
index 22ed3988cfb72ccfb824390c03d1b4354b8dd4ed..272e844f981df35ba05be9f1a472322ec2ea99b3 100644 (file)
@@ -35,6 +35,7 @@
 
 #include <boost/algorithm/string/join.hpp>
 
+#include <pv/data/decodesignal.hpp>
 #include <pv/devicemanager.hpp>
 #include <pv/devices/hardwaredevice.hpp>
 #include <pv/devices/inputfile.hpp>
@@ -575,7 +576,9 @@ void MainBar::add_decoder(srd_decoder *decoder)
 {
 #ifdef ENABLE_DECODE
        assert(decoder);
-       session_.add_decoder(decoder);
+       shared_ptr<data::DecodeSignal> signal = session_.add_decode_signal();
+       if (signal)
+               signal->stack_decoder(decoder);
 #else
        (void)decoder;
 #endif