From 04b8cca22b61c24ca0451b7655b46b85c9a7f310 Mon Sep 17 00:00:00 2001 From: Aaron Rossetto Date: Mon, 1 Jun 2020 14:36:15 -0500 Subject: python: Add block controller factory utility This commit adds a utility class for use with the Python RFNoC block controller PyBind bindings which facilitates constructing instances of a specific block controller type from its noc_block_base base class. This allows Python code to create and configure specific block controller instances by calling get_block on a uhd.rfnoc.RfnocGraph object with the block ID of the block in question and then passing the result into the constructor method of the block controller, e.g.: graph = uhd.rfnoc.RfnocGraph("addr=...") block = graph.get_block(uhd.rfnoc.BlockID("0/DDC#0")) ddc = uhd.rfnoc.DdcBlockControl(block) ddc.set_input_rate(10e6, 0) --- host/lib/rfnoc/block_controller_factory_python.hpp | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 host/lib/rfnoc/block_controller_factory_python.hpp (limited to 'host') diff --git a/host/lib/rfnoc/block_controller_factory_python.hpp b/host/lib/rfnoc/block_controller_factory_python.hpp new file mode 100644 index 000000000..2eda892dd --- /dev/null +++ b/host/lib/rfnoc/block_controller_factory_python.hpp @@ -0,0 +1,30 @@ +// +// Copyright 2020 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-laster +// + +#pragma once + +#include + +using namespace uhd::rfnoc; + +namespace { + +// Static factory for constructing a block controller T given an instance of +// the superclass noc_block_base for the block controller, as might be +// returned from uhd::rfnoc::graph::get_block(). The instance is downcast to +// the derived class and returned to the client as a T::sptr. If block_base +// does not represent an instance of T, nullptr is returned. +template +class block_controller_factory +{ +public: + static typename T::sptr make_from(noc_block_base::sptr block_base) + { + return std::dynamic_pointer_cast(block_base); + } +}; + +} // namespace -- cgit v1.2.3