aboutsummaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorAaron Rossetto <aaron.rossetto@ni.com>2020-06-01 14:36:15 -0500
committerAaron Rossetto <aaron.rossetto@ni.com>2020-06-09 07:09:34 -0500
commit04b8cca22b61c24ca0451b7655b46b85c9a7f310 (patch)
tree361d1575317bf58ef64b8acb790d9ba48113e5f9 /host
parent6aa090b7fdab3f380b52b1e572f2602e049d7d2b (diff)
downloaduhd-04b8cca22b61c24ca0451b7655b46b85c9a7f310.tar.gz
uhd-04b8cca22b61c24ca0451b7655b46b85c9a7f310.tar.bz2
uhd-04b8cca22b61c24ca0451b7655b46b85c9a7f310.zip
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)
Diffstat (limited to 'host')
-rw-r--r--host/lib/rfnoc/block_controller_factory_python.hpp30
1 files changed, 30 insertions, 0 deletions
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 <uhd/rfnoc/noc_block_base.hpp>
+
+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 <typename T>
+class block_controller_factory
+{
+public:
+ static typename T::sptr make_from(noc_block_base::sptr block_base)
+ {
+ return std::dynamic_pointer_cast<T>(block_base);
+ }
+};
+
+} // namespace