diff options
Diffstat (limited to 'host/include')
-rw-r--r-- | host/include/uhd/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/include/uhd/exception.hpp | 133 | ||||
-rw-r--r-- | host/include/uhd/types/device_addr.hpp | 10 | ||||
-rw-r--r-- | host/include/uhd/types/dict.ipp | 6 | ||||
-rw-r--r-- | host/include/uhd/types/serial.hpp | 53 | ||||
-rw-r--r-- | host/include/uhd/usrp/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/include/uhd/usrp/dsp_props.hpp | 2 | ||||
-rw-r--r-- | host/include/uhd/usrp/mboard_iface.hpp | 85 | ||||
-rw-r--r-- | host/include/uhd/usrp/mboard_props.hpp | 4 | ||||
-rw-r--r-- | host/include/uhd/usrp/multi_usrp.hpp | 33 | ||||
-rw-r--r-- | host/include/uhd/usrp/tune_helper.hpp | 14 | ||||
-rw-r--r-- | host/include/uhd/utils/CMakeLists.txt | 7 | ||||
-rw-r--r-- | host/include/uhd/utils/algorithm.hpp | 62 | ||||
-rw-r--r-- | host/include/uhd/utils/assert_has.hpp (renamed from host/include/uhd/utils/assert.hpp) | 22 | ||||
-rw-r--r-- | host/include/uhd/utils/assert_has.ipp (renamed from host/include/uhd/utils/assert.ipp) | 13 | ||||
-rw-r--r-- | host/include/uhd/utils/exception.hpp | 45 | ||||
-rw-r--r-- | host/include/uhd/utils/props.hpp | 9 | ||||
-rw-r--r-- | host/include/uhd/wax.hpp | 18 |
18 files changed, 349 insertions, 169 deletions
diff --git a/host/include/uhd/CMakeLists.txt b/host/include/uhd/CMakeLists.txt index b7a22cf0b..db755511e 100644 --- a/host/include/uhd/CMakeLists.txt +++ b/host/include/uhd/CMakeLists.txt @@ -25,6 +25,7 @@ INSTALL(FILES config.hpp convert.hpp device.hpp + exception.hpp version.hpp wax.hpp DESTINATION ${INCLUDE_DIR}/uhd diff --git a/host/include/uhd/exception.hpp b/host/include/uhd/exception.hpp new file mode 100644 index 000000000..e2a50bf1e --- /dev/null +++ b/host/include/uhd/exception.hpp @@ -0,0 +1,133 @@ +// +// Copyright 2010-2011 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + +#ifndef INCLUDED_UHD_UTILS_EXCEPTION_HPP +#define INCLUDED_UHD_UTILS_EXCEPTION_HPP + +#include <uhd/config.hpp> +#include <boost/current_function.hpp> +#include <stdexcept> +#include <string> + +/*! + * Define common exceptions used throughout the code: + * + * - The python built-in exceptions were used as inspiration. + * - Exceptions inherit from std::exception to provide what(). + * - Exceptions inherit from uhd::exception to provide code(). + * + * The code() provides an error code which allows the application + * the option of printing a cryptic error message from the 1990s. + */ +namespace uhd{ + + struct UHD_API exception : std::runtime_error{ + exception(const std::string &what); + virtual unsigned code(void) const = 0; + }; + + struct UHD_API assertion_error : exception{ + assertion_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API lookup_error : exception{ + lookup_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API index_error : lookup_error{ + index_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API key_error : lookup_error{ + key_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API type_error : exception{ + type_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API value_error : exception{ + value_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API runtime_error : exception{ + runtime_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API not_implemented_error : runtime_error{ + not_implemented_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API environment_error : exception{ + environment_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API io_error : environment_error{ + io_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API os_error : environment_error{ + os_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API system_error : exception{ + system_error(const std::string &what); + virtual unsigned code(void) const; + }; + + /*! + * Create a formated string with throw-site information. + * Fills in the function name, file name, and line number. + * \param what the std::exeption message + * \return the formatted exception message + */ + #define UHD_THROW_SITE_INFO(what) std::string( \ + std::string(what) + "\n" + \ + " in " + std::string(BOOST_CURRENT_FUNCTION) + "\n" + \ + " at " + std::string(__FILE__) + ":" + BOOST_STRINGIZE(__LINE__) + "\n" \ + ) + + /*! + * Throws an invalid code path exception with throw-site information. + * Use this macro in places that code execution is not supposed to go. + */ + #define UHD_THROW_INVALID_CODE_PATH() \ + throw uhd::system_error(UHD_THROW_SITE_INFO("invalid code path")) + + /*! + * Assert the result of the code evaluation. + * If the code evaluates to false, throw an assertion error. + * \param code the code that resolved to a boolean + */ + #define UHD_ASSERT_THROW(code) if (not (code)) \ + throw uhd::assertion_error(UHD_THROW_SITE_INFO(#code)); \ + else void(0) + +} //namespace uhd + +#endif /* INCLUDED_UHD_UTILS_EXCEPTION_HPP */ diff --git a/host/include/uhd/types/device_addr.hpp b/host/include/uhd/types/device_addr.hpp index eb3394230..2c0841146 100644 --- a/host/include/uhd/types/device_addr.hpp +++ b/host/include/uhd/types/device_addr.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -84,9 +84,15 @@ namespace uhd{ } }; - //handy typedef for a vector of device addresses + //! A typedef for a vector of device addresses typedef std::vector<device_addr_t> device_addrs_t; + //! Separate an indexed device address into a vector of device addresses + UHD_API device_addrs_t separate_device_addr(const device_addr_t &dev_addr); + + //! Combine a vector of device addresses into an indexed device address + UHD_API device_addr_t combine_device_addrs(const device_addrs_t &dev_addrs); + } //namespace uhd #endif /* INCLUDED_UHD_TYPES_DEVICE_ADDR_HPP */ diff --git a/host/include/uhd/types/dict.ipp b/host/include/uhd/types/dict.ipp index 0c014474e..5e9cf97ad 100644 --- a/host/include/uhd/types/dict.ipp +++ b/host/include/uhd/types/dict.ipp @@ -18,18 +18,18 @@ #ifndef INCLUDED_UHD_TYPES_DICT_IPP #define INCLUDED_UHD_TYPES_DICT_IPP +#include <uhd/exception.hpp> #include <boost/foreach.hpp> #include <boost/format.hpp> #include <boost/lexical_cast.hpp> -#include <stdexcept> #include <typeinfo> namespace uhd{ namespace /*anon*/{ template<typename Key, typename Val> - struct key_not_found: std::out_of_range{ - key_not_found(const Key &key): std::out_of_range( + struct key_not_found: uhd::key_error{ + key_not_found(const Key &key): uhd::key_error( str(boost::format( "key \"%s\" not found in dict(%s, %s)" ) % boost::lexical_cast<std::string>(key) diff --git a/host/include/uhd/types/serial.hpp b/host/include/uhd/types/serial.hpp index c134725f5..5c6de162b 100644 --- a/host/include/uhd/types/serial.hpp +++ b/host/include/uhd/types/serial.hpp @@ -116,6 +116,59 @@ namespace uhd{ */ spi_config_t(edge_t edge = EDGE_RISE); }; + + /*! + * The SPI interface class. + * Provides routines to transact SPI and do other useful things which haven't been defined yet. + */ + class UHD_API spi_iface{ + public: + /*! + * Perform a spi transaction. + * \param which_slave the slave device number + * \param config spi config args + * \param data the bits to write + * \param num_bits how many bits in data + * \param readback true to readback a value + * \return spi data if readback set + */ + virtual boost::uint32_t transact_spi( + int which_slave, + const spi_config_t &config, + boost::uint32_t data, + size_t num_bits, + bool readback + ) = 0; + + /*! + * Read from the SPI bus. + * \param which_slave the slave device number + * \param config spi config args + * \param data the bits to write out (be sure to set write bit) + * \param num_bits how many bits in data + * \return spi data + */ + virtual boost::uint32_t read_spi( + int which_slave, + const spi_config_t &config, + boost::uint16_t data, + size_t num_bits + ); + + /*! + * Write to the SPI bus. + * \param which_slave the slave device number + * \param config spi config args + * \param data the bits to write + * \param num_bits how many bits in data + */ + virtual void write_spi( + int which_slave, + const spi_config_t &config, + boost::uint16_t data, + size_t num_bits + ); + }; } //namespace uhd diff --git a/host/include/uhd/usrp/CMakeLists.txt b/host/include/uhd/usrp/CMakeLists.txt index f60b35e59..59a1302af 100644 --- a/host/include/uhd/usrp/CMakeLists.txt +++ b/host/include/uhd/usrp/CMakeLists.txt @@ -43,6 +43,7 @@ INSTALL(FILES ### interfaces ### single_usrp.hpp multi_usrp.hpp + mboard_iface.hpp DESTINATION ${INCLUDE_DIR}/uhd/usrp ) diff --git a/host/include/uhd/usrp/dsp_props.hpp b/host/include/uhd/usrp/dsp_props.hpp index 3e1690317..e68e11deb 100644 --- a/host/include/uhd/usrp/dsp_props.hpp +++ b/host/include/uhd/usrp/dsp_props.hpp @@ -39,8 +39,8 @@ namespace uhd{ namespace usrp{ enum dsp_prop_t{ DSP_PROP_NAME, //ro, std::string DSP_PROP_OTHERS, //ro, prop_names_t + DSP_PROP_STREAM_CMD, //wo, stream_cmd_t DSP_PROP_FREQ_SHIFT, //rw, double Hz - DSP_PROP_FREQ_SHIFT_NAMES, //ro, prop_names_t DSP_PROP_CODEC_RATE, //ro, double Sps DSP_PROP_HOST_RATE //rw, double Sps }; diff --git a/host/include/uhd/usrp/mboard_iface.hpp b/host/include/uhd/usrp/mboard_iface.hpp new file mode 100644 index 000000000..784fbc7c5 --- /dev/null +++ b/host/include/uhd/usrp/mboard_iface.hpp @@ -0,0 +1,85 @@ +// +// Copyright 2010-2011 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + +#ifndef INCLUDED_UHD_USRP_MBOARD_IFACE_HPP +#define INCLUDED_UHD_USRP_MBOARD_IFACE_HPP + +#include <uhd/types/serial.hpp> +#include <uhd/usrp/mboard_eeprom.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/utility.hpp> +#include <boost/cstdint.hpp> +#include <utility> +#include <string> + +namespace uhd{ namespace usrp{ + +/*! + * The mboard interface class: + * Provides a set of functions to implementation layer. + * Including spi, peek, poke, control... + */ +class mboard_iface : public uhd::i2c_iface, public uhd::spi_iface { +public: + typedef boost::shared_ptr<mboard_iface> sptr; + /*! + * Write a register (32 bits) + * \param addr the address + * \param data the 32bit data + */ + virtual void poke32(boost::uint32_t addr, boost::uint32_t data) = 0; + + /*! + * Read a register (32 bits) + * \param addr the address + * \return the 32bit data + */ + virtual boost::uint32_t peek32(boost::uint32_t addr) = 0; + + /*! + * Write a register (16 bits) + * \param addr the address + * \param data the 16bit data + */ + virtual void poke16(boost::uint32_t addr, boost::uint16_t data) = 0; + + /*! + * Read a register (16 bits) + * \param addr the address + * \return the 16bit data + */ + virtual boost::uint16_t peek16(boost::uint32_t addr) = 0; + + /*! + * Write to a serial port. + * \param dev which UART to write to + * \param buf the data to write + */ + virtual void write_uart(boost::uint8_t dev, const std::string &buf) = 0; + + /*! + * Read from a serial port. + * \param dev which UART to read from + * \return the data read from the serial port + */ + virtual std::string read_uart(boost::uint8_t dev) = 0; + +}; + +}} + +#endif //INCLUDED_UHD_USRP_DBOARD_IFACE_HPP diff --git a/host/include/uhd/usrp/mboard_props.hpp b/host/include/uhd/usrp/mboard_props.hpp index 8855e2b75..a2580954e 100644 --- a/host/include/uhd/usrp/mboard_props.hpp +++ b/host/include/uhd/usrp/mboard_props.hpp @@ -47,8 +47,8 @@ namespace uhd{ namespace usrp{ MBOARD_PROP_CLOCK_CONFIG, //rw, clock_config_t MBOARD_PROP_TIME_NOW, //rw, time_spec_t MBOARD_PROP_TIME_PPS, //wo, time_spec_t - MBOARD_PROP_STREAM_CMD, //wo, stream_cmd_t - MBOARD_PROP_EEPROM_MAP //wr, mboard_eeprom_t + MBOARD_PROP_EEPROM_MAP, //wr, mboard_eeprom_t + MBOARD_PROP_IFACE, //ro, mboard_iface::sptr }; }} //namespace diff --git a/host/include/uhd/usrp/multi_usrp.hpp b/host/include/uhd/usrp/multi_usrp.hpp index 3c8dd5fac..b161d1278 100644 --- a/host/include/uhd/usrp/multi_usrp.hpp +++ b/host/include/uhd/usrp/multi_usrp.hpp @@ -28,6 +28,7 @@ #include <uhd/types/sensors.hpp> #include <uhd/usrp/subdev_spec.hpp> #include <uhd/usrp/dboard_iface.hpp> +#include <uhd/usrp/mboard_iface.hpp> #include <boost/shared_ptr.hpp> #include <boost/utility.hpp> #include <vector> @@ -87,6 +88,9 @@ public: //! A wildcard motherboard index static const size_t ALL_MBOARDS = size_t(~0); + //! A wildcard channel index + static const size_t ALL_CHANS = size_t(~0); + //! A wildcard gain element name static const std::string ALL_GAINS; @@ -215,8 +219,9 @@ public: * to ensure that the packets can be aligned by their time specs. * * \param stream_cmd the stream command to issue + * \param chan the channel index 0 to N-1 */ - virtual void issue_stream_cmd(const stream_cmd_t &stream_cmd) = 0; + virtual void issue_stream_cmd(const stream_cmd_t &stream_cmd, size_t chan = ALL_CHANS) = 0; /*! * Set the clock configuration for the usrp device. @@ -246,6 +251,12 @@ public: * \return a vector of sensor names */ virtual std::vector<std::string> get_mboard_sensor_names(size_t mboard = 0) = 0; + + /*! + * Get a handle to the mboard_iface object which controls peripheral access. + * \return a mboard_iface::sptr object + */ + virtual mboard_iface::sptr get_mboard_iface(size_t mboard) = 0; /******************************************************************* * RX methods @@ -282,16 +293,18 @@ public: virtual std::string get_rx_subdev_name(size_t chan = 0) = 0; /*! - * Set the RX sample rate across all channels. + * Set the RX sample rate. * \param rate the rate in Sps + * \param chan the channel index 0 to N-1 */ - virtual void set_rx_rate(double rate) = 0; + virtual void set_rx_rate(double rate, size_t chan = ALL_CHANS) = 0; /*! - * Gets the RX sample rate for all channels. + * Gets the RX sample rate. + * \param chan the channel index 0 to N-1 * \return the rate in Sps */ - virtual double get_rx_rate(void) = 0; + virtual double get_rx_rate(size_t chan = 0) = 0; /*! * Set the RX center frequency. @@ -480,16 +493,18 @@ public: virtual std::string get_tx_subdev_name(size_t chan = 0) = 0; /*! - * Set the TX sample rate across all channels. + * Set the TX sample rate. * \param rate the rate in Sps + * \param chan the channel index 0 to N-1 */ - virtual void set_tx_rate(double rate) = 0; + virtual void set_tx_rate(double rate, size_t chan = ALL_CHANS) = 0; /*! - * Gets the TX sample rate for all channels. + * Gets the TX sample rate. + * \param chan the channel index 0 to N-1 * \return the rate in Sps */ - virtual double get_tx_rate(void) = 0; + virtual double get_tx_rate(size_t chan = 0) = 0; /*! * Set the TX center frequency. diff --git a/host/include/uhd/usrp/tune_helper.hpp b/host/include/uhd/usrp/tune_helper.hpp index db12241c1..e97ab0298 100644 --- a/host/include/uhd/usrp/tune_helper.hpp +++ b/host/include/uhd/usrp/tune_helper.hpp @@ -32,24 +32,21 @@ namespace uhd{ namespace usrp{ * The ddc cordic is setup to bring the IF down to baseband. * \param subdev the dboard subdevice object with properties * \param ddc the mboard dsp object with properties - * \param chan the channel of the dsp to tune * \param tune_request tune request instructions * \return a tune result struct */ UHD_API tune_result_t tune_rx_subdev_and_dsp( - wax::obj subdev, wax::obj ddc, size_t chan, - const tune_request_t &tune_request + wax::obj subdev, wax::obj ddc, const tune_request_t &tune_request ); /*! * Calculate the overall frequency from the combination of dboard IF and DDC shift. * \param subdev the dboard subdevice object with properties * \param ddc the mboard dsp object with properties - * \param chan the channel of the dsp to tune * \return the overall tune frequency of the system in Hz */ UHD_API double derive_freq_from_rx_subdev_and_dsp( - wax::obj subdev, wax::obj ddc, size_t chan + wax::obj subdev, wax::obj ddc ); /*! @@ -59,24 +56,21 @@ namespace uhd{ namespace usrp{ * The duc cordic is setup to bring the baseband up to IF. * \param subdev the dboard subdevice object with properties * \param duc the mboard dsp object with properties - * \param chan the channel of the dsp to tune * \param tune_request tune request instructions * \return a tune result struct */ UHD_API tune_result_t tune_tx_subdev_and_dsp( - wax::obj subdev, wax::obj duc, size_t chan, - const tune_request_t &tune_request + wax::obj subdev, wax::obj duc, const tune_request_t &tune_request ); /*! * Calculate the overall frequency from the combination of dboard IF and DUC shift. * \param subdev the dboard subdevice object with properties * \param duc the mboard dsp object with properties - * \param chan the channel of the dsp to tune * \return the overall tune frequency of the system in Hz */ UHD_API double derive_freq_from_tx_subdev_and_dsp( - wax::obj subdev, wax::obj duc, size_t chan + wax::obj subdev, wax::obj duc ); }} diff --git a/host/include/uhd/utils/CMakeLists.txt b/host/include/uhd/utils/CMakeLists.txt index b39b6083c..4ed7ca460 100644 --- a/host/include/uhd/utils/CMakeLists.txt +++ b/host/include/uhd/utils/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 Ettus Research LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,11 +17,10 @@ INSTALL(FILES algorithm.hpp - assert.hpp - assert.ipp + assert_has.hpp + assert_has.ipp byteswap.hpp byteswap.ipp - exception.hpp gain_group.hpp images.hpp pimpl.hpp diff --git a/host/include/uhd/utils/algorithm.hpp b/host/include/uhd/utils/algorithm.hpp index d3a07db96..5598d862b 100644 --- a/host/include/uhd/utils/algorithm.hpp +++ b/host/include/uhd/utils/algorithm.hpp @@ -21,24 +21,12 @@ #include <algorithm> #include <boost/range/begin.hpp> #include <boost/range/end.hpp> -#include <boost/range/size.hpp> -/*! \file algorithm.hpp +/*! * Useful templated functions and classes that I like to pretend are part of stl. * Many of the range wrapper functions come with recent versions of boost (1.43). */ -namespace std{ - - /*! - * A wrapper around std::sort that takes a range instead of an iterator. - * - * The elements are sorted into ascending order using the less-than operator. - * - * \param range the range of elements to be sorted - */ - template<typename Range> inline void sort(Range &range){ - return std::sort(boost::begin(range), boost::end(range)); - } +namespace uhd{ /*! * A wrapper around std::sort that takes a range instead of an iterator. @@ -51,18 +39,7 @@ namespace std{ * \return a new range with the elements sorted */ template<typename Range> inline Range sorted(const Range &range){ - Range srange(range); std::sort(srange); return srange; - } - - /*! - * A wrapper around std::reverse that takes a range instead of an iterator. - * - * The elements are reversed into descending order using the less-than operator. - * - * \param range the range of elements to be reversed - */ - template<typename Range> inline void reverse(Range &range){ - return std::reverse(boost::begin(range), boost::end(range)); + Range r(range); std::sort(boost::begin(r), boost::end(r)); return r; } /*! @@ -76,7 +53,7 @@ namespace std{ * \return a new range with the elements reversed */ template<typename Range> inline Range reversed(const Range &range){ - Range srange(range); std::reverse(srange); return srange; + Range r(range); std::reverse(boost::begin(r), boost::end(r)); return r; } /*! @@ -94,35 +71,6 @@ namespace std{ } /*! - * Count the number of appearances of a value in a range. - * - * Uses std::count to count the appearances in the range. - * - * \param range the elements to iterate through - * \param value the value to count in the range - * \return the number of appearances of the value - */ - template<typename Range, typename T> inline - size_t count(const Range &range, const T &value){ - return std::count(boost::begin(range), boost::end(range), value); - } - - /*! - * Are the ranges equal (are their elements equivalent)? - * - * Uses std::equal to search the iterable for an element. - * - * \param range1 the first range of elements - * \param range2 the second range of elements - * \return true when the elements are equivalent - */ - template<typename Range> inline - bool equal(const Range &range1, const Range &range2){ - return (boost::size(range1) == boost::size(range2)) and - std::equal(boost::begin(range1), boost::end(range1), boost::begin(range2)); - } - - /*! * A templated clip implementation. * \param val the value to clip between an upper and lower limit * \param bound1 the upper or lower bound @@ -137,6 +85,6 @@ namespace std{ return val; } -}//namespace std +} //namespace uhd #endif /* INCLUDED_UHD_UTILS_ALGORITHM_HPP */ diff --git a/host/include/uhd/utils/assert.hpp b/host/include/uhd/utils/assert_has.hpp index 7f7b71cfb..eae7652ad 100644 --- a/host/include/uhd/utils/assert.hpp +++ b/host/include/uhd/utils/assert_has.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -15,26 +15,14 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // -#ifndef INCLUDED_UHD_UTILS_ASSERT_HPP -#define INCLUDED_UHD_UTILS_ASSERT_HPP +#ifndef INCLUDED_UHD_UTILS_ASSERT_HAS_HPP +#define INCLUDED_UHD_UTILS_ASSERT_HAS_HPP #include <uhd/config.hpp> -#include <uhd/utils/exception.hpp> -#include <stdexcept> #include <string> namespace uhd{ - //! The exception to throw when assertions fail - struct UHD_API assert_error : std::runtime_error{ - assert_error(const std::string &what); - }; - - //! Throw an assert error with throw-site information - #define UHD_ASSERT_THROW(_x) if (not (_x)) throw uhd::assert_error( \ - UHD_THROW_SITE_INFO("assertion failed: " + std::string(#_x)) \ - ); else void(0) - /*! * Check that an element is found in a container. * If not, throw a meaningful assertion error. @@ -54,6 +42,6 @@ namespace uhd{ }//namespace uhd -#include <uhd/utils/assert.ipp> +#include <uhd/utils/assert_has.ipp> -#endif /* INCLUDED_UHD_UTILS_ASSERT_HPP */ +#endif /* INCLUDED_UHD_UTILS_ASSERT_HAS_HPP */ diff --git a/host/include/uhd/utils/assert.ipp b/host/include/uhd/utils/assert_has.ipp index 6a8b3e417..7b3c88cb7 100644 --- a/host/include/uhd/utils/assert.ipp +++ b/host/include/uhd/utils/assert_has.ipp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -15,10 +15,11 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // -#ifndef INCLUDED_UHD_UTILS_ASSERT_IPP -#define INCLUDED_UHD_UTILS_ASSERT_IPP +#ifndef INCLUDED_UHD_UTILS_ASSERT_HAS_IPP +#define INCLUDED_UHD_UTILS_ASSERT_HAS_IPP #include <uhd/utils/algorithm.hpp> +#include <uhd/exception.hpp> #include <boost/format.hpp> #include <boost/foreach.hpp> #include <boost/lexical_cast.hpp> @@ -30,14 +31,14 @@ namespace uhd{ const T &value, const std::string &what ){ - if (std::has(range, value)) return; + if (uhd::has(range, value)) return; std::string possible_values = ""; size_t i = 0; BOOST_FOREACH(const T &v, range){ if (i++ > 0) possible_values += ", "; possible_values += boost::lexical_cast<std::string>(v); } - throw uhd::assert_error(str(boost::format( + throw uhd::assertion_error(str(boost::format( "assertion failed:\n" " %s is not a valid %s.\n" " possible values are: [%s].\n" @@ -49,4 +50,4 @@ namespace uhd{ }//namespace uhd -#endif /* INCLUDED_UHD_UTILS_ASSERT_IPP */ +#endif /* INCLUDED_UHD_UTILS_ASSERT_HAS_IPP */ diff --git a/host/include/uhd/utils/exception.hpp b/host/include/uhd/utils/exception.hpp deleted file mode 100644 index e74c19b9c..000000000 --- a/host/include/uhd/utils/exception.hpp +++ /dev/null @@ -1,45 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see <http://www.gnu.org/licenses/>. -// - -#ifndef INCLUDED_UHD_UTILS_EXCEPTION_HPP -#define INCLUDED_UHD_UTILS_EXCEPTION_HPP - -#include <uhd/config.hpp> -#include <boost/current_function.hpp> -#include <stdexcept> -#include <string> - -/*! - * Create a formated string with throw-site information. - * Fills in the function name, file name, and line number. - * \param what the std::exeption message - * \return the formatted exception message - */ -#define UHD_THROW_SITE_INFO(what) std::string( \ - std::string(what) + "\n" + \ - " in " + std::string(BOOST_CURRENT_FUNCTION) + "\n" + \ - " at " + std::string(__FILE__) + ":" + BOOST_STRINGIZE(__LINE__) + "\n" \ -) - -/*! - * Throws an invalid code path exception with throw-site information. - * Use this macro in places that code execution is not supposed to go. - */ -#define UHD_THROW_INVALID_CODE_PATH() \ - throw std::runtime_error(UHD_THROW_SITE_INFO("invalid code path")) - -#endif /* INCLUDED_UHD_UTILS_EXCEPTION_HPP */ diff --git a/host/include/uhd/utils/props.hpp b/host/include/uhd/utils/props.hpp index fbca03019..81737423a 100644 --- a/host/include/uhd/utils/props.hpp +++ b/host/include/uhd/utils/props.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -20,8 +20,7 @@ #include <uhd/config.hpp> #include <uhd/wax.hpp> -#include <uhd/utils/exception.hpp> -#include <stdexcept> +#include <uhd/exception.hpp> #include <vector> #include <string> @@ -68,14 +67,14 @@ namespace uhd{ * Throw-site information will be included with this error. */ #define UHD_THROW_PROP_GET_ERROR() \ - throw std::runtime_error(UHD_THROW_SITE_INFO("cannot get this property")) + throw uhd::key_error(UHD_THROW_SITE_INFO("cannot get this property")) /*! * Throw when setting a not-implemented or read-only property. * Throw-site information will be included with this error. */ #define UHD_THROW_PROP_SET_ERROR() \ - throw std::runtime_error(UHD_THROW_SITE_INFO("cannot set this property")) + throw uhd::key_error(UHD_THROW_SITE_INFO("cannot set this property")) } //namespace uhd diff --git a/host/include/uhd/wax.hpp b/host/include/uhd/wax.hpp index 14e6734a5..6fd2b8652 100644 --- a/host/include/uhd/wax.hpp +++ b/host/include/uhd/wax.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -19,7 +19,10 @@ #define INCLUDED_WAX_HPP #include <uhd/config.hpp> +#include <uhd/exception.hpp> #include <boost/any.hpp> +#include <typeinfo> +#include <string> /*! * WAX - it's a metaphor! @@ -47,12 +50,6 @@ namespace wax{ /*! - * The wax::bad cast will be thrown when - * cast is called with the wrong typeid. - */ - typedef boost::bad_any_cast bad_cast; - - /*! * WAX object base class: * * A wax obj has two major purposes: @@ -140,7 +137,12 @@ namespace wax{ * \throw wax::bad_cast when the cast fails */ template<class T> T as(void) const{ - return boost::any_cast<T>(resolve()); + try{ + return boost::any_cast<T>(resolve()); + } + catch(const boost::bad_any_cast &e){ + throw uhd::type_error(std::string("") + "Cannot wax cast " + type().name() + " to " + typeid(T).name() + " " + e.what()); + } } private: |