1 // 2 // Copyright 2019 Ettus Research, a National Instruments Brand 3 // 4 // SPDX-License-Identifier: GPL-3.0-or-later 5 // 6 7 #include <uhd/utils/log.hpp> 8 #include <uhdlib/rfnoc/block_container.hpp> 9 #include <uhdlib/rfnoc/node_accessor.hpp> 10 #include <boost/format.hpp> 11 #include <algorithm> 12 13 14 using namespace uhd::rfnoc::detail; 15 16 using uhd::rfnoc::block_id_t; 17 using uhd::rfnoc::noc_block_base; 18 19 /****************************************************************************** 20 * Structors 21 *****************************************************************************/ block_container_t()22block_container_t::block_container_t() 23 { 24 // nop 25 } 26 27 28 /****************************************************************************** 29 * API 30 *****************************************************************************/ register_block(noc_block_base::sptr block)31void block_container_t::register_block(noc_block_base::sptr block) 32 { 33 std::lock_guard<std::mutex> lock(_mutex); 34 UHD_LOGGER_DEBUG("RFNOC::BLOCK_CONTAINER") 35 << boost::format("Registering block: %s (NOC ID=%08x)") % block->get_unique_id() 36 % block->get_noc_id(); 37 _blocks.insert(block); 38 } 39 find_blocks(const std::string & block_id_hint) const40std::vector<block_id_t> block_container_t::find_blocks( 41 const std::string& block_id_hint) const 42 { 43 std::lock_guard<std::mutex> lock(_mutex); 44 std::vector<block_id_t> block_ids; 45 for (auto it = _blocks.cbegin(); it != _blocks.cend(); ++it) { 46 auto id = (*it)->get_block_id(); 47 if (id.match(block_id_hint) || block_id_hint.empty()) { 48 block_ids.push_back(id); 49 } 50 } 51 std::sort(block_ids.begin(), 52 block_ids.end(), 53 [](const uhd::rfnoc::block_id_t& i, const uhd::rfnoc::block_id_t& j) { 54 return i < j; 55 }); 56 return block_ids; 57 } 58 has_block(const block_id_t & block_id) const59bool block_container_t::has_block(const block_id_t& block_id) const 60 { 61 std::lock_guard<std::mutex> lock(_mutex); 62 return std::any_of( 63 _blocks.cbegin(), _blocks.cend(), [block_id](noc_block_base::sptr block) { 64 return block->get_block_id() == block_id; 65 }); 66 } 67 get_block(const block_id_t & block_id) const68noc_block_base::sptr block_container_t::get_block(const block_id_t& block_id) const 69 { 70 auto block_itr = std::find_if( 71 _blocks.cbegin(), _blocks.cend(), [block_id](noc_block_base::sptr block) { 72 return block->get_block_id() == block_id; 73 }); 74 if (block_itr == _blocks.cend()) { 75 throw uhd::lookup_error(std::string("This device does not have a block with ID: ") 76 + block_id.to_string()); 77 } 78 return *block_itr; 79 } 80 shutdown()81void block_container_t::shutdown() 82 { 83 node_accessor_t node_accessor{}; 84 for (auto it = _blocks.begin(); it != _blocks.end(); ++it) { 85 node_accessor.shutdown(it->get()); 86 } 87 } 88 init_props()89void block_container_t::init_props() 90 { 91 node_accessor_t node_accessor{}; 92 for (auto it = _blocks.begin(); it != _blocks.end(); ++it) { 93 node_accessor.init_props(it->get()); 94 } 95 } 96