From f0371292a43c3e4e3c68d8631c57d64ab10faf4c Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Tue, 7 May 2019 14:39:26 -0700 Subject: rfnoc: Add detail::block_container_t class This is a storage for the noc_block_base derivatives. It supports finding blocks. --- host/lib/rfnoc/block_container.cpp | 74 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 host/lib/rfnoc/block_container.cpp (limited to 'host/lib/rfnoc/block_container.cpp') diff --git a/host/lib/rfnoc/block_container.cpp b/host/lib/rfnoc/block_container.cpp new file mode 100644 index 000000000..0151b228b --- /dev/null +++ b/host/lib/rfnoc/block_container.cpp @@ -0,0 +1,74 @@ +// +// Copyright 2019 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#include +#include +#include +#include + + +using namespace uhd::rfnoc::detail; + +using uhd::rfnoc::block_id_t; +using uhd::rfnoc::noc_block_base; + +/****************************************************************************** + * Structors + *****************************************************************************/ +block_container_t::block_container_t() +{ + // nop +} + + +/****************************************************************************** + * API + *****************************************************************************/ +void block_container_t::register_block(noc_block_base::sptr block) +{ + std::lock_guard lock(_mutex); + UHD_LOGGER_DEBUG("RFNOC::BLOCK_CONTAINER") + << boost::format("Registering block: %s (NOC ID=%08x)") % block->get_unique_id() + % block->get_noc_id(); + _blocks.insert(block); +} + +std::vector block_container_t::find_blocks( + const std::string& block_id_hint) const +{ + std::lock_guard lock(_mutex); + std::vector block_ids; + for (auto it = _blocks.cbegin(); it != _blocks.cend(); ++it) { + auto id = (*it)->get_block_id(); + if (id.match(block_id_hint) || block_id_hint.empty()) { + block_ids.push_back(id); + } + } + return block_ids; +} + +bool block_container_t::has_block(const block_id_t& block_id) const +{ + std::lock_guard lock(_mutex); + return std::any_of( + _blocks.cbegin(), _blocks.cend(), [block_id](noc_block_base::sptr block) { + return block->get_block_id() == block_id; + }); +} + +noc_block_base::sptr block_container_t::get_block(const block_id_t& block_id) const +{ + auto block_itr = std::find_if( + _blocks.cbegin(), _blocks.cend(), [block_id](noc_block_base::sptr block) { + return block->get_block_id() == block_id; + }); + if (block_itr == _blocks.cend()) { + throw uhd::lookup_error(std::string("This device does not have a block with ID: ") + + block_id.to_string()); + } + return *block_itr; +} + -- cgit v1.2.3