diff options
Diffstat (limited to 'host')
-rw-r--r-- | host/include/uhd/property_tree.hpp | 9 | ||||
-rw-r--r-- | host/include/uhd/property_tree.ipp | 10 | ||||
-rw-r--r-- | host/lib/usrp/cores/time64_core_200.cpp | 7 | ||||
-rw-r--r-- | host/tests/property_test.cpp | 7 |
4 files changed, 25 insertions, 8 deletions
diff --git a/host/include/uhd/property_tree.hpp b/host/include/uhd/property_tree.hpp index b20f3b779..c41a129b1 100644 --- a/host/include/uhd/property_tree.hpp +++ b/host/include/uhd/property_tree.hpp @@ -31,7 +31,7 @@ namespace uhd{ * A templated property interface for holding a value * and registering callbacks when that value changes. */ -template <typename T> class UHD_API property : boost::noncopyable{ +template <typename T> class property : boost::noncopyable{ public: typedef boost::function<void(const T &)> subscriber_type; typedef boost::function<T(void)> publisher_type; @@ -89,6 +89,13 @@ public: * \return the current value in the property */ virtual T get(void) const = 0; + + /*! + * A property is empty if it has never been set. + * A property with a publisher is never empty. + * \return true if the property is empty + */ + virtual bool empty(void) const = 0; }; /*! diff --git a/host/include/uhd/property_tree.ipp b/host/include/uhd/property_tree.ipp index 58ee2339c..868cba475 100644 --- a/host/include/uhd/property_tree.ipp +++ b/host/include/uhd/property_tree.ipp @@ -27,7 +27,7 @@ **********************************************************************/ namespace uhd{ namespace /*anon*/{ -template <typename T> class UHD_API property_impl : public property<T>{ +template <typename T> class property_impl : public property<T>{ public: property<T> &coerce(const typename property<T>::coercer_type &coercer){ @@ -59,12 +59,14 @@ public: } T get(void) const{ - if (_publisher.empty() and _value.get() == NULL) throw uhd::runtime_error( - "Called get() on property with an uninitialized value" - ); + if (empty()) throw uhd::runtime_error("Cannot get() on an empty property"); return _publisher.empty()? *_value : _publisher(); } + bool empty(void) const{ + return _publisher.empty() and _value.get() == NULL; + } + private: std::vector<typename property<T>::subscriber_type> _subscribers; typename property<T>::publisher_type _publisher; diff --git a/host/lib/usrp/cores/time64_core_200.cpp b/host/lib/usrp/cores/time64_core_200.cpp index 843d4bdfb..772a2a2bb 100644 --- a/host/lib/usrp/cores/time64_core_200.cpp +++ b/host/lib/usrp/cores/time64_core_200.cpp @@ -18,6 +18,7 @@ #include "time64_core_200.hpp" #include <uhd/exception.hpp> #include <uhd/utils/assert_has.hpp> +#include <boost/math/special_functions/round.hpp> #define REG_TIME64_SECS _base + 0 #define REG_TIME64_TICKS _base + 4 @@ -58,11 +59,11 @@ public: void set_tick_rate(const double rate){ _tick_rate = rate; - _iface->poke32(REG_TIME64_TPS, rate); + _iface->poke32(REG_TIME64_TPS, boost::math::iround(rate)); } uhd::time_spec_t get_time_now(void){ - for (size_t i = 0; i < 3; i++){ //special algorithm because we cant rest 64 bits synchronously + for (size_t i = 0; i < 3; i++){ //special algorithm because we cant read 64 bits synchronously const boost::uint32_t secs = _iface->peek32(_readback_bases.rb_secs_imm); const boost::uint32_t ticks = _iface->peek32(_readback_bases.rb_ticks_imm); if (secs != _iface->peek32(_readback_bases.rb_secs_imm)) continue; @@ -72,7 +73,7 @@ public: } uhd::time_spec_t get_time_last_pps(void){ - for (size_t i = 0; i < 3; i++){ //special algorithm because we cant rest 64 bits synchronously + for (size_t i = 0; i < 3; i++){ //special algorithm because we cant read 64 bits synchronously const boost::uint32_t secs = _iface->peek32(_readback_bases.rb_secs_pps); const boost::uint32_t ticks = _iface->peek32(_readback_bases.rb_ticks_pps); if (secs != _iface->peek32(_readback_bases.rb_secs_pps)) continue; diff --git a/host/tests/property_test.cpp b/host/tests/property_test.cpp index 20f6b6924..4c1aa046c 100644 --- a/host/tests/property_test.cpp +++ b/host/tests/property_test.cpp @@ -46,6 +46,11 @@ struct getter_type{ BOOST_AUTO_TEST_CASE(test_prop_simple){ uhd::property_tree::sptr tree = uhd::property_tree::make(); uhd::property<int> &prop = tree->create<int>("/"); + + BOOST_CHECK(prop.empty()); + prop.set(0); + BOOST_CHECK(not prop.empty()); + prop.set(42); BOOST_CHECK_EQUAL(prop.get(), 42); prop.set(34); @@ -72,8 +77,10 @@ BOOST_AUTO_TEST_CASE(test_prop_with_publisher){ uhd::property_tree::sptr tree = uhd::property_tree::make(); uhd::property<int> &prop = tree->create<int>("/"); + BOOST_CHECK(prop.empty()); getter_type getter; prop.publish(boost::bind(&getter_type::doit, &getter)); + BOOST_CHECK(not prop.empty()); getter._x = 42; prop.set(0); //should not change |