Loading...
Searching...
No Matches
expert_factory.hpp
Go to the documentation of this file.
//
// Copyright 2016 Ettus Research
// Copyright 2018 Ettus Research, a National Instruments Company
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
#pragma once
#include <uhd/config.hpp>
#include <uhd/experts/expert_container.hpp>
#include <uhd/experts/expert_nodes.hpp>
#include <uhd/property_tree.hpp>
#include <uhd/utils/noncopyable.hpp>
#include <functional>
#include <memory>
#include <string>
namespace uhd { namespace experts {
class UHD_API expert_factory : public uhd::noncopyable
{
public:
static expert_container::sptr create_container(const std::string& name);
template <typename data_t>
inline 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)
{
container->add_data_node(new data_node_t<data_t>(name, init_val), mode);
}
template <typename data_t>
inline 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)
{
property<data_t>& prop =
subtree->create<data_t>(path, property_tree::AUTO_COERCE);
data_node_t<data_t>* node_ptr =
new data_node_t<data_t>(name, init_val, &container->resolve_mutex());
prop.set(init_val);
prop.add_coerced_subscriber(
std::bind(&data_node_t<data_t>::commit, node_ptr, std::placeholders::_1));
prop.set_publisher(std::bind(&data_node_t<data_t>::retrieve, node_ptr));
container->add_data_node(node_ptr, mode);
return prop;
}
template <typename data_t>
inline 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)
{
return add_prop_node(container, subtree, path, path, init_val, mode);
}
template <typename data_t>
inline 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)
{
bool auto_resolve_desired =
(mode == AUTO_RESOLVE_ON_WRITE or mode == AUTO_RESOLVE_ON_READ_WRITE);
bool auto_resolve_coerced =
(mode == AUTO_RESOLVE_ON_READ or mode == AUTO_RESOLVE_ON_READ_WRITE);
property<data_t>& prop =
subtree->create<data_t>(path, property_tree::MANUAL_COERCE);
data_node_t<data_t>* desired_node_ptr =
new data_node_t<data_t>(desired_name, init_val, &container->resolve_mutex());
data_node_t<data_t>* coerced_node_ptr =
new data_node_t<data_t>(coerced_name, init_val, &container->resolve_mutex());
prop.set(init_val);
prop.set_coerced(init_val);
prop.add_desired_subscriber(std::bind(
&data_node_t<data_t>::commit, desired_node_ptr, std::placeholders::_1));
prop.set_publisher(std::bind(&data_node_t<data_t>::retrieve, coerced_node_ptr));
container->add_data_node(desired_node_ptr,
auto_resolve_desired ? AUTO_RESOLVE_ON_WRITE : AUTO_RESOLVE_OFF);
container->add_data_node(coerced_node_ptr,
auto_resolve_coerced ? AUTO_RESOLVE_ON_READ : AUTO_RESOLVE_OFF);
return prop;
}
template <typename data_t>
inline 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)
{
return add_dual_prop_node(container,
subtree,
path,
path + "/desired",
path + "/coerced",
init_val,
mode);
}
template <typename worker_t>
inline static void add_worker_node(expert_container::sptr container)
{
container->add_worker(new worker_t());
}
template <typename worker_t, typename... Args>
inline static void add_worker_node(
expert_container::sptr container, Args const&... args)
{
container->add_worker(new worker_t(args...));
}
};
}} // namespace uhd::experts
uhd::experts::data_node_t
Definition expert_nodes.hpp:137
uhd::experts::data_node_t::retrieve
data_t retrieve() const
Definition expert_nodes.hpp:226
uhd::experts::data_node_t::commit
void commit(const data_t &value)
Definition expert_nodes.hpp:212
uhd::experts::expert_container::sptr
std::shared_ptr< expert_container > sptr
Definition expert_container.hpp:28
uhd::experts::expert_factory
Definition expert_factory.hpp:34
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::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::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
uhd::experts::expert_factory::create_container
static expert_container::sptr create_container(const std::string &name)
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::experts::expert_factory::add_worker_node
static void add_worker_node(expert_container::sptr container)
Definition expert_factory.hpp:225
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::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::property_tree::sptr
std::shared_ptr< property_tree > sptr
Definition property_tree.hpp:224
uhd::property_tree::AUTO_COERCE
@ AUTO_COERCE
Definition property_tree.hpp:226
uhd::property_tree::MANUAL_COERCE
@ MANUAL_COERCE
Definition property_tree.hpp:226
uhd::property
Definition property_tree.hpp:80
uhd::property::set_coerced
virtual property< T > & set_coerced(const T &value)=0
uhd::property::add_coerced_subscriber
virtual property< T > & add_coerced_subscriber(const subscriber_type &subscriber)=0
uhd::property::add_desired_subscriber
virtual property< T > & add_desired_subscriber(const subscriber_type &subscriber)=0
uhd::property::set_publisher
virtual property< T > & set_publisher(const publisher_type &publisher)=0
uhd::property::set
virtual property< T > & set(const T &value)=0
UHD_API
#define UHD_API
Definition config.h:87
config.hpp
expert_container.hpp
expert_nodes.hpp
uhd::experts
Definition expert_container.hpp:16
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::experts::AUTO_RESOLVE_ON_READ
@ AUTO_RESOLVE_ON_READ
Definition expert_container.hpp:20
uhd::experts::AUTO_RESOLVE_OFF
@ AUTO_RESOLVE_OFF
Definition expert_container.hpp:19
uhd::experts::AUTO_RESOLVE_ON_READ_WRITE
@ AUTO_RESOLVE_ON_READ_WRITE
Definition expert_container.hpp:22
uhd
Definition build_info.hpp:12
uhd::noncopyable
boost::noncopyable noncopyable
Definition noncopyable.hpp:45
noncopyable.hpp
property_tree.hpp
uhd::fs_path
Definition property_tree.hpp:207