USRP Hardware Driver and USRP Manual Version: 4.4.0.0
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
12namespace {
13
14template <typename prop_data_t>
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) {
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 =
28 dynamic_cast<uhd::rfnoc::property_t<prop_data_t>*>(prop_base_ptr);
29 if (!prop_ptr) {
30 throw uhd::type_error(str(
31 boost::format(
32 "[%s] Found property `%s', but could not cast to requested type `%s'!")
33 % node_id % prop_id % 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
42namespace uhd { namespace rfnoc {
43
44template <typename prop_data_t>
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
52template <typename prop_data_t>
53const 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
59template <typename prop_data_t>
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 }
68 else {
69 // Node unconnected to graph
70 _set_property(id, val, src_info);
71 }
72}
73
74template <typename prop_data_t>
75const prop_data_t& node_t::get_property(
76 const std::string& id, const res_source_info& src_info)
77{
78 RFNOC_LOG_TRACE("Getting property " << id << "@" << src_info.to_string());
79 // First, trigger a property resolution to make sure this property is
80 // updated (if necessary) before reading it out
81 resolve_all();
82 auto prop_ptr = _assert_prop<prop_data_t>(
83 _find_property(src_info, id), get_unique_id(), id);
84
85 auto prop_access = _request_property_access(prop_ptr, property_base_t::RO);
86 return prop_ptr->get();
87}
88
89template <typename prop_data_t>
90void node_t::_set_property(
91 const std::string& id, const prop_data_t& val, const res_source_info& src_info)
92{
93 RFNOC_LOG_TRACE("Setting property " << id << "@" << src_info.to_string());
94
95 auto prop_ptr =
96 _assert_prop<prop_data_t>(_find_property(src_info, id), get_unique_id(), id);
97 {
98 auto prop_access = _request_property_access(prop_ptr, property_base_t::RW);
99 prop_ptr->set(val);
100 }
101
102 // Now trigger a property resolution. If other properties depend on this one,
103 // they will be updated.
104 resolve_all();
105}
106
107}} /* namespace uhd::rfnoc */
108
virtual std::string get_unique_id() const
Return a unique identifier string for this node. In every RFNoC graph,.
const prop_data_t & get_property(const std::string &id, const size_t instance=0)
Definition node.ipp:53
void set_property(const std::string &id, const prop_data_t &val, const size_t instance=0)
Definition node.ipp:45
Definition property.hpp:26
@ RO
Read-Only.
Definition property.hpp:30
@ RW
Read-Write.
Definition property.hpp:31
Definition property.hpp:151
#define RFNOC_LOG_TRACE(message)
Definition log.hpp:251
Definition build_info.hpp:12
Definition exception.hpp:59
Definition res_source_info.hpp:18
@ USER
The user API sources this resource.
Definition res_source_info.hpp:22
std::string to_string() const
Returns a string representation of the source.
Definition res_source_info.hpp:55
Definition exception.hpp:96