Moved decoder config into the popup
[pulseview.git] / pv / sigsession.cpp
index aadaf45011451bc21bad01045f7781347cd1aaaa..aeb6d22072f55f6bc49c04dd389295fd852b5c6a 100644 (file)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <libsigrokdecode/libsigrokdecode.h>
+
 #include "sigsession.h"
 
 #include "devicemanager.h"
@@ -36,6 +38,8 @@
 
 #include <stdexcept>
 
+#include <boost/foreach.hpp>
+
 #include <sys/stat.h>
 
 #include <QDebug>
@@ -195,17 +199,34 @@ boost::shared_ptr<data::Logic> SigSession::get_data()
        return _logic_data;
 }
 
-bool SigSession::add_decoder(srd_decoder *const dec,
-       std::map<const srd_probe*,
-               boost::shared_ptr<view::LogicSignal> > probes,
-       GHashTable *options)
+bool SigSession::add_decoder(srd_decoder *const dec)
 {
+       map<const srd_probe*, shared_ptr<view::LogicSignal> > probes;
+
        try
        {
                lock_guard<mutex> lock(_signals_mutex);
 
-               shared_ptr<data::Decoder> decoder(
-                       new data::Decoder(dec, probes, options));
+               // Create the decoder
+               shared_ptr<data::Decoder> decoder(new data::Decoder(dec));
+
+               // Auto select the initial probes
+               for(const GSList *i = dec->probes; i; i = i->next)
+               {
+                       const srd_probe *const probe = (const srd_probe*)i->data;
+                       BOOST_FOREACH(shared_ptr<view::Signal> s, _signals)
+                       {
+                               shared_ptr<view::LogicSignal> l =
+                                       dynamic_pointer_cast<view::LogicSignal>(s);
+                               if (l && QString(probe->name).toLower().contains(
+                                       l->get_name().toLower()))
+                                       probes[probe] = l;
+                       }
+               }
+
+               decoder->set_probes(probes);
+
+               // Create the decode signal
                shared_ptr<view::DecodeSignal> d(
                        new view::DecodeSignal(*this, decoder,
                                _decode_traces.size()));
@@ -428,8 +449,8 @@ void SigSession::read_sample_rate(const sr_dev_inst *const sdi)
        // Read out the sample rate
        if(sdi->driver)
        {
-               const int ret = sr_config_get(sdi->driver,
-                       SR_CONF_SAMPLERATE, &gvar, sdi);
+               const int ret = sr_config_get(sdi->driver, sdi, NULL,
+                       SR_CONF_SAMPLERATE, &gvar);
                if (ret != SR_OK) {
                        qDebug("Failed to get samplerate\n");
                        return;
@@ -505,7 +526,7 @@ void SigSession::sample_thread_proc(struct sr_dev_inst *sdi,
        }
 
        // Set the sample limit
-       if (sr_config_set(sdi, SR_CONF_LIMIT_SAMPLES,
+       if (sr_config_set(sdi, NULL, SR_CONF_LIMIT_SAMPLES,
                g_variant_new_uint64(record_length)) != SR_OK) {
                error_handler(tr("Failed to configure "
                        "time-based sample limit."));