| USRP Hardware Driver and USRP Manual Version: 4.9.0.makepkg-0-g9ec1f582 UHD and USRP Manual |

Loading...
Searching...
No Matches
node.ipp
Go to the documentation of this file.
1//
2// Copyright 2019 Ettus Research, a National Instruments Brand
3//
4// SPDX-License-Identifier: GPL-3.0-or-later
5//
6
7#pragma once
8
9#include <boost/format.hpp>
10#include <boost/units/detail/utility.hpp>
11
12 namespace {
13
14 template <typename prop_data_t>
15 uhd::rfnoc::property_t<prop_data_t>* _assert_prop(
16 uhd::rfnoc::property_base_t* prop_base_ptr,
17 const std::string& node_id,
18 const std::string& prop_id)
19{
20 // First check if the pointer is valid at all:
21 if (prop_base_ptr == nullptr) {
22 throw uhd::lookup_error(
23 str(boost::format("[%s] Unknown property: `%s'") % node_id % prop_id));
24 }
25
26 // Next, check if we can cast the pointer to the desired type:
27 auto prop_ptr = dynamic_cast<uhd::rfnoc::property_t<prop_data_t>*>(prop_base_ptr);
28 if (!prop_ptr) {
29 throw uhd::type_error(str(
30 boost::format(
31 "[%s] Found property `%s', but could not cast to requested type `%s'!")
32 % node_id % prop_id
33 % boost::units::detail::demangle(typeid(prop_data_t).name())));
34 }
35
36 // All is good, we now return the raw pointer that has been validated.
37 return prop_ptr;
38}
39
40} // namespace
41
42 namespace uhd { namespace rfnoc {
43
44 template <typename prop_data_t>
45 void node_t::set_property(
46 const std::string& id, const prop_data_t& val, const size_t instance)
47{
48 res_source_info src_info{res_source_info::USER, instance};
49 set_property<prop_data_t>(id, val, src_info);
50}
51
52 template <typename prop_data_t>
53 const prop_data_t& node_t::get_property(const std::string& id, const size_t instance)
54{
55 res_source_info src_info{res_source_info::USER, instance};
56 return get_property<prop_data_t>(id, src_info);
57}
58
59 template <typename prop_data_t>
60 void node_t::set_property(
61 const std::string& id, const prop_data_t& val, const res_source_info& src_info)
62{
63 if (_graph_mutex_cb) {
64 // Node connected to graph. Must lock graph first.
65 std::lock_guard<std::recursive_mutex> l(_graph_mutex_cb());
66 _set_property(id, val, src_info);
67 } else {
68 // Node unconnected to graph
69 _set_property(id, val, src_info);
70 }
71}
72
73 template <typename prop_data_t>
74 const prop_data_t& node_t::get_property(
75 const std::string& id, const res_source_info& src_info)
76{
77 RFNOC_LOG_TRACE("Getting property " << id << "@" << src_info.to_string());
78 // First, trigger a property resolution to make sure this property is
79 // updated (if necessary) before reading it out
80 resolve_all();
81 auto prop_ptr =
82 _assert_prop<prop_data_t>(_find_property(src_info, id), get_unique_id(), id);
83
84 auto prop_access = _request_property_access(prop_ptr, property_base_t::RO);
85 return prop_ptr->get();
86}
87
88 template <typename prop_data_t>
89 void node_t::_set_property(
90 const std::string& id, const prop_data_t& val, const res_source_info& src_info)
91{
92 RFNOC_LOG_TRACE("Setting property " << id << "@" << src_info.to_string());
93
94 auto prop_ptr =
95 _assert_prop<prop_data_t>(_find_property(src_info, id), get_unique_id(), id);
96 {
97 auto prop_access = _request_property_access(prop_ptr, property_base_t::RW);
98 prop_ptr->set(val);
99 }
100
101 // Now trigger a property resolution. If other properties depend on this one,
102 // they will be updated.
103 resolve_all();
104}
105
106}} /* namespace uhd::rfnoc */
uhd::rfnoc::node_t::get_unique_id
virtual std::string get_unique_id() const
Return a unique identifier string for this node. In every RFNoC graph,.
uhd::rfnoc::node_t::get_property
const prop_data_t & get_property(const std::string &id, const size_t instance=0)
Definition node.ipp:53
uhd::rfnoc::node_t::set_property
void set_property(const std::string &id, const prop_data_t &val, const size_t instance=0)
Definition node.ipp:45
uhd::rfnoc::property_base_t
Definition property.hpp:26
uhd::rfnoc::property_base_t::RO
@ RO
Read-Only.
Definition property.hpp:30
uhd::rfnoc::property_base_t::RW
@ RW
Read-Write.
Definition property.hpp:31
uhd::rfnoc::property_t
Definition property.hpp:151
RFNOC_LOG_TRACE
#define RFNOC_LOG_TRACE(message)
Definition log.hpp:251
uhd::rfnoc
Definition actions.hpp:24
uhd
Definition build_info.hpp:12
uhd::lookup_error
Definition exception.hpp:59
uhd::rfnoc::res_source_info
Definition res_source_info.hpp:18
uhd::rfnoc::res_source_info::USER
@ USER
The user API sources this resource.
Definition res_source_info.hpp:22
uhd::rfnoc::res_source_info::to_string
std::string to_string() const
Returns a string representation of the source.
Definition res_source_info.hpp:55
uhd::type_error
Definition exception.hpp:96