diff options
| -rw-r--r-- | host/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | host/docs/build.rst | 2 | ||||
| -rw-r--r-- | host/include/uhd/utils/assert.hpp | 33 | ||||
| -rw-r--r-- | host/include/uhd/utils/props.hpp | 29 | ||||
| -rw-r--r-- | host/include/uhd/utils/safe_main.hpp | 3 | ||||
| -rw-r--r-- | host/lib/usrp/dboard/db_basic_and_lf.cpp | 12 | ||||
| -rw-r--r-- | host/lib/usrp/dboard/db_rfx.cpp | 14 | ||||
| -rw-r--r-- | host/lib/usrp/dboard/db_xcvr2450.cpp | 15 | ||||
| -rw-r--r-- | host/lib/usrp/usrp2/dboard_impl.cpp | 10 | ||||
| -rw-r--r-- | host/lib/usrp/usrp2/dsp_impl.cpp | 10 | ||||
| -rw-r--r-- | host/lib/usrp/usrp2/mboard_impl.cpp | 8 | ||||
| -rw-r--r-- | host/lib/usrp/usrp2/usrp2_impl.cpp | 3 | ||||
| -rw-r--r-- | host/test/gain_handler_test.cpp | 6 | 
13 files changed, 86 insertions, 61 deletions
| diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index 4ef6278b9..bf8d71b21 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -76,7 +76,7 @@ ENDIF(WIN32)  # Setup Boost  ########################################################################  SET(Boost_ADDITIONAL_VERSIONS "1.42.0" "1.42") -FIND_PACKAGE(Boost 1.36 REQUIRED COMPONENTS +FIND_PACKAGE(Boost 1.37 REQUIRED COMPONENTS      date_time      filesystem      program_options diff --git a/host/docs/build.rst b/host/docs/build.rst index d28682764..81e61475e 100644 --- a/host/docs/build.rst +++ b/host/docs/build.rst @@ -40,7 +40,7 @@ CMake  ^^^^^^^^^^^^^^^^  Boost  ^^^^^^^^^^^^^^^^ -* **Version:** at least 3.6 unix, at least 4.0 windows +* **Version:** at least 3.7 unix, at least 4.0 windows  * **Required for:** build time + run time  * **Download URL:** http://www.boost.org/users/download/  * **Download URL (windows installer):** http://www.boostpro.com/download diff --git a/host/include/uhd/utils/assert.hpp b/host/include/uhd/utils/assert.hpp index 842ed8dfa..773acd634 100644 --- a/host/include/uhd/utils/assert.hpp +++ b/host/include/uhd/utils/assert.hpp @@ -18,27 +18,27 @@  #ifndef INCLUDED_UHD_UTILS_ASSERT_HPP  #define INCLUDED_UHD_UTILS_ASSERT_HPP +#include <uhd/config.hpp>  #include <uhd/utils/algorithm.hpp>  #include <boost/format.hpp>  #include <boost/foreach.hpp>  #include <boost/lexical_cast.hpp> -#include <boost/current_function.hpp> +#include <boost/throw_exception.hpp> +#include <boost/exception/info.hpp>  #include <stdexcept> +#include <string>  namespace uhd{ -    class assert_error : public std::logic_error{ -    public: -        explicit assert_error(const std::string& what_arg) : logic_error(what_arg){ -            /* NOP */ -        } -    }; +    //! The exception to throw when assertions fail +    struct UHD_API assert_error : virtual std::exception, virtual boost::exception{}; -    #define ASSERT_THROW(_x) if (not (_x)) { \ -        throw uhd::assert_error(str(boost::format( \ -            "Assertion Failed:\n  %s:%d\n  %s\n  ---> %s <---" \ -        ) % __FILE__ % __LINE__ % BOOST_CURRENT_FUNCTION % std::string(#_x))); \ -    } +    //! The assertion info, the code that failed +    typedef boost::error_info<struct tag_assert_info, std::string> assert_info; + +    //! Throw an assert error with throw-site information +    #define ASSERT_THROW(_x) if (not (_x)) \ +        BOOST_THROW_EXCEPTION(uhd::assert_error() << uhd::assert_info(#_x))      /*!       * Check that an element is found in a container. @@ -58,17 +58,18 @@ namespace uhd{      ){          if (std::has(iterable, elem)) return;          std::string possible_values = ""; -        BOOST_FOREACH(T e, iterable){ -            if (e != iterable.begin()[0]) possible_values += ", "; +        size_t i = 0; +        BOOST_FOREACH(const T &e, iterable){ +            if (i++ > 0) possible_values += ", ";              possible_values += boost::lexical_cast<std::string>(e);          } -        throw uhd::assert_error(str(boost::format( +        boost::throw_exception(uhd::assert_error() << assert_info(str(boost::format(                  "Error: %s is not a valid %s. "                  "Possible values are: [%s]."              )              % boost::lexical_cast<std::string>(elem)              % what % possible_values -        )); +        )));      }  }//namespace uhd diff --git a/host/include/uhd/utils/props.hpp b/host/include/uhd/utils/props.hpp index 6be0b2ce5..bfbca4273 100644 --- a/host/include/uhd/utils/props.hpp +++ b/host/include/uhd/utils/props.hpp @@ -21,6 +21,9 @@  #include <uhd/config.hpp>  #include <uhd/wax.hpp>  #include <boost/tuple/tuple.hpp> +#include <boost/throw_exception.hpp> +#include <boost/exception/info.hpp> +#include <stdexcept>  #include <vector>  #include <string> @@ -35,14 +38,36 @@ namespace uhd{       * \param key a reference to the prop object       * \param name a reference to the name object       */ -    inline UHD_API named_prop_t //must be exported as part of the api to work (TODO move guts to cpp file) -    extract_named_prop(const wax::obj &key, const std::string &name = ""){ +    inline UHD_API named_prop_t extract_named_prop( +        const wax::obj &key, +        const std::string &name = "" +    ){          if (key.type() == typeid(named_prop_t)){              return key.as<named_prop_t>();          }          return named_prop_t(key, name);      } +    //! The exception to throw for property errors +    struct UHD_API prop_error : virtual std::exception, virtual boost::exception{}; + +    //! The property error info (verbose or message) +    typedef boost::error_info<struct tag_prop_info, std::string> prop_info; + +    /*! +     * Throw an error when trying to get a write only property. +     * Throw-site information will be included with this error. +     */ +    #define UHD_THROW_PROP_WRITE_ONLY() \ +        BOOST_THROW_EXCEPTION(uhd::prop_error() << uhd::prop_info("cannot get write-only property")) + +    /*! +     * Throw an error when trying to set a read only property. +     * Throw-site information will be included with this error. +     */ +    #define UHD_THROW_PROP_READ_ONLY() \ +        BOOST_THROW_EXCEPTION(uhd::prop_error() << uhd::prop_info("cannot set read-only property")) +  } //namespace uhd  #endif /* INCLUDED_UHD_UTILS_PROPS_HPP */ diff --git a/host/include/uhd/utils/safe_main.hpp b/host/include/uhd/utils/safe_main.hpp index b682aa540..a4e4e06e8 100644 --- a/host/include/uhd/utils/safe_main.hpp +++ b/host/include/uhd/utils/safe_main.hpp @@ -19,6 +19,7 @@  #define INCLUDED_UHD_UTILS_SAFE_MAIN_HPP  #include <uhd/config.hpp> +#include <boost/exception/diagnostic_information.hpp>  #include <iostream>  #include <stdexcept> @@ -33,6 +34,8 @@  int main(int argc, char *argv[]){ \      try { \          return _main(argc, argv); \ +    } catch(const boost::exception &e){ \ +        std::cerr << "Error: " << boost::diagnostic_information(e) << std::endl; \      } catch(const std::exception &e) { \          std::cerr << "Error: " << e.what() << std::endl; \      } catch(...) { \ diff --git a/host/lib/usrp/dboard/db_basic_and_lf.cpp b/host/lib/usrp/dboard/db_basic_and_lf.cpp index aad2398d8..c7b841efb 100644 --- a/host/lib/usrp/dboard/db_basic_and_lf.cpp +++ b/host/lib/usrp/dboard/db_basic_and_lf.cpp @@ -153,6 +153,8 @@ void basic_rx::rx_get(const wax::obj &key_, wax::obj &val){      case SUBDEV_PROP_USE_LO_OFFSET:          val = false;          return; + +    default: UHD_THROW_PROP_WRITE_ONLY();      }  } @@ -174,9 +176,7 @@ void basic_rx::rx_set(const wax::obj &key_, const wax::obj &val){      case SUBDEV_PROP_FREQ:          return; // it wont do you much good, but you can set it -    default: throw std::runtime_error(str(boost::format( -            "Error: trying to set read-only property on %s subdev" -        ) % dboard_id::to_string(get_rx_id()))); +    default: UHD_THROW_PROP_READ_ONLY();      }  } @@ -248,6 +248,8 @@ void basic_tx::tx_get(const wax::obj &key_, wax::obj &val){      case SUBDEV_PROP_USE_LO_OFFSET:          val = false;          return; + +    default: UHD_THROW_PROP_WRITE_ONLY();      }  } @@ -269,8 +271,6 @@ void basic_tx::tx_set(const wax::obj &key_, const wax::obj &val){      case SUBDEV_PROP_FREQ:          return; // it wont do you much good, but you can set it -    default: throw std::runtime_error(str(boost::format( -            "Error: trying to set read-only property on %s subdev" -        ) % dboard_id::to_string(get_tx_id()))); +    default: UHD_THROW_PROP_READ_ONLY();      }  } diff --git a/host/lib/usrp/dboard/db_rfx.cpp b/host/lib/usrp/dboard/db_rfx.cpp index 76b2c6d7a..49ec9412c 100644 --- a/host/lib/usrp/dboard/db_rfx.cpp +++ b/host/lib/usrp/dboard/db_rfx.cpp @@ -396,6 +396,8 @@ void rfx_xcvr::rx_get(const wax::obj &key_, wax::obj &val){      case SUBDEV_PROP_USE_LO_OFFSET:          val = false;          return; + +    default: UHD_THROW_PROP_WRITE_ONLY();      }  } @@ -419,10 +421,7 @@ void rfx_xcvr::rx_set(const wax::obj &key_, const wax::obj &val){          set_rx_ant(val.as<std::string>());          return; -    default: -        throw std::runtime_error(str(boost::format( -            "Error: trying to set read-only property on %s subdev" -        ) % dboard_id::to_string(get_rx_id()))); +    default: UHD_THROW_PROP_READ_ONLY();      }  } @@ -486,6 +485,8 @@ void rfx_xcvr::tx_get(const wax::obj &key_, wax::obj &val){      case SUBDEV_PROP_USE_LO_OFFSET:          val = true;          return; + +    default: UHD_THROW_PROP_WRITE_ONLY();      }  } @@ -509,9 +510,6 @@ void rfx_xcvr::tx_set(const wax::obj &key_, const wax::obj &val){          ASSERT_THROW(val.as<std::string>() == "TX/RX");          return; -    default: -        throw std::runtime_error(str(boost::format( -            "Error: trying to set read-only property on %s subdev" -        ) % dboard_id::to_string(get_tx_id()))); +    default: UHD_THROW_PROP_READ_ONLY();      }  } diff --git a/host/lib/usrp/dboard/db_xcvr2450.cpp b/host/lib/usrp/dboard/db_xcvr2450.cpp index 2c2843d3a..2052511f8 100644 --- a/host/lib/usrp/dboard/db_xcvr2450.cpp +++ b/host/lib/usrp/dboard/db_xcvr2450.cpp @@ -352,7 +352,8 @@ static max2829_regs_t::tx_baseband_gain_t gain_to_tx_bb_reg(float &gain){          gain = 5;          return max2829_regs_t::TX_BASEBAND_GAIN_5DB;      } -    ASSERT_THROW(false); +    BOOST_THROW_EXCEPTION(std::runtime_error("should not get here")); +    return max2829_regs_t::TX_BASEBAND_GAIN_0DB;  }  /*! @@ -474,6 +475,8 @@ void xcvr2450::rx_get(const wax::obj &key_, wax::obj &val){      case SUBDEV_PROP_USE_LO_OFFSET:          val = false;          return; + +    default: UHD_THROW_PROP_WRITE_ONLY();      }  } @@ -496,9 +499,7 @@ void xcvr2450::rx_set(const wax::obj &key_, const wax::obj &val){          this->set_rx_ant(val.as<std::string>());          return; -    default: throw std::runtime_error(str(boost::format( -        "Error: trying to set read-only property on %s subdev" -    ) % dboard_id::to_string(get_rx_id()))); +    default: UHD_THROW_PROP_READ_ONLY();      }  } @@ -564,6 +565,8 @@ void xcvr2450::tx_get(const wax::obj &key_, wax::obj &val){      case SUBDEV_PROP_USE_LO_OFFSET:          val = false;          return; + +    default: UHD_THROW_PROP_WRITE_ONLY();      }  } @@ -586,8 +589,6 @@ void xcvr2450::tx_set(const wax::obj &key_, const wax::obj &val){          this->set_tx_ant(val.as<std::string>());          return; -    default: throw std::runtime_error(str(boost::format( -        "Error: trying to set read-only property on %s subdev" -    ) % dboard_id::to_string(get_tx_id()))); +    default: UHD_THROW_PROP_READ_ONLY();      }  } diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp index 8952a9f75..043609458 100644 --- a/host/lib/usrp/usrp2/dboard_impl.cpp +++ b/host/lib/usrp/usrp2/dboard_impl.cpp @@ -123,8 +123,7 @@ void usrp2_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val){          val = _rx_db_eeprom.id;          return; -    //case DBOARD_PROP_CODEC: -    //    throw std::runtime_error("unhandled prop in usrp2 dboard"); +    default: UHD_THROW_PROP_WRITE_ONLY();      }  } @@ -140,7 +139,7 @@ void usrp2_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val){          _iface->write_eeprom(I2C_ADDR_RX_DB, 0, _tx_db_eeprom.get_eeprom_bytes());          return; -    default: throw std::runtime_error("Cannot set read-only property on usrp2 dboard"); +    default: UHD_THROW_PROP_READ_ONLY();      }  } @@ -173,8 +172,7 @@ void usrp2_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val){          val = _tx_db_eeprom.id;          return; -    //case DBOARD_PROP_CODEC: -    //    throw std::runtime_error("unhandled prop in usrp2 dboard"); +    default: UHD_THROW_PROP_WRITE_ONLY();      }  } @@ -190,6 +188,6 @@ void usrp2_impl::tx_dboard_set(const wax::obj &key, const wax::obj &val){          _iface->write_eeprom(I2C_ADDR_TX_DB, 0, _tx_db_eeprom.get_eeprom_bytes());          return; -    default: throw std::runtime_error("Cannot set read-only property on usrp2 dboard"); +    default: UHD_THROW_PROP_READ_ONLY();      }  } diff --git a/host/lib/usrp/usrp2/dsp_impl.cpp b/host/lib/usrp/usrp2/dsp_impl.cpp index 204277ba7..379276f7d 100644 --- a/host/lib/usrp/usrp2/dsp_impl.cpp +++ b/host/lib/usrp/usrp2/dsp_impl.cpp @@ -117,6 +117,8 @@ void usrp2_impl::ddc_get(const wax::obj &key, wax::obj &val){      case DSP_PROP_HOST_RATE:          val = get_master_clock_freq()/_ddc_decim;          return; + +    default: UHD_THROW_PROP_WRITE_ONLY();      }  } @@ -139,8 +141,7 @@ void usrp2_impl::ddc_set(const wax::obj &key, const wax::obj &val){          }          return; -    default: -        throw std::runtime_error("Error: trying to set read-only property on usrp2 ddc0"); +    default: UHD_THROW_PROP_READ_ONLY();      }  } @@ -200,6 +201,8 @@ void usrp2_impl::duc_get(const wax::obj &key, wax::obj &val){      case DSP_PROP_HOST_RATE:          val = get_master_clock_freq()/_duc_interp;          return; + +    default: UHD_THROW_PROP_WRITE_ONLY();      }  } @@ -222,7 +225,6 @@ void usrp2_impl::duc_set(const wax::obj &key, const wax::obj &val){          }          return; -    default: -        throw std::runtime_error("Error: trying to set read-only property on usrp2 duc0"); +    default: UHD_THROW_PROP_READ_ONLY();      }  } diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index f94806c9f..2c185ec53 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -248,9 +248,7 @@ void usrp2_impl::mboard_get(const wax::obj &key_, wax::obj &val){          val = _clock_config;          return; -    default: -        throw std::runtime_error("Error: trying to get write-only property on usrp2 mboard"); - +    default: UHD_THROW_PROP_WRITE_ONLY();      }  } @@ -306,8 +304,6 @@ void usrp2_impl::mboard_set(const wax::obj &key, const wax::obj &val){          issue_ddc_stream_cmd(val.as<stream_cmd_t>());          return; -    default: -        throw std::runtime_error("Error: trying to set read-only property on usrp2 mboard"); - +    default: UHD_THROW_PROP_READ_ONLY();      }  } diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 0fa56c339..11ad812e1 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -202,9 +202,10 @@ void usrp2_impl::get(const wax::obj &key_, wax::obj &val){          val = size_t(_max_tx_samples_per_packet);          return; +    default: UHD_THROW_PROP_WRITE_ONLY();      }  }  void usrp2_impl::set(const wax::obj &, const wax::obj &){ -    throw std::runtime_error("Cannot set in usrp2 device"); +    UHD_THROW_PROP_READ_ONLY();  } diff --git a/host/test/gain_handler_test.cpp b/host/test/gain_handler_test.cpp index bf2ec5db7..0669b491a 100644 --- a/host/test/gain_handler_test.cpp +++ b/host/test/gain_handler_test.cpp @@ -72,6 +72,8 @@ private:          case PROP_GAIN_NAMES:              val = _gain_values.keys();              return; + +        default: UHD_THROW_PROP_WRITE_ONLY();          }      } @@ -87,9 +89,7 @@ private:              _gain_values[name] = val.as<float>();              return; -        case PROP_GAIN_RANGE: -        case PROP_GAIN_NAMES: -            throw std::runtime_error("cannot set this property"); +        default: UHD_THROW_PROP_READ_ONLY();          }      } | 
