Loading [MathJax]/extensions/tex2jax.js
USRP Hardware Driver and USRP Manual  Version: 4.8.0.0
UHD and USRP Manual
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
expert_factory.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2016 Ettus Research
3 // Copyright 2018 Ettus Research, a National Instruments Company
4 //
5 // SPDX-License-Identifier: GPL-3.0-or-later
6 //
7 
8 #pragma once
9 
10 #include <uhd/config.hpp>
13 #include <uhd/property_tree.hpp>
15 #include <functional>
16 #include <memory>
17 #include <string>
18 
19 
20 namespace uhd { namespace experts {
21 
34 {
35 public:
42  static expert_container::sptr create_container(const std::string& name);
43 
58  template <typename data_t>
59  inline static void add_data_node(expert_container::sptr container,
60  const std::string& name,
61  const data_t& init_val,
63  {
64  container->add_data_node(new data_node_t<data_t>(name, init_val), mode);
65  }
66 
93  template <typename data_t>
95  property_tree::sptr subtree,
96  const fs_path& path,
97  const std::string& name,
98  const data_t& init_val,
100  {
101  property<data_t>& prop =
102  subtree->create<data_t>(path, property_tree::AUTO_COERCE);
103  data_node_t<data_t>* node_ptr =
104  new data_node_t<data_t>(name, init_val, &container->resolve_mutex());
105  prop.set(init_val);
107  std::bind(&data_node_t<data_t>::commit, node_ptr, std::placeholders::_1));
108  prop.set_publisher(std::bind(&data_node_t<data_t>::retrieve, node_ptr));
109  container->add_data_node(node_ptr, mode);
110  return prop;
111  }
112 
125  template <typename data_t>
127  property_tree::sptr subtree,
128  const fs_path& path,
129  const data_t& init_val,
131  {
132  return add_prop_node(container, subtree, path, path, init_val, mode);
133  }
134 
153  template <typename data_t>
155  property_tree::sptr subtree,
156  const fs_path& path,
157  const std::string& desired_name,
158  const std::string& coerced_name,
159  const data_t& init_val,
161  {
162  bool auto_resolve_desired =
164  bool auto_resolve_coerced =
166 
167  property<data_t>& prop =
168  subtree->create<data_t>(path, property_tree::MANUAL_COERCE);
169  data_node_t<data_t>* desired_node_ptr =
170  new data_node_t<data_t>(desired_name, init_val, &container->resolve_mutex());
171  data_node_t<data_t>* coerced_node_ptr =
172  new data_node_t<data_t>(coerced_name, init_val, &container->resolve_mutex());
173  prop.set(init_val);
174  prop.set_coerced(init_val);
175  prop.add_desired_subscriber(std::bind(
176  &data_node_t<data_t>::commit, desired_node_ptr, std::placeholders::_1));
177  prop.set_publisher(std::bind(&data_node_t<data_t>::retrieve, coerced_node_ptr));
178 
179  container->add_data_node(desired_node_ptr,
180  auto_resolve_desired ? AUTO_RESOLVE_ON_WRITE : AUTO_RESOLVE_OFF);
181  container->add_data_node(coerced_node_ptr,
182  auto_resolve_coerced ? AUTO_RESOLVE_ON_READ : AUTO_RESOLVE_OFF);
183  return prop;
184  }
185 
199  template <typename data_t>
201  property_tree::sptr subtree,
202  const fs_path& path,
203  const data_t& init_val,
205  {
206  return add_dual_prop_node(container,
207  subtree,
208  path,
209  path + "/desired",
210  path + "/coerced",
211  init_val,
212  mode);
213  }
214 
224  template <typename worker_t>
225  inline static void add_worker_node(expert_container::sptr container)
226  {
227  container->add_worker(new worker_t());
228  }
229 
244  template <typename worker_t, typename... Args>
245  inline static void add_worker_node(
246  expert_container::sptr container, Args const&... args)
247  {
248  container->add_worker(new worker_t(args...));
249  }
250 };
251 }} // namespace uhd::experts
uhd::experts::expert_factory
Definition: expert_factory.hpp:33
uhd::property::add_desired_subscriber
virtual property< T > & add_desired_subscriber(const subscriber_type &subscriber)=0
uhd::experts::expert_factory::add_dual_prop_node
static property< data_t > & add_dual_prop_node(expert_container::sptr container, property_tree::sptr subtree, const fs_path &path, const std::string &desired_name, const std::string &coerced_name, const data_t &init_val, const auto_resolve_mode_t mode=AUTO_RESOLVE_OFF)
Definition: expert_factory.hpp:154
expert_nodes.hpp
config.hpp
uhd::experts::expert_container::sptr
std::shared_ptr< expert_container > sptr
Definition: expert_container.hpp:28
uhd::property::add_coerced_subscriber
virtual property< T > & add_coerced_subscriber(const subscriber_type &subscriber)=0
property_tree.hpp
uhd::experts::expert_factory::add_prop_node
static property< data_t > & add_prop_node(expert_container::sptr container, property_tree::sptr subtree, const fs_path &path, const data_t &init_val, const auto_resolve_mode_t mode=AUTO_RESOLVE_OFF)
Definition: expert_factory.hpp:126
uhd::property::set_publisher
virtual property< T > & set_publisher(const publisher_type &publisher)=0
uhd::experts::expert_factory::add_data_node
static void add_data_node(expert_container::sptr container, const std::string &name, const data_t &init_val, const auto_resolve_mode_t mode=AUTO_RESOLVE_OFF)
Definition: expert_factory.hpp:59
uhd::experts::AUTO_RESOLVE_OFF
@ AUTO_RESOLVE_OFF
Definition: expert_container.hpp:19
UHD_API
#define UHD_API
Definition: config.h:87
uhd::property_tree::sptr
std::shared_ptr< property_tree > sptr
Definition: property_tree.hpp:224
noncopyable.hpp
uhd::experts::AUTO_RESOLVE_ON_READ
@ AUTO_RESOLVE_ON_READ
Definition: expert_container.hpp:20
expert_container.hpp
uhd::experts::expert_factory::add_prop_node
static property< data_t > & add_prop_node(expert_container::sptr container, property_tree::sptr subtree, const fs_path &path, const std::string &name, const data_t &init_val, const auto_resolve_mode_t mode=AUTO_RESOLVE_OFF)
Definition: expert_factory.hpp:94
uhd::property::set
virtual property< T > & set(const T &value)=0
uhd
Definition: build_info.hpp:12
uhd::experts::expert_factory::add_worker_node
static void add_worker_node(expert_container::sptr container, Args const &... args)
Definition: expert_factory.hpp:245
uhd::experts::data_node_t
Definition: expert_nodes.hpp:128
uhd::fs_path
Definition: property_tree.hpp:206
uhd::property
Definition: property_tree.hpp:79
uhd::experts::expert_factory::add_worker_node
static void add_worker_node(expert_container::sptr container)
Definition: expert_factory.hpp:225
uhd::experts::auto_resolve_mode_t
auto_resolve_mode_t
Definition: expert_container.hpp:18
uhd::experts::AUTO_RESOLVE_ON_WRITE
@ AUTO_RESOLVE_ON_WRITE
Definition: expert_container.hpp:21
uhd::property::set_coerced
virtual property< T > & set_coerced(const T &value)=0
uhd::property_tree::AUTO_COERCE
@ AUTO_COERCE
Definition: property_tree.hpp:226
uhd::noncopyable
boost::noncopyable noncopyable
Definition: noncopyable.hpp:45
uhd::experts::expert_factory::add_dual_prop_node
static property< data_t > & add_dual_prop_node(expert_container::sptr container, property_tree::sptr subtree, const fs_path &path, const data_t &init_val, const auto_resolve_mode_t mode=AUTO_RESOLVE_OFF)
Definition: expert_factory.hpp:200
uhd::experts::AUTO_RESOLVE_ON_READ_WRITE
@ AUTO_RESOLVE_ON_READ_WRITE
Definition: expert_container.hpp:22
uhd::property_tree::MANUAL_COERCE
@ MANUAL_COERCE
Definition: property_tree.hpp:226