]> sigrok.org Git - pulseview.git/commitdiff
Added error handling to SigSession::add_decoder
authorJoel Holdsworth <redacted>
Tue, 15 Oct 2013 22:09:35 +0000 (23:09 +0100)
committerJoel Holdsworth <redacted>
Tue, 15 Oct 2013 22:10:26 +0000 (23:10 +0100)
pv/data/decoder.cpp
pv/data/decoder.h
pv/sigsession.cpp
pv/sigsession.h

index 65fc8fff7c858312fa77a902d8df9d33ea3acddd..292430b6f0969290d206258bc2859fa10b0f041e 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <boost/thread/thread.hpp>
 
 
 #include <boost/thread/thread.hpp>
 
+#include <stdexcept>
+
 #include <QDebug>
 
 #include "decoder.h"
 #include <QDebug>
 
 #include "decoder.h"
@@ -51,7 +53,9 @@ Decoder::Decoder(const srd_decoder *const dec,
        _session(NULL),
        _decoder_inst(NULL)
 {
        _session(NULL),
        _decoder_inst(NULL)
 {
-       init_decoder();
+       if (!init_decoder())
+               throw runtime_error("Failed to initialise decoder.");
+
        begin_decode();
 }
 
        begin_decode();
 }
 
@@ -101,7 +105,7 @@ void Decoder::clear_snapshots()
 {
 }
 
 {
 }
 
-void Decoder::init_decoder()
+bool Decoder::init_decoder()
 {
        if (!_probes.empty())
        {
 {
        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";
        _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;
        }
 
        _decoder_inst->data_samplerate = _samplerate;
@@ -144,6 +148,8 @@ void Decoder::init_decoder()
        }
 
        srd_inst_probe_set_all(_decoder_inst, probes);
        }
 
        srd_inst_probe_set_all(_decoder_inst, probes);
+
+       return true;
 }
 
 void Decoder::decode_proc(shared_ptr<data::Logic> data)
 }
 
 void Decoder::decode_proc(shared_ptr<data::Logic> data)
index 93d8fa6a89fb8dae531e48d9f01e0f7c5d4526d7..264920a723422c9bf51f5e1fb6947e9f5e03f759 100644 (file)
@@ -80,7 +80,7 @@ public:
 private:
        void begin_decode();
 
 private:
        void begin_decode();
 
-       void init_decoder();
+       bool init_decoder();
 
        void decode_proc(boost::shared_ptr<data::Logic> data);
 
 
        void decode_proc(boost::shared_ptr<data::Logic> data);
 
index a69f068e804f3d249ec831f59395e5dcec31904e..e81d36051fa068e361eafb01c18ef3aeee02caaa 100644 (file)
@@ -34,6 +34,8 @@
 
 #include <assert.h>
 
 
 #include <assert.h>
 
+#include <stdexcept>
+
 #include <sys/stat.h>
 
 #include <QDebug>
 #include <sys/stat.h>
 
 #include <QDebug>
@@ -193,11 +195,12 @@ boost::shared_ptr<data::Logic> SigSession::get_data()
        return _logic_data;
 }
 
        return _logic_data;
 }
 
-void SigSession::add_decoder(srd_decoder *const dec,
+bool SigSession::add_decoder(srd_decoder *const dec,
        std::map<const srd_probe*,
                boost::shared_ptr<view::Signal> > probes,
        GHashTable *options)
 {
        std::map<const srd_probe*,
                boost::shared_ptr<view::Signal> > probes,
        GHashTable *options)
 {
+       try
        {
                lock_guard<mutex> lock(_signals_mutex);
 
        {
                lock_guard<mutex> lock(_signals_mutex);
 
@@ -208,7 +211,14 @@ void SigSession::add_decoder(srd_decoder *const dec,
                                _decode_traces.size()));
                _decode_traces.push_back(d);
        }
                                _decode_traces.size()));
                _decode_traces.push_back(d);
        }
+       catch(std::runtime_error e)
+       {
+               return false;
+       }
+
        signals_changed();
        signals_changed();
+
+       return true;
 }
 
 vector< shared_ptr<view::DecodeSignal> > SigSession::get_decode_signals() const
 }
 
 vector< shared_ptr<view::DecodeSignal> > SigSession::get_decode_signals() const
index e0eb493853cb54d871f2aafc5e8e15b21376a232..499814cadbb4c223294382aa520c19d80bc9a091 100644 (file)
@@ -93,7 +93,7 @@ public:
 
        boost::shared_ptr<data::Logic> get_data();
 
 
        boost::shared_ptr<data::Logic> get_data();
 
-       void add_decoder(srd_decoder *const dec,
+       bool add_decoder(srd_decoder *const dec,
                std::map<const srd_probe*,
                        boost::shared_ptr<view::Signal> > probes,
                GHashTable *options);
                std::map<const srd_probe*,
                        boost::shared_ptr<view::Signal> > probes,
                GHashTable *options);