diff options
author | Josh Blum <josh@joshknows.com> | 2010-02-05 11:36:17 -0800 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-02-05 11:36:17 -0800 |
commit | 89152d1ffe452438db46932ebc62d5ccc5b79208 (patch) | |
tree | 47c261e35669fbc8a5e0dd0a1a9db63bcd1a5964 | |
parent | bff701727b268a87900b5f8445847a3920c23541 (diff) | |
download | uhd-89152d1ffe452438db46932ebc62d5ccc5b79208.tar.gz uhd-89152d1ffe452438db46932ebc62d5ccc5b79208.tar.bz2 uhd-89152d1ffe452438db46932ebc62d5ccc5b79208.zip |
Made get_link the only way to create nested props.
Removed the obj::ptr and sptr typedefs.
The dboard manager now must store not the subdevs, but their proxies.
-rw-r--r-- | include/usrp_uhd/gain_handler.hpp | 4 | ||||
-rw-r--r-- | include/usrp_uhd/usrp/dboard/manager.hpp | 11 | ||||
-rw-r--r-- | include/usrp_uhd/wax.hpp | 12 | ||||
-rw-r--r-- | lib/gain_handler.cpp | 2 | ||||
-rw-r--r-- | lib/usrp/dboard/manager.cpp | 36 | ||||
-rw-r--r-- | lib/usrp/mboard/test.cpp | 16 | ||||
-rw-r--r-- | lib/wax.cpp | 28 | ||||
-rw-r--r-- | test/usrp_dboard_test.cpp | 4 | ||||
-rw-r--r-- | test/wax_test.cpp | 2 |
9 files changed, 70 insertions, 45 deletions
diff --git a/include/usrp_uhd/gain_handler.hpp b/include/usrp_uhd/gain_handler.hpp index 22e987803..786db993b 100644 --- a/include/usrp_uhd/gain_handler.hpp +++ b/include/usrp_uhd/gain_handler.hpp @@ -31,7 +31,7 @@ public: typedef boost::shared_ptr<gain_handler> sptr; template <class T> gain_handler( - wax::obj::ptr wax_obj_ptr, const T &gain_prop, + wax::obj *wax_obj_ptr, const T &gain_prop, const T &gain_min_prop, const T &gain_max_prop, const T &gain_step_prop, const T &gain_names_prop ){ @@ -63,7 +63,7 @@ public: private: - wax::obj::ptr _wax_obj_ptr; + wax::obj *_wax_obj_ptr; wax::obj _gain_prop; wax::obj _gain_min_prop; wax::obj _gain_max_prop; diff --git a/include/usrp_uhd/usrp/dboard/manager.hpp b/include/usrp_uhd/usrp/dboard/manager.hpp index e4eb76bcf..8cc5658d9 100644 --- a/include/usrp_uhd/usrp/dboard/manager.hpp +++ b/include/usrp_uhd/usrp/dboard/manager.hpp @@ -66,14 +66,15 @@ public: //interface prop_names_t get_rx_subdev_names(void); prop_names_t get_tx_subdev_names(void); - wax::obj::sptr get_rx_subdev(const std::string &subdev_name); - wax::obj::sptr get_tx_subdev(const std::string &subdev_name); + wax::obj get_rx_subdev(const std::string &subdev_name); + wax::obj get_tx_subdev(const std::string &subdev_name); private: //list of rx and tx dboards in this manager - //each dboard here is actually a subdevice - std::map<std::string, base::sptr> _rx_dboards; - std::map<std::string, base::sptr> _tx_dboards; + //each dboard here is actually a subdevice proxy + //the subdevice proxy is internal to the cpp file + std::map<std::string, wax::obj> _rx_dboards; + std::map<std::string, wax::obj> _tx_dboards; }; }}} //namespace diff --git a/include/usrp_uhd/wax.hpp b/include/usrp_uhd/wax.hpp index f0e7a3acc..29a96cdb6 100644 --- a/include/usrp_uhd/wax.hpp +++ b/include/usrp_uhd/wax.hpp @@ -19,7 +19,6 @@ #define INCLUDED_WAX_HPP #include <boost/any.hpp> -#include <boost/shared_ptr.hpp> #include <iostream> /*! @@ -45,8 +44,6 @@ namespace wax{ - typedef boost::bad_any_cast bad_cast; - /*! * WAX object base class: * @@ -61,9 +58,6 @@ namespace wax{ */ class obj{ public: - //obj pointer typedefs - typedef boost::shared_ptr<obj> sptr; - typedef obj* ptr; /*! * Default constructor: @@ -151,6 +145,12 @@ namespace wax{ }; /*! + * The wax::bad cast will be thrown when + * cast is called with the wrong typeid. + */ + typedef boost::bad_any_cast bad_cast; + + /*! * Cast a wax::obj into the desired obj. * Usage wax::cast<new_obj>(my_value). * diff --git a/lib/gain_handler.cpp b/lib/gain_handler.cpp index 3d0c38aa1..8713ad766 100644 --- a/lib/gain_handler.cpp +++ b/lib/gain_handler.cpp @@ -33,7 +33,7 @@ using namespace usrp_uhd; /*! * Helper function to simplify getting a named gain (also min, max, step). */ -static gain_t get_named_gain(wax::obj::ptr wax_obj_ptr, wax::obj prop, std::string name){ +static gain_t get_named_gain(wax::obj *wax_obj_ptr, wax::obj prop, std::string name){ return wax::cast<gain_t>((*wax_obj_ptr)[named_prop_t(prop, name)]); } diff --git a/lib/usrp/dboard/manager.cpp b/lib/usrp/dboard/manager.cpp index 12cfdd156..759cb20b8 100644 --- a/lib/usrp/dboard/manager.cpp +++ b/lib/usrp/dboard/manager.cpp @@ -140,23 +140,37 @@ manager::manager( base::sptr xcvr_dboard = rx_dboard_ctor( base::ctor_args_t(name, dboard_interface) ); - _rx_dboards[name] = xcvr_dboard; - _tx_dboards[name] = xcvr_dboard; + //create a rx proxy for this xcvr board + _rx_dboards[name] = subdev_proxy::sptr( + new subdev_proxy(xcvr_dboard, subdev_proxy::RX_TYPE) + ); + //create a tx proxy for this xcvr board + _tx_dboards[name] = subdev_proxy::sptr( + new subdev_proxy(xcvr_dboard, subdev_proxy::TX_TYPE) + ); } } //make tx and rx subdevs (separate subdevs for rx and tx dboards) else{ //make the rx subdevs BOOST_FOREACH(std::string name, ctor_to_names_map[rx_dboard_ctor]){ - _rx_dboards[name] = rx_dboard_ctor( + base::sptr rx_dboard = rx_dboard_ctor( base::ctor_args_t(name, dboard_interface) ); + //create a rx proxy for this rx board + _rx_dboards[name] = subdev_proxy::sptr( + new subdev_proxy(rx_dboard, subdev_proxy::RX_TYPE) + ); } //make the tx subdevs BOOST_FOREACH(std::string name, ctor_to_names_map[tx_dboard_ctor]){ - _tx_dboards[name] = tx_dboard_ctor( + base::sptr tx_dboard = tx_dboard_ctor( base::ctor_args_t(name, dboard_interface) ); + //create a tx proxy for this tx board + _tx_dboards[name] = subdev_proxy::sptr( + new subdev_proxy(tx_dboard, subdev_proxy::TX_TYPE) + ); } } } @@ -173,20 +187,18 @@ prop_names_t manager::get_tx_subdev_names(void){ return get_map_keys(_tx_dboards); } -wax::obj::sptr manager::get_rx_subdev(const std::string &subdev_name){ +wax::obj manager::get_rx_subdev(const std::string &subdev_name){ if (_rx_dboards.count(subdev_name) == 0) throw std::invalid_argument( str(boost::format("Unknown rx subdev name %s") % subdev_name) ); - return wax::obj::sptr(new subdev_proxy( - _rx_dboards[subdev_name], subdev_proxy::RX_TYPE) - ); + //get a link to the rx subdev proxy + return wax::cast<subdev_proxy::sptr>(_rx_dboards[subdev_name])->get_link(); } -wax::obj::sptr manager::get_tx_subdev(const std::string &subdev_name){ +wax::obj manager::get_tx_subdev(const std::string &subdev_name){ if (_tx_dboards.count(subdev_name) == 0) throw std::invalid_argument( str(boost::format("Unknown tx subdev name %s") % subdev_name) ); - return wax::obj::sptr(new subdev_proxy( - _tx_dboards[subdev_name], subdev_proxy::TX_TYPE) - ); + //get a link to the tx subdev proxy + return wax::cast<subdev_proxy::sptr>(_tx_dboards[subdev_name])->get_link(); } diff --git a/lib/usrp/mboard/test.cpp b/lib/usrp/mboard/test.cpp index 57482448c..b54d66408 100644 --- a/lib/usrp/mboard/test.cpp +++ b/lib/usrp/mboard/test.cpp @@ -140,9 +140,11 @@ void test::get(const wax::obj &key_, wax::obj &val){ if (_dboard_managers.count(name) == 0) throw std::invalid_argument( str(boost::format("Unknown rx dboard name %s") % name) ); - val = wax::obj::sptr( - new shell_dboard(_dboard_managers[name], shell_dboard::TYPE_RX) - ); + //FIXME store the shell dboard within the class + //may not fix, plan to remove this test class when real usrps work + //val = wax::obj::sptr( + // new shell_dboard(_dboard_managers[name], shell_dboard::TYPE_RX) + //); return; case MBOARD_PROP_RX_DBOARD_NAMES: @@ -153,9 +155,11 @@ void test::get(const wax::obj &key_, wax::obj &val){ if (_dboard_managers.count(name) == 0) throw std::invalid_argument( str(boost::format("Unknown tx dboard name %s") % name) ); - val = wax::obj::sptr( - new shell_dboard(_dboard_managers[name], shell_dboard::TYPE_TX) - ); + //FIXME store the shell dboard within the class + //may not fix, plan to remove this test class when real usrps work + //val = wax::obj::sptr( + // new shell_dboard(_dboard_managers[name], shell_dboard::TYPE_TX) + //); return; case MBOARD_PROP_TX_DBOARD_NAMES: diff --git a/lib/wax.cpp b/lib/wax.cpp index 0ae0d4315..a75acdc7f 100644 --- a/lib/wax.cpp +++ b/lib/wax.cpp @@ -34,6 +34,18 @@ struct proxy_args_t{ boost::function<void(const wax::obj &)> set; }; +/*! + * The link args for internal use within this cpp file: + * + * It contains a link (in this case a pointer) to a wax object. + * Only the methods in this file may create or parse link args. + * The get_link method is the creator of a link args object. + * The [] operator will resolve the link and make the [] call. + */ +struct link_args_t{ + wax::obj *obj_ptr; +}; + /*********************************************************************** * Structors **********************************************************************/ @@ -55,16 +67,12 @@ wax::obj::~obj(void){ wax::obj wax::obj::operator[](const obj &key){ if (_contents.type() == typeid(proxy_args_t)){ obj val = resolve(); - //check if its a regular pointer and call - if (val.type() == typeid(obj::ptr)){ - return (*cast<obj::ptr>(val))[key]; - } - //check if its a smart pointer and call - if (val.type() == typeid(obj::sptr)){ - return (*cast<obj::sptr>(val))[key]; + //check if its a special link and call + if (val.type() == typeid(link_args_t)){ + return (*cast<link_args_t>(val).obj_ptr)[key]; } //unknown obj - throw std::runtime_error("cannot use [] on non wax::obj pointer"); + throw std::runtime_error("cannot use [] on non wax::obj link"); } else{ proxy_args_t proxy_args; @@ -88,7 +96,9 @@ wax::obj & wax::obj::operator=(const obj &val){ * Public Methods **********************************************************************/ wax::obj wax::obj::get_link(void) const{ - return ptr(this); + link_args_t link_args; + link_args.obj_ptr = const_cast<obj*>(this); + return link_args; } const std::type_info & wax::obj::type(void) const{ diff --git a/test/usrp_dboard_test.cpp b/test/usrp_dboard_test.cpp index 60a10a384..5bd086dc1 100644 --- a/test/usrp_dboard_test.cpp +++ b/test/usrp_dboard_test.cpp @@ -55,6 +55,6 @@ BOOST_AUTO_TEST_CASE(test_manager){ std::cout << "Testing access (will fail later when db code filled in)..." << std::endl; BOOST_CHECK_THROW(mgr0->get_rx_subdev(""), std::invalid_argument); BOOST_CHECK_THROW(mgr0->get_tx_subdev("x"), std::invalid_argument); - (*mgr0->get_rx_subdev("a"))[NULL]; - (*mgr0->get_tx_subdev(""))[NULL]; + mgr0->get_rx_subdev("a")[NULL]; + mgr0->get_tx_subdev("")[NULL]; } diff --git a/test/wax_test.cpp b/test/wax_test.cpp index b329788f2..de66a9f64 100644 --- a/test/wax_test.cpp +++ b/test/wax_test.cpp @@ -71,8 +71,6 @@ BOOST_AUTO_TEST_CASE(test_chaining){ wd[size_t(0)][size_t(0)]; std::cout << "chain 3" << std::endl; wd[size_t(0)][size_t(0)][size_t(0)]; - std::cout << "cast proxy with link" << std::endl; - wax::cast<wax::obj::ptr>(wd[size_t(0)][size_t(0)]); } BOOST_AUTO_TEST_CASE(test_set_get){ |