diff options
author | Josh Blum <josh@joshknows.com> | 2010-03-15 12:15:33 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-03-15 12:15:33 -0700 |
commit | 7590f187d0414fd05e23828488166bc4bc88df26 (patch) | |
tree | 20eb597e4614276120814b727486c50e95f234fd /host/include | |
parent | 1ba6aafa678cdf61aef44de1d22ec72653e87ec7 (diff) | |
download | uhd-7590f187d0414fd05e23828488166bc4bc88df26.tar.gz uhd-7590f187d0414fd05e23828488166bc4bc88df26.tar.bz2 uhd-7590f187d0414fd05e23828488166bc4bc88df26.zip |
Device sub classes can register themselves. Simplifies device.cpp internals.
Added static instance macro for lazy instantiation of static variables.
Diffstat (limited to 'host/include')
-rw-r--r-- | host/include/uhd/device.hpp | 13 | ||||
-rw-r--r-- | host/include/uhd/dict.hpp | 8 | ||||
-rw-r--r-- | host/include/uhd/usrp/dboard_manager.hpp | 4 | ||||
-rw-r--r-- | host/include/uhd/utils.hpp | 13 |
4 files changed, 34 insertions, 4 deletions
diff --git a/host/include/uhd/device.hpp b/host/include/uhd/device.hpp index 47dfa4328..c9d608bcf 100644 --- a/host/include/uhd/device.hpp +++ b/host/include/uhd/device.hpp @@ -37,6 +37,19 @@ class device : boost::noncopyable, public wax::obj{ public: typedef boost::shared_ptr<device> sptr; + typedef boost::function<device_addrs_t(const device_addr_t &)> discover_t; + typedef boost::function<sptr(const device_addr_t &)> make_t; + + /*! + * Register a device into the discovery and factory system. + * + * \param discover a function that discovers devices + * \param make a factory function that makes a device + */ + static void register_device( + const discover_t &discover, + const make_t &make + ); /*! * \brief Discover usrp devices attached to the host. diff --git a/host/include/uhd/dict.hpp b/host/include/uhd/dict.hpp index 1ed28551a..2224a0063 100644 --- a/host/include/uhd/dict.hpp +++ b/host/include/uhd/dict.hpp @@ -57,6 +57,14 @@ namespace uhd{ } /*! + * Get the number of elements in this dict. + * \param the number of elements + */ + std::size_t size(void) const{ + return _map.size(); + } + + /*! * Get a list of the keys in this dict. * \return vector of keys */ diff --git a/host/include/uhd/usrp/dboard_manager.hpp b/host/include/uhd/usrp/dboard_manager.hpp index cf69675fc..0c32c6dba 100644 --- a/host/include/uhd/usrp/dboard_manager.hpp +++ b/host/include/uhd/usrp/dboard_manager.hpp @@ -40,14 +40,14 @@ public: typedef dboard_base::sptr(*dboard_ctor_t)(dboard_base::ctor_args_t const&); /*! - * Register subdevices for a given dboard id. + * Register a dboard into the system. * * \param dboard_id the dboard id (rx or tx) * \param dboard_ctor the dboard constructor function pointer * \param name the canonical name for the dboard represented * \param subdev_names the names of the subdevs on this dboard */ - static void register_subdevs( + static void register_dboard( dboard_id_t dboard_id, dboard_ctor_t dboard_ctor, const std::string &name, diff --git a/host/include/uhd/utils.hpp b/host/include/uhd/utils.hpp index 2f6e4fd87..995cb9926 100644 --- a/host/include/uhd/utils.hpp +++ b/host/include/uhd/utils.hpp @@ -24,9 +24,18 @@ #include <boost/current_function.hpp> /*! + * Defines a function that implements the "construct on first use" idiom + * \param _t the type definition for the instance + * \param _x the name of the defined function + * \return a reference to the lazy instance + */ +#define STATIC_INSTANCE(_t, _x) static _t &_x(){static _t _x; return _x;} + +/*! * Defines a static code block that will be called before main() + * \param _x the name of the defined struct (must be unique in file) */ -#define STATIC_BLOCK(_x) struct _x{_x();}_x;_x::_x() +#define STATIC_BLOCK(_x) static struct _x{_x();}_x;_x::_x() /*! * Useful templated functions and classes that I like to pretend are part of stl @@ -42,7 +51,7 @@ namespace std{ #define ASSERT_THROW(_x) if (not (_x)) { \ throw std::assert_error(str(boost::format( \ - "Assertion Failed:\n %s:%d\n %s\n __/ %s __/" \ + "Assertion Failed:\n %s:%d\n %s\n ---> %s <---" \ ) % __FILE__ % __LINE__ % BOOST_CURRENT_FUNCTION % std::string(#_x))); \ } |