]> sigrok.org Git - pulseview.git/commitdiff
Check LIMIT_SAMPLES and SAMPLERATE are available to read before reading them
authorJoel Holdsworth <redacted>
Sat, 22 Nov 2014 14:11:03 +0000 (14:11 +0000)
committerJoel Holdsworth <redacted>
Sat, 22 Nov 2014 15:15:34 +0000 (15:15 +0000)
This fixes bug #487

pv/sigsession.cpp
pv/toolbars/samplingbar.cpp

index fb457f6dcd7599003cf0d0b9981e3c07424fc507..80830214877148f38a6100c06dc43bbc56c0a134 100644 (file)
@@ -421,8 +421,12 @@ shared_ptr<view::Signal> SigSession::signal_from_channel(
 
 void SigSession::read_sample_rate(shared_ptr<Device> device)
 {
-       uint64_t sample_rate = VariantBase::cast_dynamic<Variant<guint64>>(
-               device->config_get(ConfigKey::SAMPLERATE)).get();
+       const auto keys = device_->config_keys(ConfigKey::DEVICE_OPTIONS);
+       const auto iter = keys.find(ConfigKey::SAMPLERATE);
+       const uint64_t sample_rate = (iter != keys.end() &&
+               (*iter).second.find(sigrok::GET) != (*iter).second.end()) ?
+               VariantBase::cast_dynamic<Variant<guint64>>(
+                       device->config_get(ConfigKey::SAMPLERATE)).get() : 0;
 
        // Set the sample rate of all data
        const set< shared_ptr<data::SignalData> > data_set = get_data();
@@ -507,13 +511,14 @@ void SigSession::feed_in_logic(shared_ptr<Logic> logic)
                set_capture_state(Running);
 
                // Get sample limit.
-               uint64_t sample_limit;
-               try {
-                       sample_limit = VariantBase::cast_dynamic<Variant<guint64>>(
-                               device_->config_get(ConfigKey::LIMIT_SAMPLES)).get();
-               } catch (Error) {
-                       sample_limit = 0;
-               }
+               const auto keys = device_->config_keys(
+                       ConfigKey::DEVICE_OPTIONS);
+               const auto iter = keys.find(ConfigKey::LIMIT_SAMPLES);
+               const uint64_t sample_limit = (iter != keys.end() &&
+                       (*iter).second.find(sigrok::GET) !=
+                       (*iter).second.end()) ?
+                       VariantBase::cast_dynamic<Variant<guint64>>(
+                       device_->config_get(ConfigKey::LIMIT_SAMPLES)).get() : 0;
 
                // Create a new data snapshot
                cur_logic_snapshot_ = shared_ptr<data::LogicSnapshot>(
index 4a69265258f3e3b83678a6a0e3ef026401e49daf..ddca7b5961a8145155c2a64ab0f9f6df0e1fea33 100644 (file)
@@ -177,9 +177,12 @@ void SamplingBar::update_sample_rate_selector()
        assert(!updating_sample_rate_);
        updating_sample_rate_ = true;
 
-       try {
+       const auto keys = device->config_keys(ConfigKey::DEVICE_OPTIONS);
+       const auto iter = keys.find(ConfigKey::SAMPLERATE);
+       if (iter != keys.end() &&
+               (*iter).second.find(sigrok::LIST) != (*iter).second.end()) {
                gvar_dict = device->config_list(ConfigKey::SAMPLERATE);
-       } catch (Error error) {
+       } else {
                sample_rate_.show_none();
                updating_sample_rate_ = false;
                return;
@@ -275,11 +278,14 @@ void SamplingBar::update_sample_count_selector()
        if (sample_count == 0)
                sample_count = DefaultSampleCount;
 
-       try {
+       const auto keys = device->config_keys(ConfigKey::DEVICE_OPTIONS);
+       const auto iter = keys.find(ConfigKey::LIMIT_SAMPLES);
+       if (iter != keys.end() &&
+               (*iter).second.find(sigrok::LIST) != (*iter).second.end()) {
                auto gvar = device->config_list(ConfigKey::LIMIT_SAMPLES);
                g_variant_get(gvar.gobj(), "(tt)",
                        &min_sample_count, &max_sample_count);
-       } catch (Error error) {}
+       }
 
        min_sample_count = min(max(min_sample_count, MinSampleCount),
                max_sample_count);