diff options
author | Aaron Rossetto <aaron.rossetto@ni.com> | 2020-07-22 12:51:21 -0500 |
---|---|---|
committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2020-07-24 13:15:30 -0500 |
commit | a5fe0b071d7041f0539804cd16ada27d920bc96d (patch) | |
tree | 840f254f2f2d0165681706f7c539bdc48a52e67f /host/lib/rfnoc/node.cpp | |
parent | 4b01628cad132db68ec1cc8cce211f2df0f62770 (diff) | |
download | uhd-a5fe0b071d7041f0539804cd16ada27d920bc96d.tar.gz uhd-a5fe0b071d7041f0539804cd16ada27d920bc96d.tar.bz2 uhd-a5fe0b071d7041f0539804cd16ada27d920bc96d.zip |
rfnoc: Support instance overrides in set_properties()
This commit adds an enhancement to node_t::set_properties() in which
the instance argument provided to the function (which normally applies
to all properties in the key/value list) can be overridden on a
per-property basis using a special syntax.
If the key consists of the property name followed by a colon (':') and
then a number, the number following the colon is used to determine which
instance of the property this set pertains to, and the value passed via
the instance parameter is ignored for that property. For example, in the
following call:
node->set_properties("dog=10,cat:2=5,bird:0=0.5", 1)
instance 1 of node's 'dog' property is set to 10, the 1 coming from the
instance parameter, instance 2 of the node's 'cat' property is set to 5
due to the override syntax provided in the string, and instance 0 of the
node's 'bird' property is set to 0.5 due to its override.
If the name/instance pair is malformed, e.g. 'value:=10' or
'value:foobar=10', a runtime error is thrown.
Diffstat (limited to 'host/lib/rfnoc/node.cpp')
-rw-r--r-- | host/lib/rfnoc/node.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/host/lib/rfnoc/node.cpp b/host/lib/rfnoc/node.cpp index 0abbb0d3b..062645b93 100644 --- a/host/lib/rfnoc/node.cpp +++ b/host/lib/rfnoc/node.cpp @@ -48,11 +48,28 @@ std::vector<std::string> node_t::get_property_ids() const void node_t::set_properties(const uhd::device_addr_t& props, const size_t instance) { for (const auto& key : props.keys()) { + std::string local_key = key; + size_t local_instance = instance; + const size_t colon_pos = key.find(':'); + if (colon_pos != std::string::npos) { + // Extract the property ID and instance + local_key = key.substr(0, colon_pos); + std::string instance_part = key.substr(colon_pos + 1); + try { + local_instance = std::stoi(instance_part); + } catch (...) { + // If no number, or an invalid number is specified after the + // colon, throw a value_error. + throw uhd::value_error("Property id `" + local_key + + "' contains a malformed instance override!"); + } + } + property_base_t* prop_ref = - _find_property({res_source_info::USER, instance}, key); + _find_property({res_source_info::USER, local_instance}, local_key); if (!prop_ref) { RFNOC_LOG_WARNING("set_properties() cannot set property `" - << key << "': No such property."); + << local_key << "': No such property."); continue; } auto prop_access = _request_property_access(prop_ref, property_base_t::RW); |