aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDimitri Stolnikov <horiz0n@gmx.net>2013-06-08 17:13:16 +0200
committerDimitri Stolnikov <horiz0n@gmx.net>2013-06-08 17:13:16 +0200
commitfaa1f44550aa4ad823da5f480d7b5bcbb725d1b1 (patch)
tree1615cc2466f403efc4ae4cd653509dfeaf2f7bef
parent1822e881482b87013af935b92db79c77bf510a73 (diff)
return cached values in setters immediately if same as requested
-rw-r--r--lib/osmosdr_sink_c_impl.cc40
-rw-r--r--lib/osmosdr_source_c_impl.cc40
2 files changed, 48 insertions, 32 deletions
diff --git a/lib/osmosdr_sink_c_impl.cc b/lib/osmosdr_sink_c_impl.cc
index 8e08444..0130582 100644
--- a/lib/osmosdr_sink_c_impl.cc
+++ b/lib/osmosdr_sink_c_impl.cc
@@ -252,11 +252,12 @@ double osmosdr_sink_c_impl::set_center_freq( double freq, size_t chan )
size_t channel = 0;
BOOST_FOREACH( osmosdr_snk_iface *dev, _devs )
for (size_t dev_chan = 0; dev_chan < dev->get_num_channels(); dev_chan++)
- if ( chan == channel++ )
+ if ( chan == channel++ ) {
if ( _center_freq[ chan ] != freq ) {
_center_freq[ chan ] = freq;
return dev->set_center_freq( freq, dev_chan );
- }
+ } else { return _center_freq[ chan ]; }
+ }
return 0;
}
@@ -277,11 +278,12 @@ double osmosdr_sink_c_impl::set_freq_corr( double ppm, size_t chan )
size_t channel = 0;
BOOST_FOREACH( osmosdr_snk_iface *dev, _devs )
for (size_t dev_chan = 0; dev_chan < dev->get_num_channels(); dev_chan++)
- if ( chan == channel++ )
+ if ( chan == channel++ ) {
if ( _freq_corr[ chan ] != ppm ) {
_freq_corr[ chan ] = ppm;
return dev->set_freq_corr( ppm, dev_chan );
- }
+ } else { return _freq_corr[ chan ]; }
+ }
return 0;
}
@@ -335,14 +337,15 @@ bool osmosdr_sink_c_impl::set_gain_mode( bool automatic, size_t chan )
size_t channel = 0;
BOOST_FOREACH( osmosdr_snk_iface *dev, _devs )
for (size_t dev_chan = 0; dev_chan < dev->get_num_channels(); dev_chan++)
- if ( chan == channel++ )
+ if ( chan == channel++ ) {
if ( _gain_mode[ chan ] != automatic ) {
_gain_mode[ chan ] = automatic;
bool mode = dev->set_gain_mode( automatic, dev_chan );
if (!automatic) // reapply gain value when switched to manual mode
dev->set_gain( _gain[ chan ], dev_chan );
return mode;
- }
+ } else { return _gain_mode[ chan ]; }
+ }
return false;
}
@@ -363,11 +366,12 @@ double osmosdr_sink_c_impl::set_gain( double gain, size_t chan )
size_t channel = 0;
BOOST_FOREACH( osmosdr_snk_iface *dev, _devs )
for (size_t dev_chan = 0; dev_chan < dev->get_num_channels(); dev_chan++)
- if ( chan == channel++ )
+ if ( chan == channel++ ) {
if ( _gain[ chan ] != gain ) {
_gain[ chan ] = gain;
return dev->set_gain( gain, dev_chan );
- }
+ } else { return _gain[ chan ]; }
+ }
return 0;
}
@@ -410,11 +414,12 @@ double osmosdr_sink_c_impl::set_if_gain( double gain, size_t chan )
size_t channel = 0;
BOOST_FOREACH( osmosdr_snk_iface *dev, _devs )
for (size_t dev_chan = 0; dev_chan < dev->get_num_channels(); dev_chan++)
- if ( chan == channel++ )
+ if ( chan == channel++ ) {
if ( _if_gain[ chan ] != gain ) {
_if_gain[ chan ] = gain;
return dev->set_if_gain( gain, dev_chan );
- }
+ } else { return _if_gain[ chan ]; }
+ }
return 0;
}
@@ -424,11 +429,12 @@ double osmosdr_sink_c_impl::set_bb_gain( double gain, size_t chan )
size_t channel = 0;
BOOST_FOREACH( osmosdr_snk_iface *dev, _devs )
for (size_t dev_chan = 0; dev_chan < dev->get_num_channels(); dev_chan++)
- if ( chan == channel++ )
+ if ( chan == channel++ ) {
if ( _bb_gain[ chan ] != gain ) {
_bb_gain[ chan ] = gain;
return dev->set_bb_gain( gain, dev_chan );
- }
+ } else { return _bb_gain[ chan ]; }
+ }
return 0;
}
@@ -449,11 +455,12 @@ std::string osmosdr_sink_c_impl::set_antenna( const std::string & antenna, size_
size_t channel = 0;
BOOST_FOREACH( osmosdr_snk_iface *dev, _devs )
for (size_t dev_chan = 0; dev_chan < dev->get_num_channels(); dev_chan++)
- if ( chan == channel++ )
+ if ( chan == channel++ ) {
if ( _antenna[ chan ] != antenna ) {
_antenna[ chan ] = antenna;
return dev->set_antenna( antenna, dev_chan );
- }
+ } else { return _antenna[ chan ]; }
+ }
return "";
}
@@ -484,11 +491,12 @@ double osmosdr_sink_c_impl::set_bandwidth( double bandwidth, size_t chan )
size_t channel = 0;
BOOST_FOREACH( osmosdr_snk_iface *dev, _devs )
for (size_t dev_chan = 0; dev_chan < dev->get_num_channels(); dev_chan++)
- if ( chan == channel++ )
+ if ( chan == channel++ ) {
if ( _bandwidth[ chan ] != bandwidth ) {
_bandwidth[ chan ] = bandwidth;
return dev->set_bandwidth( bandwidth, dev_chan );
- }
+ } else { return _bandwidth[ chan ]; }
+ }
return 0;
}
diff --git a/lib/osmosdr_source_c_impl.cc b/lib/osmosdr_source_c_impl.cc
index 09f29cb..d811afe 100644
--- a/lib/osmosdr_source_c_impl.cc
+++ b/lib/osmosdr_source_c_impl.cc
@@ -386,11 +386,12 @@ double osmosdr_source_c_impl::set_center_freq( double freq, size_t chan )
size_t channel = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _devs )
for (size_t dev_chan = 0; dev_chan < dev->get_num_channels(); dev_chan++)
- if ( chan == channel++ )
+ if ( chan == channel++ ) {
if ( _center_freq[ chan ] != freq ) {
_center_freq[ chan ] = freq;
return dev->set_center_freq( freq, dev_chan );
- }
+ } else { return _center_freq[ chan ]; }
+ }
return 0;
}
@@ -411,11 +412,12 @@ double osmosdr_source_c_impl::set_freq_corr( double ppm, size_t chan )
size_t channel = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _devs )
for (size_t dev_chan = 0; dev_chan < dev->get_num_channels(); dev_chan++)
- if ( chan == channel++ )
+ if ( chan == channel++ ) {
if ( _freq_corr[ chan ] != ppm ) {
_freq_corr[ chan ] = ppm;
return dev->set_freq_corr( ppm, dev_chan );
- }
+ } else { return _freq_corr[ chan ]; }
+ }
return 0;
}
@@ -469,14 +471,15 @@ bool osmosdr_source_c_impl::set_gain_mode( bool automatic, size_t chan )
size_t channel = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _devs )
for (size_t dev_chan = 0; dev_chan < dev->get_num_channels(); dev_chan++)
- if ( chan == channel++ )
+ if ( chan == channel++ ) {
if ( _gain_mode[ chan ] != automatic ) {
_gain_mode[ chan ] = automatic;
bool mode = dev->set_gain_mode( automatic, dev_chan );
if (!automatic) // reapply gain value when switched to manual mode
dev->set_gain( _gain[ chan ], dev_chan );
return mode;
- }
+ } else { return _gain_mode[ chan ]; }
+ }
return false;
}
@@ -497,11 +500,12 @@ double osmosdr_source_c_impl::set_gain( double gain, size_t chan )
size_t channel = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _devs )
for (size_t dev_chan = 0; dev_chan < dev->get_num_channels(); dev_chan++)
- if ( chan == channel++ )
+ if ( chan == channel++ ) {
if ( _gain[ chan ] != gain ) {
_gain[ chan ] = gain;
return dev->set_gain( gain, dev_chan );
- }
+ } else { return _gain[ chan ]; }
+ }
return 0;
}
@@ -544,11 +548,12 @@ double osmosdr_source_c_impl::set_if_gain( double gain, size_t chan )
size_t channel = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _devs )
for (size_t dev_chan = 0; dev_chan < dev->get_num_channels(); dev_chan++)
- if ( chan == channel++ )
+ if ( chan == channel++ ) {
if ( _if_gain[ chan ] != gain ) {
_if_gain[ chan ] = gain;
return dev->set_if_gain( gain, dev_chan );
- }
+ } else { return _if_gain[ chan ]; }
+ }
return 0;
}
@@ -558,11 +563,12 @@ double osmosdr_source_c_impl::set_bb_gain( double gain, size_t chan )
size_t channel = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _devs )
for (size_t dev_chan = 0; dev_chan < dev->get_num_channels(); dev_chan++)
- if ( chan == channel++ )
+ if ( chan == channel++ ) {
if ( _bb_gain[ chan ] != gain ) {
_bb_gain[ chan ] = gain;
return dev->set_bb_gain( gain, dev_chan );
- }
+ } else { return _bb_gain[ chan ]; }
+ }
return 0;
}
@@ -583,11 +589,12 @@ std::string osmosdr_source_c_impl::set_antenna( const std::string & antenna, siz
size_t channel = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _devs )
for (size_t dev_chan = 0; dev_chan < dev->get_num_channels(); dev_chan++)
- if ( chan == channel++ )
+ if ( chan == channel++ ) {
if ( _antenna[ chan ] != antenna ) {
_antenna[ chan ] = antenna;
return dev->set_antenna( antenna, dev_chan );
- }
+ } else { return _antenna[ chan ]; }
+ }
return "";
}
@@ -666,11 +673,12 @@ double osmosdr_source_c_impl::set_bandwidth( double bandwidth, size_t chan )
size_t channel = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _devs )
for (size_t dev_chan = 0; dev_chan < dev->get_num_channels(); dev_chan++)
- if ( chan == channel++ )
+ if ( chan == channel++ ) {
if ( _bandwidth[ chan ] != bandwidth ) {
_bandwidth[ chan ] = bandwidth;
return dev->set_bandwidth( bandwidth, dev_chan );
- }
+ } else { return _bandwidth[ chan ]; }
+ }
return 0;
}