USRP Hardware Driver and USRP Manual Version: 4.6.0.0
UHD and USRP Manual
 
Loading...
Searching...
No Matches
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
18namespace uhd { namespace experts {
19
32{
33public:
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,
60 const auto_resolve_mode_t mode = AUTO_RESOLVE_OFF)
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,
97 const auto_resolve_mode_t mode = AUTO_RESOLVE_OFF)
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,
128 const auto_resolve_mode_t mode = AUTO_RESOLVE_OFF)
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,
158 const auto_resolve_mode_t mode = AUTO_RESOLVE_OFF)
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,
202 const auto_resolve_mode_t mode = AUTO_RESOLVE_OFF)
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 arg1_t>
243 inline static void add_worker_node(
244 expert_container::sptr container, arg1_t const& arg1)
245 {
246 container->add_worker(new worker_t(arg1));
247 }
248
249 template <typename worker_t, typename arg1_t, typename arg2_t>
250 inline static void add_worker_node(
251 expert_container::sptr container, arg1_t const& arg1, arg2_t const& arg2)
252 {
253 container->add_worker(new worker_t(arg1, arg2));
254 }
255
256 template <typename worker_t, typename arg1_t, typename arg2_t, typename arg3_t>
257 inline static void add_worker_node(expert_container::sptr container,
258 arg1_t const& arg1,
259 arg2_t const& arg2,
260 arg3_t const& arg3)
261 {
262 container->add_worker(new worker_t(arg1, arg2, arg3));
263 }
264
265 template <typename worker_t,
266 typename arg1_t,
267 typename arg2_t,
268 typename arg3_t,
269 typename arg4_t>
270 inline static void add_worker_node(expert_container::sptr container,
271 arg1_t const& arg1,
272 arg2_t const& arg2,
273 arg3_t const& arg3,
274 arg4_t const& arg4)
275 {
276 container->add_worker(new worker_t(arg1, arg2, arg3, arg4));
277 }
278
279 template <typename worker_t,
280 typename arg1_t,
281 typename arg2_t,
282 typename arg3_t,
283 typename arg4_t,
284 typename arg5_t>
285 inline static void add_worker_node(expert_container::sptr container,
286 arg1_t const& arg1,
287 arg2_t const& arg2,
288 arg3_t const& arg3,
289 arg4_t const& arg4,
290 arg5_t const& arg5)
291 {
292 container->add_worker(new worker_t(arg1, arg2, arg3, arg4, arg5));
293 }
294
295 template <typename worker_t,
296 typename arg1_t,
297 typename arg2_t,
298 typename arg3_t,
299 typename arg4_t,
300 typename arg5_t,
301 typename arg6_t>
302 inline static void add_worker_node(expert_container::sptr container,
303 arg1_t const& arg1,
304 arg2_t const& arg2,
305 arg3_t const& arg3,
306 arg4_t const& arg4,
307 arg5_t const& arg5,
308 arg6_t const& arg6)
309 {
310 container->add_worker(new worker_t(arg1, arg2, arg3, arg4, arg5, arg6));
311 }
312
313 template <typename worker_t,
314 typename arg1_t,
315 typename arg2_t,
316 typename arg3_t,
317 typename arg4_t,
318 typename arg5_t,
319 typename arg6_t,
320 typename arg7_t>
321 inline static void add_worker_node(expert_container::sptr container,
322 arg1_t const& arg1,
323 arg2_t const& arg2,
324 arg3_t const& arg3,
325 arg4_t const& arg4,
326 arg5_t const& arg5,
327 arg6_t const& arg6,
328 arg7_t const& arg7)
329 {
330 container->add_worker(new worker_t(arg1, arg2, arg3, arg4, arg5, arg6, arg7));
331 }
332
333 template <typename worker_t,
334 typename arg1_t,
335 typename arg2_t,
336 typename arg3_t,
337 typename arg4_t,
338 typename arg5_t,
339 typename arg6_t,
340 typename arg7_t,
341 typename arg8_t>
342 inline static void add_worker_node(expert_container::sptr container,
343 arg1_t const& arg1,
344 arg2_t const& arg2,
345 arg3_t const& arg3,
346 arg4_t const& arg4,
347 arg5_t const& arg5,
348 arg6_t const& arg6,
349 arg7_t const& arg7,
350 arg7_t const& arg8)
351 {
352 container->add_worker(
353 new worker_t(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8));
354 }
355};
356}} // 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_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 void add_worker_node(expert_container::sptr container, arg1_t const &arg1)
Definition expert_factory.hpp:243
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 expert_container::sptr create_container(const std::string &name)
static void add_worker_node(expert_container::sptr container, arg1_t const &arg1, arg2_t const &arg2, arg3_t const &arg3, arg4_t const &arg4, arg5_t const &arg5, arg6_t const &arg6, arg7_t const &arg7, arg7_t const &arg8)
Definition expert_factory.hpp:342
static void add_worker_node(expert_container::sptr container, arg1_t const &arg1, arg2_t const &arg2, arg3_t const &arg3)
Definition expert_factory.hpp:257
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 void add_worker_node(expert_container::sptr container, arg1_t const &arg1, arg2_t const &arg2, arg3_t const &arg3, arg4_t const &arg4)
Definition expert_factory.hpp:270
static void add_worker_node(expert_container::sptr container, arg1_t const &arg1, arg2_t const &arg2, arg3_t const &arg3, arg4_t const &arg4, arg5_t const &arg5, arg6_t const &arg6)
Definition expert_factory.hpp:302
static void add_worker_node(expert_container::sptr container)
Definition expert_factory.hpp:223
static void add_worker_node(expert_container::sptr container, arg1_t const &arg1, arg2_t const &arg2, arg3_t const &arg3, arg4_t const &arg4, arg5_t const &arg5, arg6_t const &arg6, arg7_t const &arg7)
Definition expert_factory.hpp:321
static void add_worker_node(expert_container::sptr container, arg1_t const &arg1, arg2_t const &arg2)
Definition expert_factory.hpp:250
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
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 void add_worker_node(expert_container::sptr container, arg1_t const &arg1, arg2_t const &arg2, arg3_t const &arg3, arg4_t const &arg4, arg5_t const &arg5)
Definition expert_factory.hpp:285
std::shared_ptr< property_tree > sptr
Definition property_tree.hpp:223
Definition property_tree.hpp:79
virtual property< T > & set_coerced(const T &value)=0
virtual property< T > & add_coerced_subscriber(const subscriber_type &subscriber)=0
virtual property< T > & add_desired_subscriber(const subscriber_type &subscriber)=0
virtual property< T > & set_publisher(const publisher_type &publisher)=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