diff options
Diffstat (limited to 'host/lib')
-rw-r--r-- | host/lib/property_tree.cpp | 102 | ||||
-rw-r--r-- | host/lib/usrp/b100/b100_impl.cpp | 8 | ||||
-rw-r--r-- | host/lib/usrp/b100/io_impl.cpp | 4 | ||||
-rw-r--r-- | host/lib/usrp/e100/e100_impl.cpp | 8 | ||||
-rw-r--r-- | host/lib/usrp/e100/io_impl.cpp | 4 | ||||
-rw-r--r-- | host/lib/usrp/multi_usrp.cpp | 10 | ||||
-rw-r--r-- | host/lib/usrp/usrp1/usrp1_impl.cpp | 10 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/io_impl.cpp | 4 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/usrp2_impl.cpp | 10 |
9 files changed, 102 insertions, 58 deletions
diff --git a/host/lib/property_tree.cpp b/host/lib/property_tree.cpp index 58cd3f6ea..50e82a6ba 100644 --- a/host/lib/property_tree.cpp +++ b/host/lib/property_tree.cpp @@ -22,17 +22,63 @@ #include <boost/make_shared.hpp> #include <iostream> +using namespace uhd; + +/*********************************************************************** + * Helper function to iterate through paths + **********************************************************************/ +#include <boost/tokenizer.hpp> +#define path_tokenizer(path) \ + boost::tokenizer<boost::char_separator<char> > \ + (path, boost::char_separator<char>("/")) + +/*********************************************************************** + * Property path implementation wrapper + **********************************************************************/ +fs_path::fs_path(void): std::string(){} +fs_path::fs_path(const char *p): std::string(p){} +fs_path::fs_path(const std::string &p): std::string(p){} + +std::string fs_path::leaf(void) const{ + const size_t pos = this->rfind("/"); + if (pos == std::string::npos) return *this; + return this->substr(pos+1); +} + +fs_path fs_path::branch_path(void) const{ + const size_t pos = this->rfind("/"); + if (pos == std::string::npos) return *this; + return fs_path(this->substr(0, pos)); +} + +fs_path uhd::operator/(const fs_path &lhs, const fs_path &rhs){ + //strip trailing slash on left-hand-side + if (not lhs.empty() and *lhs.rbegin() == '/'){ + return fs_path(lhs.substr(0, lhs.size()-1)) / rhs; + } + + //strip leading slash on right-hand-side + if (not rhs.empty() and *rhs.begin() == '/'){ + return lhs / fs_path(rhs.substr(1)); + } + + return fs_path(lhs + "/" + rhs); +} + +/*********************************************************************** + * Property tree implementation + **********************************************************************/ class property_tree_impl : public uhd::property_tree{ public: - property_tree_impl(const path_type &root = path_type()): + property_tree_impl(const fs_path &root = fs_path()): _root(root) { _guts = boost::make_shared<tree_guts_type>(); } - sptr subtree(const path_type &path_) const{ - const path_type path = _root / path_; + sptr subtree(const fs_path &path_) const{ + const fs_path path = _root / path_; boost::mutex::scoped_lock lock(_guts->mutex); property_tree_impl *subtree = new property_tree_impl(path); @@ -40,42 +86,39 @@ public: return sptr(subtree); } - void remove(const path_type &path_){ - const path_type path = _root / path_; + void remove(const fs_path &path_){ + const fs_path path = _root / path_; boost::mutex::scoped_lock lock(_guts->mutex); node_type *parent = NULL; node_type *node = &_guts->root; - BOOST_FOREACH(const path_type &branch, path){ - const std::string name = branch.string(); + BOOST_FOREACH(const std::string &name, path_tokenizer(path)){ if (not node->has_key(name)) throw_path_not_found(path); parent = node; node = &(*node)[name]; } if (parent == NULL) throw uhd::runtime_error("Cannot uproot"); - parent->pop(path_type(path.leaf()).string()); + parent->pop(fs_path(path.leaf())); } - bool exists(const path_type &path_) const{ - const path_type path = _root / path_; + bool exists(const fs_path &path_) const{ + const fs_path path = _root / path_; boost::mutex::scoped_lock lock(_guts->mutex); node_type *node = &_guts->root; - BOOST_FOREACH(const path_type &branch, path){ - const std::string name = branch.string(); + BOOST_FOREACH(const std::string &name, path_tokenizer(path)){ if (not node->has_key(name)) return false; node = &(*node)[name]; } return true; } - std::vector<std::string> list(const path_type &path_) const{ - const path_type path = _root / path_; + std::vector<std::string> list(const fs_path &path_) const{ + const fs_path path = _root / path_; boost::mutex::scoped_lock lock(_guts->mutex); node_type *node = &_guts->root; - BOOST_FOREACH(const path_type &branch, path){ - const std::string name = branch.string(); + BOOST_FOREACH(const std::string &name, path_tokenizer(path)){ if (not node->has_key(name)) throw_path_not_found(path); node = &(*node)[name]; } @@ -83,37 +126,35 @@ public: return node->keys(); } - void _create(const path_type &path_, const boost::shared_ptr<void> &prop){ - const path_type path = _root / path_; + void _create(const fs_path &path_, const boost::shared_ptr<void> &prop){ + const fs_path path = _root / path_; boost::mutex::scoped_lock lock(_guts->mutex); node_type *node = &_guts->root; - BOOST_FOREACH(const path_type &branch, path){ - const std::string name = branch.string(); + BOOST_FOREACH(const std::string &name, path_tokenizer(path)){ if (not node->has_key(name)) (*node)[name] = node_type(); node = &(*node)[name]; } - if (node->prop.get() != NULL) throw uhd::runtime_error("Cannot create! Property already exists at: " + path.string()); + if (node->prop.get() != NULL) throw uhd::runtime_error("Cannot create! Property already exists at: " + path); node->prop = prop; } - boost::shared_ptr<void> &_access(const path_type &path_) const{ - const path_type path = _root / path_; + boost::shared_ptr<void> &_access(const fs_path &path_) const{ + const fs_path path = _root / path_; boost::mutex::scoped_lock lock(_guts->mutex); node_type *node = &_guts->root; - BOOST_FOREACH(const path_type &branch, path){ - const std::string name = branch.string(); + BOOST_FOREACH(const std::string &name, path_tokenizer(path)){ if (not node->has_key(name)) throw_path_not_found(path); node = &(*node)[name]; } - if (node->prop.get() == NULL) throw uhd::runtime_error("Cannot access! Property uninitialized at: " + path.string()); + if (node->prop.get() == NULL) throw uhd::runtime_error("Cannot access! Property uninitialized at: " + path); return node->prop; } private: - void throw_path_not_found(const path_type &path) const{ - throw uhd::lookup_error("Path not found in tree: " + path.string()); + void throw_path_not_found(const fs_path &path) const{ + throw uhd::lookup_error("Path not found in tree: " + path); } //basic structural node element @@ -129,9 +170,12 @@ private: //members, the tree and root prefix boost::shared_ptr<tree_guts_type> _guts; - const path_type _root; + const fs_path _root; }; +/*********************************************************************** + * Property tree factory + **********************************************************************/ uhd::property_tree::sptr uhd::property_tree::make(void){ return sptr(new property_tree_impl()); } diff --git a/host/lib/usrp/b100/b100_impl.cpp b/host/lib/usrp/b100/b100_impl.cpp index 2e2421ed3..ea9c91c50 100644 --- a/host/lib/usrp/b100/b100_impl.cpp +++ b/host/lib/usrp/b100/b100_impl.cpp @@ -209,7 +209,7 @@ b100_impl::b100_impl(const device_addr_t &device_addr){ //////////////////////////////////////////////////////////////////// _tree = property_tree::make(); _tree->create<std::string>("/name").set("B-Series Device"); - const property_tree::path_type mb_path = "/mboards/0"; + const fs_path mb_path = "/mboards/0"; _tree->create<std::string>(mb_path / "name").set("B100 (B-Hundo)"); _tree->create<std::string>(mb_path / "load_eeprom") .subscribe(boost::bind(&fx2_ctrl::usrp_load_eeprom, _fx2_ctrl, _1)); @@ -234,8 +234,8 @@ b100_impl::b100_impl(const device_addr_t &device_addr){ // create codec control objects //////////////////////////////////////////////////////////////////// _codec_ctrl = b100_codec_ctrl::make(_fpga_spi_ctrl); - const property_tree::path_type rx_codec_path = mb_path / "rx_codecs/A"; - const property_tree::path_type tx_codec_path = mb_path / "tx_codecs/A"; + const fs_path rx_codec_path = mb_path / "rx_codecs/A"; + const fs_path tx_codec_path = mb_path / "tx_codecs/A"; _tree->create<std::string>(rx_codec_path / "name").set("ad9522"); _tree->create<meta_range_t>(rx_codec_path / "gains/pga/range").set(b100_codec_ctrl::rx_pga_gain_range); _tree->create<double>(rx_codec_path / "gains/pga/value") @@ -276,7 +276,7 @@ b100_impl::b100_impl(const device_addr_t &device_addr){ _rx_dsps[dspno]->set_link_rate(B100_LINK_RATE_BPS); _tree->access<double>(mb_path / "tick_rate") .subscribe(boost::bind(&rx_dsp_core_200::set_tick_rate, _rx_dsps[dspno], _1)); - property_tree::path_type rx_dsp_path = mb_path / str(boost::format("rx_dsps/%u") % dspno); + fs_path rx_dsp_path = mb_path / str(boost::format("rx_dsps/%u") % dspno); _tree->create<double>(rx_dsp_path / "rate/value") .coerce(boost::bind(&rx_dsp_core_200::set_host_rate, _rx_dsps[dspno], _1)) .subscribe(boost::bind(&b100_impl::update_rx_samp_rate, this, _1)); diff --git a/host/lib/usrp/b100/io_impl.cpp b/host/lib/usrp/b100/io_impl.cpp index d841188c0..34535217a 100644 --- a/host/lib/usrp/b100/io_impl.cpp +++ b/host/lib/usrp/b100/io_impl.cpp @@ -140,7 +140,7 @@ void b100_impl::update_tx_samp_rate(const double rate){ void b100_impl::update_rx_subdev_spec(const uhd::usrp::subdev_spec_t &spec){ boost::mutex::scoped_lock recv_lock = _io_impl->recv_handler.get_scoped_lock(); - property_tree::path_type root = "/mboards/0/dboards"; + fs_path root = "/mboards/0/dboards"; //sanity checking validate_subdev_spec(_tree, spec, "rx"); @@ -169,7 +169,7 @@ void b100_impl::update_rx_subdev_spec(const uhd::usrp::subdev_spec_t &spec){ void b100_impl::update_tx_subdev_spec(const uhd::usrp::subdev_spec_t &spec){ boost::mutex::scoped_lock send_lock = _io_impl->send_handler.get_scoped_lock(); - property_tree::path_type root = "/mboards/0/dboards"; + fs_path root = "/mboards/0/dboards"; //sanity checking validate_subdev_spec(_tree, spec, "tx"); diff --git a/host/lib/usrp/e100/e100_impl.cpp b/host/lib/usrp/e100/e100_impl.cpp index cca4ee9b3..0defb2973 100644 --- a/host/lib/usrp/e100/e100_impl.cpp +++ b/host/lib/usrp/e100/e100_impl.cpp @@ -170,7 +170,7 @@ e100_impl::e100_impl(const uhd::device_addr_t &device_addr){ //////////////////////////////////////////////////////////////////// _tree = property_tree::make(); _tree->create<std::string>("/name").set("E-Series Device"); - const property_tree::path_type mb_path = "/mboards/0"; + const fs_path mb_path = "/mboards/0"; _tree->create<std::string>(mb_path / "name").set("E100 (euewanee)"); //////////////////////////////////////////////////////////////////// @@ -193,8 +193,8 @@ e100_impl::e100_impl(const uhd::device_addr_t &device_addr){ // create codec control objects //////////////////////////////////////////////////////////////////// _codec_ctrl = e100_codec_ctrl::make(_fpga_spi_ctrl); - const property_tree::path_type rx_codec_path = mb_path / "rx_codecs/A"; - const property_tree::path_type tx_codec_path = mb_path / "tx_codecs/A"; + const fs_path rx_codec_path = mb_path / "rx_codecs/A"; + const fs_path tx_codec_path = mb_path / "tx_codecs/A"; _tree->create<std::string>(rx_codec_path / "name").set("ad9522"); _tree->create<meta_range_t>(rx_codec_path / "gains/pga/range").set(e100_codec_ctrl::rx_pga_gain_range); _tree->create<double>(rx_codec_path / "gains/pga/value") @@ -235,7 +235,7 @@ e100_impl::e100_impl(const uhd::device_addr_t &device_addr){ _rx_dsps[dspno]->set_link_rate(E100_LINK_RATE_BPS); _tree->access<double>(mb_path / "tick_rate") .subscribe(boost::bind(&rx_dsp_core_200::set_tick_rate, _rx_dsps[dspno], _1)); - property_tree::path_type rx_dsp_path = mb_path / str(boost::format("rx_dsps/%u") % dspno); + fs_path rx_dsp_path = mb_path / str(boost::format("rx_dsps/%u") % dspno); _tree->create<double>(rx_dsp_path / "rate/value") .coerce(boost::bind(&rx_dsp_core_200::set_host_rate, _rx_dsps[dspno], _1)) .subscribe(boost::bind(&e100_impl::update_rx_samp_rate, this, _1)); diff --git a/host/lib/usrp/e100/io_impl.cpp b/host/lib/usrp/e100/io_impl.cpp index a10b3ffb3..0b81c1a86 100644 --- a/host/lib/usrp/e100/io_impl.cpp +++ b/host/lib/usrp/e100/io_impl.cpp @@ -218,7 +218,7 @@ void e100_impl::update_tx_samp_rate(const double rate){ void e100_impl::update_rx_subdev_spec(const uhd::usrp::subdev_spec_t &spec){ boost::mutex::scoped_lock recv_lock = _io_impl->recv_handler.get_scoped_lock(); - property_tree::path_type root = "/mboards/0/dboards"; + fs_path root = "/mboards/0/dboards"; //sanity checking validate_subdev_spec(_tree, spec, "rx"); @@ -247,7 +247,7 @@ void e100_impl::update_rx_subdev_spec(const uhd::usrp::subdev_spec_t &spec){ void e100_impl::update_tx_subdev_spec(const uhd::usrp::subdev_spec_t &spec){ boost::mutex::scoped_lock send_lock = _io_impl->send_handler.get_scoped_lock(); - property_tree::path_type root = "/mboards/0/dboards"; + fs_path root = "/mboards/0/dboards"; //sanity checking validate_subdev_spec(_tree, spec, "tx"); diff --git a/host/lib/usrp/multi_usrp.cpp b/host/lib/usrp/multi_usrp.cpp index f9f5e675f..49cbe522f 100644 --- a/host/lib/usrp/multi_usrp.cpp +++ b/host/lib/usrp/multi_usrp.cpp @@ -634,30 +634,30 @@ private: return mcp; } - property_tree::path_type mb_root(const size_t mboard){ + fs_path mb_root(const size_t mboard){ const std::string name = _tree->list("/mboards").at(mboard); return "/mboards/" + name; } - property_tree::path_type rx_dsp_root(const size_t chan){ + fs_path rx_dsp_root(const size_t chan){ mboard_chan_pair mcp = rx_chan_to_mcp(chan); const std::string name = _tree->list(mb_root(mcp.mboard) / "rx_dsps").at(mcp.chan); return mb_root(mcp.mboard) / "rx_dsps" / name; } - property_tree::path_type tx_dsp_root(const size_t chan){ + fs_path tx_dsp_root(const size_t chan){ mboard_chan_pair mcp = tx_chan_to_mcp(chan); const std::string name = _tree->list(mb_root(mcp.mboard) / "tx_dsps").at(mcp.chan); return mb_root(mcp.mboard) / "tx_dsps" / name; } - property_tree::path_type rx_rf_fe_root(const size_t chan){ + fs_path rx_rf_fe_root(const size_t chan){ mboard_chan_pair mcp = rx_chan_to_mcp(chan); const subdev_spec_pair_t spec = get_rx_subdev_spec(mcp.mboard).at(mcp.chan); return mb_root(mcp.mboard) / "dboards" / spec.db_name / "rx_frontends" / spec.sd_name; } - property_tree::path_type tx_rf_fe_root(const size_t chan){ + fs_path tx_rf_fe_root(const size_t chan){ mboard_chan_pair mcp = tx_chan_to_mcp(chan); const subdev_spec_pair_t spec = get_tx_subdev_spec(mcp.mboard).at(mcp.chan); return mb_root(mcp.mboard) / "dboards" / spec.db_name / "tx_frontends" / spec.sd_name; diff --git a/host/lib/usrp/usrp1/usrp1_impl.cpp b/host/lib/usrp/usrp1/usrp1_impl.cpp index 7a8f6497c..7c9e61e94 100644 --- a/host/lib/usrp/usrp1/usrp1_impl.cpp +++ b/host/lib/usrp/usrp1/usrp1_impl.cpp @@ -208,7 +208,7 @@ usrp1_impl::usrp1_impl(const device_addr_t &device_addr){ //////////////////////////////////////////////////////////////////// _tree = property_tree::make(); _tree->create<std::string>("/name").set("USRP1 Device"); - const property_tree::path_type mb_path = "/mboards/0"; + const fs_path mb_path = "/mboards/0"; _tree->create<std::string>(mb_path / "name").set("USRP1 (Classic)"); _tree->create<std::string>(mb_path / "load_eeprom") .subscribe(boost::bind(&fx2_ctrl::usrp_load_eeprom, _fx2_ctrl, _1)); @@ -239,8 +239,8 @@ usrp1_impl::usrp1_impl(const device_addr_t &device_addr){ //////////////////////////////////////////////////////////////////// BOOST_FOREACH(const std::string &db, _dbc.keys()){ _dbc[db].codec = usrp1_codec_ctrl::make(_iface, (db == "A")? SPI_ENABLE_CODEC_A : SPI_ENABLE_CODEC_B); - const property_tree::path_type rx_codec_path = mb_path / "rx_codecs" / db; - const property_tree::path_type tx_codec_path = mb_path / "tx_codecs" / db; + const fs_path rx_codec_path = mb_path / "rx_codecs" / db; + const fs_path tx_codec_path = mb_path / "tx_codecs" / db; _tree->create<std::string>(rx_codec_path / "name").set("ad9522"); _tree->create<meta_range_t>(rx_codec_path / "gains/pga/range").set(usrp1_codec_ctrl::rx_pga_gain_range); _tree->create<double>(rx_codec_path / "gains/pga/value") @@ -270,7 +270,7 @@ usrp1_impl::usrp1_impl(const device_addr_t &device_addr){ // create rx dsp control objects //////////////////////////////////////////////////////////////////// for (size_t dspno = 0; dspno < get_num_ddcs(); dspno++){ - property_tree::path_type rx_dsp_path = mb_path / str(boost::format("rx_dsps/%u") % dspno); + fs_path rx_dsp_path = mb_path / str(boost::format("rx_dsps/%u") % dspno); _tree->create<double>(rx_dsp_path / "rate/value") .coerce(boost::bind(&usrp1_impl::update_rx_samp_rate, this, _1)); _tree->create<double>(rx_dsp_path / "freq/value") @@ -289,7 +289,7 @@ usrp1_impl::usrp1_impl(const device_addr_t &device_addr){ // create tx dsp control objects //////////////////////////////////////////////////////////////////// for (size_t dspno = 0; dspno < get_num_ducs(); dspno++){ - property_tree::path_type tx_dsp_path = mb_path / str(boost::format("tx_dsps/%u") % dspno); + fs_path tx_dsp_path = mb_path / str(boost::format("tx_dsps/%u") % dspno); _tree->create<double>(tx_dsp_path / "rate/value") .coerce(boost::bind(&usrp1_impl::update_tx_samp_rate, this, _1)); _tree->create<double>(tx_dsp_path / "freq/value") diff --git a/host/lib/usrp/usrp2/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp index 67bf25c2b..aef3f3a39 100644 --- a/host/lib/usrp/usrp2/io_impl.cpp +++ b/host/lib/usrp/usrp2/io_impl.cpp @@ -316,7 +316,7 @@ static subdev_spec_t replace_zero_in_spec(const std::string &type, const subdev_ subdev_spec_t usrp2_impl::update_rx_subdev_spec(const std::string &which_mb, const subdev_spec_t &spec_){ const subdev_spec_t spec = replace_zero_in_spec("RX", spec_); boost::mutex::scoped_lock recv_lock = _io_impl->recv_handler.get_scoped_lock(); - property_tree::path_type root = "/mboards/" + which_mb + "/dboards"; + fs_path root = "/mboards/" + which_mb + "/dboards"; //sanity checking validate_subdev_spec(_tree, spec, "rx", which_mb); @@ -352,7 +352,7 @@ subdev_spec_t usrp2_impl::update_rx_subdev_spec(const std::string &which_mb, con subdev_spec_t usrp2_impl::update_tx_subdev_spec(const std::string &which_mb, const subdev_spec_t &spec_){ const subdev_spec_t spec = replace_zero_in_spec("TX", spec_); boost::mutex::scoped_lock send_lock = _io_impl->send_handler.get_scoped_lock(); - property_tree::path_type root = "/mboards/" + which_mb + "/dboards"; + fs_path root = "/mboards/" + which_mb + "/dboards"; //sanity checking validate_subdev_spec(_tree, spec, "tx", which_mb); diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 9a8269e6f..f87eb067e 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -328,7 +328,7 @@ usrp2_impl::usrp2_impl(const device_addr_t &_device_addr){ const device_addr_t device_args_i = device_args[mbi]; const std::string mb = boost::lexical_cast<std::string>(mbi); const std::string addr = device_args_i["addr"]; - const property_tree::path_type mb_path = "/mboards/" + mb; + const fs_path mb_path = "/mboards/" + mb; //////////////////////////////////////////////////////////////// // create the iface that controls i2c, spi, uart, and wb @@ -395,8 +395,8 @@ usrp2_impl::usrp2_impl(const device_addr_t &_device_addr){ //////////////////////////////////////////////////////////////// // create codec control objects //////////////////////////////////////////////////////////////// - const property_tree::path_type rx_codec_path = mb_path / "rx_codecs/A"; - const property_tree::path_type tx_codec_path = mb_path / "tx_codecs/A"; + const fs_path rx_codec_path = mb_path / "rx_codecs/A"; + const fs_path tx_codec_path = mb_path / "tx_codecs/A"; _tree->create<int>(rx_codec_path / "gains"); //phony property so this dir exists _tree->create<int>(tx_codec_path / "gains"); //phony property so this dir exists _mbc[mb].codec = usrp2_codec_ctrl::make(_mbc[mb].iface); @@ -479,7 +479,7 @@ usrp2_impl::usrp2_impl(const device_addr_t &_device_addr){ //The dsp core starts streaming briefly... now we flush _mbc[mb].rx_dsp_xports[dspno]->get_recv_buff(0.01).get(); //recv with timeout for lingering _mbc[mb].rx_dsp_xports[dspno]->get_recv_buff(0.01).get(); //recv with timeout for expected - property_tree::path_type rx_dsp_path = mb_path / str(boost::format("rx_dsps/%u") % dspno); + fs_path rx_dsp_path = mb_path / str(boost::format("rx_dsps/%u") % dspno); _tree->create<double>(rx_dsp_path / "rate/value") .coerce(boost::bind(&rx_dsp_core_200::set_host_rate, _mbc[mb].rx_dsps[dspno], _1)) .subscribe(boost::bind(&usrp2_impl::update_rx_samp_rate, this, _1)); @@ -595,7 +595,7 @@ usrp2_impl::usrp2_impl(const device_addr_t &_device_addr){ //do some post-init tasks BOOST_FOREACH(const std::string &mb, _mbc.keys()){ - property_tree::path_type root = "/mboards/" + mb; + fs_path root = "/mboards/" + mb; _tree->access<double>(root / "tick_rate").update(); //and now that the tick rate is set, init the host rates to something |