From: Joel Holdsworth Date: Sat, 22 Nov 2014 14:11:03 +0000 (+0000) Subject: Check LIMIT_SAMPLES and SAMPLERATE are available to read before reading them X-Git-Tag: pulseview-0.3.0~435 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=ed1d9d81f46c6595bea7278aa5dc9c1213c81609;p=pulseview.git Check LIMIT_SAMPLES and SAMPLERATE are available to read before reading them This fixes bug #487 --- diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index fb457f6d..80830214 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -421,8 +421,12 @@ shared_ptr SigSession::signal_from_channel( void SigSession::read_sample_rate(shared_ptr device) { - uint64_t sample_rate = VariantBase::cast_dynamic>( - 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>( + device->config_get(ConfigKey::SAMPLERATE)).get() : 0; // Set the sample rate of all data const set< shared_ptr > data_set = get_data(); @@ -507,13 +511,14 @@ void SigSession::feed_in_logic(shared_ptr logic) set_capture_state(Running); // Get sample limit. - uint64_t sample_limit; - try { - sample_limit = VariantBase::cast_dynamic>( - 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>( + device_->config_get(ConfigKey::LIMIT_SAMPLES)).get() : 0; // Create a new data snapshot cur_logic_snapshot_ = shared_ptr( diff --git a/pv/toolbars/samplingbar.cpp b/pv/toolbars/samplingbar.cpp index 4a692652..ddca7b59 100644 --- a/pv/toolbars/samplingbar.cpp +++ b/pv/toolbars/samplingbar.cpp @@ -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);