USRP Hardware Driver and USRP Manual  Version: 4.7.0.0-22-g6758966a
UHD and USRP Manual
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>
12 #include <uhd/property_tree.hpp>
14 #include <functional>
15 #include <memory>
16 
17 
18 namespace uhd { namespace experts {
19 
32 {
33 public:
40  static expert_container::sptr create_container(const std::string& name);
41 
56  template <typename data_t>
57  inline static void add_data_node(expert_container::sptr container,
58  const std::string& name,
59  const data_t& init_val,
61  {
62  container->add_data_node(new data_node_t<data_t>(name, init_val), mode);
63  }
64 
91  template <typename data_t>
93  property_tree::sptr subtree,
94  const fs_path& path,
95  const std::string& name,
96  const data_t& init_val,
98  {
99  property<data_t>& prop =
100  subtree->create<data_t>(path, property_tree::AUTO_COERCE);
101  data_node_t<data_t>* node_ptr =
102  new data_node_t<data_t>(name, init_val, &container->resolve_mutex());
103  prop.set(init_val);
105  std::bind(&data_node_t<data_t>::commit, node_ptr, std::placeholders::_1));
106  prop.set_publisher(std::bind(&data_node_t<data_t>::retrieve, node_ptr));
107  container->add_data_node(node_ptr, mode);
108  return prop;
109  }
110 
123  template <typename data_t>
125  property_tree::sptr subtree,
126  const fs_path& path,
127  const data_t& init_val,
129  {
130  return add_prop_node(container, subtree, path, path, init_val, mode);
131  }
132 
151  template <typename data_t>
153  property_tree::sptr subtree,
154  const fs_path& path,
155  const std::string& desired_name,
156  const std::string& coerced_name,
157  const data_t& init_val,
159  {
160  bool auto_resolve_desired =
162  bool auto_resolve_coerced =
164 
165  property<data_t>& prop =
166  subtree->create<data_t>(path, property_tree::MANUAL_COERCE);
167  data_node_t<data_t>* desired_node_ptr =
168  new data_node_t<data_t>(desired_name, init_val, &container->resolve_mutex());
169  data_node_t<data_t>* coerced_node_ptr =
170  new data_node_t<data_t>(coerced_name, init_val, &container->resolve_mutex());
171  prop.set(init_val);
172  prop.set_coerced(init_val);
173  prop.add_desired_subscriber(std::bind(
174  &data_node_t<data_t>::commit, desired_node_ptr, std::placeholders::_1));
175  prop.set_publisher(std::bind(&data_node_t<data_t>::retrieve, coerced_node_ptr));
176 
177  container->add_data_node(desired_node_ptr,
178  auto_resolve_desired ? AUTO_RESOLVE_ON_WRITE : AUTO_RESOLVE_OFF);
179  container->add_data_node(coerced_node_ptr,
180  auto_resolve_coerced ? AUTO_RESOLVE_ON_READ : AUTO_RESOLVE_OFF);
181  return prop;
182  }
183 
197  template <typename data_t>
199  property_tree::sptr subtree,
200  const fs_path& path,
201  const data_t& init_val,
203  {
204  return add_dual_prop_node(container,
205  subtree,
206  path,
207  path + "/desired",
208  path + "/coerced",
209  init_val,
210  mode);
211  }
212 
222  template <typename worker_t>
223  inline static void add_worker_node(expert_container::sptr container)
224  {
225  container->add_worker(new worker_t());
226  }
227 
242  template <typename worker_t, typename... Args>
243  inline static void add_worker_node(
244  expert_container::sptr container, Args const&... args)
245  {
246  container->add_worker(new worker_t(args...));
247  }
248 };
249 }} // namespace uhd::experts
Definition: expert_nodes.hpp:129
std::shared_ptr< expert_container > sptr
Definition: expert_container.hpp:28
Definition: expert_factory.hpp:32
static void add_worker_node(expert_container::sptr container, Args const &... args)
Definition: expert_factory.hpp:243
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:57
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:92
static expert_container::sptr create_container(const std::string &name)
static void add_worker_node(expert_container::sptr container)
Definition: expert_factory.hpp:223
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:152
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:198
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:124
std::shared_ptr< property_tree > sptr
Definition: property_tree.hpp:223
@ AUTO_COERCE
Definition: property_tree.hpp:225
@ MANUAL_COERCE
Definition: property_tree.hpp:225
Definition: property_tree.hpp:79
virtual property< T > & set_publisher(const publisher_type &publisher)=0
virtual property< T > & add_desired_subscriber(const subscriber_type &subscriber)=0
virtual property< T > & add_coerced_subscriber(const subscriber_type &subscriber)=0
virtual property< T > & set_coerced(const T &value)=0
virtual property< T > & set(const T &value)=0
#define UHD_API
Definition: config.h:87
auto_resolve_mode_t
Definition: expert_container.hpp:18
@ AUTO_RESOLVE_ON_WRITE
Definition: expert_container.hpp:21
@ AUTO_RESOLVE_ON_READ
Definition: expert_container.hpp:20
@ AUTO_RESOLVE_OFF
Definition: expert_container.hpp:19
@ AUTO_RESOLVE_ON_READ_WRITE
Definition: expert_container.hpp:22
Definition: build_info.hpp:12
boost::noncopyable noncopyable
Definition: noncopyable.hpp:45
Definition: property_tree.hpp:206