diff options
Diffstat (limited to 'host/include')
-rw-r--r-- | host/include/uhd/config.hpp | 22 | ||||
-rw-r--r-- | host/include/uhd/transport/udp_zero_copy.hpp | 24 | ||||
-rw-r--r-- | host/include/uhd/types/device_addr.hpp | 10 | ||||
-rw-r--r-- | host/include/uhd/types/dict.hpp | 4 | ||||
-rw-r--r-- | host/include/uhd/usrp/dboard_base.hpp | 24 | ||||
-rw-r--r-- | host/include/uhd/usrp/dboard_id.hpp | 64 | ||||
-rw-r--r-- | host/include/uhd/usrp/dboard_manager.hpp | 2 | ||||
-rw-r--r-- | host/include/uhd/utils/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/include/uhd/utils/algorithm.hpp | 30 | ||||
-rw-r--r-- | host/include/uhd/utils/assert.hpp | 39 | ||||
-rw-r--r-- | host/include/uhd/utils/exception.hpp | 38 | ||||
-rw-r--r-- | host/include/uhd/utils/props.hpp | 13 | ||||
-rw-r--r-- | host/include/uhd/utils/safe_main.hpp | 3 |
13 files changed, 163 insertions, 111 deletions
diff --git a/host/include/uhd/config.hpp b/host/include/uhd/config.hpp index 941219ac7..32eafc89b 100644 --- a/host/include/uhd/config.hpp +++ b/host/include/uhd/config.hpp @@ -39,27 +39,23 @@ //define logical operators #ifdef BOOST_MSVC - #define not ! - #define and && - #define or || + #include <ciso646> #endif // http://gcc.gnu.org/wiki/Visibility // Generic helper definitions for shared library support -#if defined _WIN32 || defined __CYGWIN__ +#if defined(BOOST_HAS_DECLSPEC) #define UHD_HELPER_DLL_IMPORT __declspec(dllimport) #define UHD_HELPER_DLL_EXPORT __declspec(dllexport) #define UHD_HELPER_DLL_LOCAL +#elif defined(__GNUG__) && __GNUG__ >= 4 + #define UHD_HELPER_DLL_IMPORT __attribute__ ((visibility("default"))) + #define UHD_HELPER_DLL_EXPORT __attribute__ ((visibility("default"))) + #define UHD_HELPER_DLL_LOCAL __attribute__ ((visibility("hidden"))) #else - #if __GNUC__ >= 4 - #define UHD_HELPER_DLL_IMPORT __attribute__ ((visibility("default"))) - #define UHD_HELPER_DLL_EXPORT __attribute__ ((visibility("default"))) - #define UHD_HELPER_DLL_LOCAL __attribute__ ((visibility("hidden"))) - #else - #define UHD_HELPER_DLL_IMPORT - #define UHD_HELPER_DLL_EXPORT - #define UHD_HELPER_DLL_LOCAL - #endif + #define UHD_HELPER_DLL_IMPORT + #define UHD_HELPER_DLL_EXPORT + #define UHD_HELPER_DLL_LOCAL #endif // Now we use the generic helper definitions above to define UHD_API and UHD_LOCAL. diff --git a/host/include/uhd/transport/udp_zero_copy.hpp b/host/include/uhd/transport/udp_zero_copy.hpp index c74e6d7b7..525606a9f 100644 --- a/host/include/uhd/transport/udp_zero_copy.hpp +++ b/host/include/uhd/transport/udp_zero_copy.hpp @@ -50,23 +50,15 @@ public: * * \param addr a string representing the destination address * \param port a string representing the destination port + * \param recv_buff_size size in bytes for the recv buffer, 0 for automatic + * \param send_buff_size size in bytes for the send buffer, 0 for automatic */ - static sptr make(const std::string &addr, const std::string &port); - - /*! - * Resize the the rx buffer size on the socket. - * \param num_bytes the new size for the socket buffer - * \return the actual number of bytes allowed by the OS - */ - virtual size_t resize_recv_buff_size(size_t num_bytes) = 0; - - /*! - * Resize the the tx buffer size on the socket. - * \param num_bytes the new size for the socket buffer - * \return the actual number of bytes allowed by the OS - */ - virtual size_t resize_send_buff_size(size_t num_bytes) = 0; - + static sptr make( + const std::string &addr, + const std::string &port, + size_t recv_buff_size = 0, + size_t send_buff_size = 0 + ); }; }} //namespace diff --git a/host/include/uhd/types/device_addr.hpp b/host/include/uhd/types/device_addr.hpp index e8da2a1ab..e359d9467 100644 --- a/host/include/uhd/types/device_addr.hpp +++ b/host/include/uhd/types/device_addr.hpp @@ -40,7 +40,7 @@ namespace uhd{ * An arguments string, is a way to represent a device address * using a single string with delimiter characters. * - Ex: addr=192.168.10.2 - * - Ex: addr=192.168.10.2, rx_buff_size=1e6 + * - Ex: addr=192.168.10.2, recv_buff_size=1e6 */ class UHD_API device_addr_t : public dict<std::string, std::string>{ public: @@ -51,17 +51,17 @@ namespace uhd{ device_addr_t(const std::string &args = ""); /*! - * Convert a device address into a printable string. - * \return string good for use with std::cout << + * Convert a device address into a pretty print string. + * \return a printable string representing the device address */ - std::string to_string(void) const; + std::string to_pp_string(void) const; /*! * Convert the device address into an args string. * The args string contains delimiter symbols. * \return a string with delimiter markup */ - std::string to_args_str(void) const; + std::string to_string(void) const; }; //handy typedef for a vector of device addresses diff --git a/host/include/uhd/types/dict.hpp b/host/include/uhd/types/dict.hpp index c8fbc5a9f..b5fb11120 100644 --- a/host/include/uhd/types/dict.hpp +++ b/host/include/uhd/types/dict.hpp @@ -29,7 +29,7 @@ namespace uhd{ /*! * A templated dictionary class with a python-like interface. */ - template <class Key, class Val> class dict{ + template <typename Key, typename Val> class dict{ public: typedef std::pair<Key, Val> pair_t; @@ -130,7 +130,7 @@ namespace uhd{ BOOST_FOREACH(pair_t &p, _map){ if (p.first == key) return p.second; } - _map.push_back(pair_t(key, Val())); + _map.push_back(std::make_pair(key, Val())); return _map.back().second; } diff --git a/host/include/uhd/usrp/dboard_base.hpp b/host/include/uhd/usrp/dboard_base.hpp index 2025760ee..28bf2ae66 100644 --- a/host/include/uhd/usrp/dboard_base.hpp +++ b/host/include/uhd/usrp/dboard_base.hpp @@ -22,7 +22,6 @@ #include <uhd/wax.hpp> #include <boost/utility.hpp> #include <boost/shared_ptr.hpp> -#include <boost/tuple/tuple.hpp> #include <uhd/usrp/dboard_id.hpp> #include <uhd/usrp/dboard_iface.hpp> @@ -35,13 +34,15 @@ namespace uhd{ namespace usrp{ class UHD_API dboard_base : boost::noncopyable{ public: typedef boost::shared_ptr<dboard_base> sptr; - //the constructor args consist of a subdev name, interface, and ids - //derived classes should pass the args into the dboard_base class ctor - //but should not have to deal with the internals of the args - typedef boost::tuple<std::string, dboard_iface::sptr, dboard_id_t, dboard_id_t> ctor_args_t; + /*! + * An opaque type for the dboard constructor args. + * Derived classes should pass the args into the base class, + * but should not deal with the internals of the args. + */ + struct ctor_args_impl; typedef ctor_args_impl* ctor_args_t; //structors - dboard_base(ctor_args_t const&); + dboard_base(ctor_args_t); virtual ~dboard_base(void); //interface @@ -57,9 +58,8 @@ protected: dboard_id_t get_tx_id(void); private: - std::string _subdev_name; - dboard_iface::sptr _dboard_iface; - dboard_id_t _rx_id, _tx_id; + struct dboard_base_impl; + dboard_base_impl *_impl; }; /*! @@ -71,7 +71,7 @@ public: /*! * Create a new xcvr dboard object, override in subclasses. */ - xcvr_dboard_base(ctor_args_t const&); + xcvr_dboard_base(ctor_args_t); virtual ~xcvr_dboard_base(void); }; @@ -85,7 +85,7 @@ public: /*! * Create a new rx dboard object, override in subclasses. */ - rx_dboard_base(ctor_args_t const&); + rx_dboard_base(ctor_args_t); virtual ~rx_dboard_base(void); @@ -103,7 +103,7 @@ public: /*! * Create a new rx dboard object, override in subclasses. */ - tx_dboard_base(ctor_args_t const&); + tx_dboard_base(ctor_args_t); virtual ~tx_dboard_base(void); diff --git a/host/include/uhd/usrp/dboard_id.hpp b/host/include/uhd/usrp/dboard_id.hpp index afacaf8ff..8b6eaf6bd 100644 --- a/host/include/uhd/usrp/dboard_id.hpp +++ b/host/include/uhd/usrp/dboard_id.hpp @@ -20,16 +20,70 @@ #include <uhd/config.hpp> #include <boost/cstdint.hpp> +#include <boost/operators.hpp> #include <string> namespace uhd{ namespace usrp{ -typedef boost::uint16_t dboard_id_t; + class UHD_API dboard_id_t : boost::equality_comparable1<dboard_id_t>{ + public: + /*! + * Create a dboard id from an integer. + * \param id the integer representation + */ + dboard_id_t(boost::uint16_t id = 0xffff); -namespace dboard_id{ - static const dboard_id_t NONE = 0xffff; - UHD_API std::string to_string(const dboard_id_t &id); -} + /*! + * Obtain a dboard id that represents no dboard. + * \return the dboard id with the 0xffff id. + */ + static dboard_id_t none(void); + + /*! + * Create a new dboard id from an integer representation. + * \param uint16 an unsigned 16 bit integer + * \return a new dboard id containing the integer + */ + static dboard_id_t from_uint16(boost::uint16_t uint16); + + /*! + * Get the dboard id represented as an integer. + * \return an unsigned 16 bit integer representation + */ + boost::uint16_t to_uint16(void) const; + + /*! + * Create a new dboard id from a string representation. + * If the string has a 0x prefix, it will be parsed as hex. + * \param string a numeric string, possibly hex + * \return a new dboard id containing the integer + */ + static dboard_id_t from_string(const std::string &string); + + /*! + * Get the dboard id represented as an integer. + * \return a hex string representation with 0x prefix + */ + std::string to_string(void) const; + + /*! + * Get the pretty print representation of this dboard id. + * \return a string with the dboard name and id number + */ + std::string to_pp_string(void) const; + + private: + boost::uint16_t _id; //internal representation + }; + + /*! + * Comparator operator overloaded for dboard ids. + * The boost::equality_comparable provides the !=. + * \param lhs the dboard id to the left of the operator + * \param rhs the dboard id to the right of the operator + * \return true when the dboard ids are equal + */ + UHD_API bool operator==(const dboard_id_t &lhs, const dboard_id_t &rhs); }} //namespace diff --git a/host/include/uhd/usrp/dboard_manager.hpp b/host/include/uhd/usrp/dboard_manager.hpp index 007d85bb4..b84fee4e7 100644 --- a/host/include/uhd/usrp/dboard_manager.hpp +++ b/host/include/uhd/usrp/dboard_manager.hpp @@ -37,7 +37,7 @@ public: typedef boost::shared_ptr<dboard_manager> sptr; //dboard constructor (each dboard should have a ::make with this signature) - typedef dboard_base::sptr(*dboard_ctor_t)(dboard_base::ctor_args_t const&); + typedef dboard_base::sptr(*dboard_ctor_t)(dboard_base::ctor_args_t); /*! * Register a dboard into the system. diff --git a/host/include/uhd/utils/CMakeLists.txt b/host/include/uhd/utils/CMakeLists.txt index 2831ab0b0..f588c6310 100644 --- a/host/include/uhd/utils/CMakeLists.txt +++ b/host/include/uhd/utils/CMakeLists.txt @@ -18,6 +18,7 @@ INSTALL(FILES algorithm.hpp assert.hpp + exception.hpp gain_handler.hpp props.hpp safe_main.hpp diff --git a/host/include/uhd/utils/algorithm.hpp b/host/include/uhd/utils/algorithm.hpp index 8fe9cde82..72b655745 100644 --- a/host/include/uhd/utils/algorithm.hpp +++ b/host/include/uhd/utils/algorithm.hpp @@ -19,43 +19,25 @@ #define INCLUDED_UHD_UTILS_ALGORITHM_HPP #include <algorithm> +#include <boost/range/functions.hpp> /*! * Useful templated functions and classes that I like to pretend are part of stl */ namespace std{ - template<class T, class InputIterator, class Function> - T reduce(InputIterator first, InputIterator last, Function fcn, T init = 0){ - T tmp = init; - for ( ; first != last; ++first ){ - tmp = fcn(tmp, *first); - } - return tmp; + template<typename Range, typename T> inline + bool has(const Range &range, const T &value){ + return boost::end(range) != std::find(boost::begin(range), boost::end(range), value); } - template<class T, class Iterable, class Function> - T reduce(Iterable iterable, Function fcn, T init = 0){ - return reduce(iterable.begin(), iterable.end(), fcn, init); - } - - template<class T, class InputIterator> - bool has(InputIterator first, InputIterator last, const T &elem){ - return last != std::find(first, last, elem); - } - - template<class T, class Iterable> - bool has(const Iterable &iterable, const T &elem){ - return has(iterable.begin(), iterable.end(), elem); - } - - template<class T> T signum(T n){ + template<typename T> inline T signum(T n){ if (n < 0) return -1; if (n > 0) return 1; return 0; } - template<class T> T clip(T val, T minVal, T maxVal){ + template<typename T> inline T clip(T val, T minVal, T maxVal){ return std::min(std::max(val, minVal), maxVal); } diff --git a/host/include/uhd/utils/assert.hpp b/host/include/uhd/utils/assert.hpp index 01beed757..2f0ed4ff1 100644 --- a/host/include/uhd/utils/assert.hpp +++ b/host/include/uhd/utils/assert.hpp @@ -19,26 +19,24 @@ #define INCLUDED_UHD_UTILS_ASSERT_HPP #include <uhd/config.hpp> +#include <uhd/utils/exception.hpp> #include <uhd/utils/algorithm.hpp> #include <boost/format.hpp> #include <boost/foreach.hpp> #include <boost/lexical_cast.hpp> -#include <boost/throw_exception.hpp> -#include <boost/exception/info.hpp> #include <stdexcept> #include <string> namespace uhd{ //! The exception to throw when assertions fail - struct UHD_API assert_error : virtual std::exception, virtual boost::exception{}; - - //! The assertion info, the code that failed - typedef boost::error_info<struct tag_assert_info, std::string> assert_info; + 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)) \ - BOOST_THROW_EXCEPTION(uhd::assert_error() << uhd::assert_info(#_x)) + throw uhd::assert_error(UHD_THROW_SITE_INFO("assertion failed: " + std::string(#_x))) /*! * Check that an element is found in a container. @@ -46,30 +44,31 @@ namespace uhd{ * The "what" in the error will show what is * being set and a list of known good values. * - * \param iterable a list of possible settings - * \param elem an element that may be in the list + * \param range a list of possible settings + * \param value an element that may be in the list * \param what a description of what is being set * \throw assertion_error when elem not in list */ - template<class T, class Iterable> void assert_has( - const Iterable &iterable, - const T &elem, + template<typename T, typename Range> void assert_has( + const Range &range, + const T &value, const std::string &what = "unknown" ){ - if (std::has(iterable, elem)) return; + if (std::has(range, value)) return; std::string possible_values = ""; size_t i = 0; - BOOST_FOREACH(const T &e, iterable){ + BOOST_FOREACH(const T &v, range){ if (i++ > 0) possible_values += ", "; - possible_values += boost::lexical_cast<std::string>(e); + possible_values += boost::lexical_cast<std::string>(v); } - boost::throw_exception(uhd::assert_error() << assert_info(str(boost::format( - "Error: %s is not a valid %s. " - "Possible values are: [%s]." + throw uhd::assert_error(str(boost::format( + "assertion failed:\n" + " %s is not a valid %s.\n" + " possible values are: [%s].\n" ) - % boost::lexical_cast<std::string>(elem) + % boost::lexical_cast<std::string>(value) % what % possible_values - ))); + )); } }//namespace uhd diff --git a/host/include/uhd/utils/exception.hpp b/host/include/uhd/utils/exception.hpp new file mode 100644 index 000000000..40e81fae0 --- /dev/null +++ b/host/include/uhd/utils/exception.hpp @@ -0,0 +1,38 @@ +// +// 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" \ +) + +#endif /* INCLUDED_UHD_UTILS_EXCEPTION_HPP */ diff --git a/host/include/uhd/utils/props.hpp b/host/include/uhd/utils/props.hpp index 516102a5f..f376d2612 100644 --- a/host/include/uhd/utils/props.hpp +++ b/host/include/uhd/utils/props.hpp @@ -20,9 +20,8 @@ #include <uhd/config.hpp> #include <uhd/wax.hpp> +#include <uhd/utils/exception.hpp> #include <boost/tuple/tuple.hpp> -#include <boost/throw_exception.hpp> -#include <boost/exception/info.hpp> #include <stdexcept> #include <vector> #include <string> @@ -59,25 +58,19 @@ namespace uhd{ const std::string &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 when getting a not-implemented or write-only property. * Throw-site information will be included with this error. */ #define UHD_THROW_PROP_GET_ERROR() \ - BOOST_THROW_EXCEPTION(uhd::prop_error() << uhd::prop_info("cannot get this property")) + throw std::runtime_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() \ - BOOST_THROW_EXCEPTION(uhd::prop_error() << uhd::prop_info("cannot set this property")) + throw std::runtime_error(UHD_THROW_SITE_INFO("cannot set this property")) } //namespace uhd diff --git a/host/include/uhd/utils/safe_main.hpp b/host/include/uhd/utils/safe_main.hpp index a4e4e06e8..b682aa540 100644 --- a/host/include/uhd/utils/safe_main.hpp +++ b/host/include/uhd/utils/safe_main.hpp @@ -19,7 +19,6 @@ #define INCLUDED_UHD_UTILS_SAFE_MAIN_HPP #include <uhd/config.hpp> -#include <boost/exception/diagnostic_information.hpp> #include <iostream> #include <stdexcept> @@ -34,8 +33,6 @@ 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(...) { \ |