USRP Hardware Driver and USRP Manual  Version: 3.15.0.HEAD-0-g6563c537
UHD and USRP Manual
node_ctrl_base.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2014-2016 Ettus Research LLC
3 // Copyright 2018 Ettus Research, a National Instruments Company
4 //
5 // SPDX-License-Identifier: GPL-3.0-or-later
6 //
7 
8 #ifndef INCLUDED_LIBUHD_NODE_CTRL_BASE_HPP
9 #define INCLUDED_LIBUHD_NODE_CTRL_BASE_HPP
10 
11 #include <uhd/rfnoc/constants.hpp>
13 #include <uhd/utils/log.hpp>
15 #include <stdint.h>
16 #include <boost/enable_shared_from_this.hpp>
17 #include <boost/function.hpp>
18 #include <boost/shared_ptr.hpp>
19 #include <boost/utility.hpp>
20 #include <map>
21 #include <set>
22 
23 namespace uhd { namespace rfnoc {
24 
25 #define UHD_RFNOC_BLOCK_TRACE() UHD_LOGGER_TRACE("RFNOC")
26 
32  public boost::enable_shared_from_this<node_ctrl_base>
33 {
34 public:
35  /***********************************************************************
36  * Types
37  **********************************************************************/
38  typedef boost::shared_ptr<node_ctrl_base> sptr;
39  typedef boost::weak_ptr<node_ctrl_base> wptr;
40  typedef std::map<size_t, wptr> node_map_t;
41  typedef std::pair<size_t, wptr> node_map_pair_t;
42 
43  /***********************************************************************
44  * Node control
45  **********************************************************************/
47  virtual std::string unique_id() const;
48 
49  /***********************************************************************
50  * Connections
51  **********************************************************************/
54  virtual void clear();
55 
56  node_map_t list_downstream_nodes()
57  {
58  return _downstream_nodes;
59  };
60  node_map_t list_upstream_nodes()
61  {
62  return _upstream_nodes;
63  };
64 
67  void disconnect();
68 
71  void disconnect_output_port(const size_t output_port);
72 
75  void disconnect_input_port(const size_t input_port);
76 
77  // TODO we need a more atomic connect procedure, this is too error-prone.
78 
83  void set_downstream_port(const size_t this_port, const size_t remote_port);
84 
89  size_t get_downstream_port(const size_t this_port);
90 
95  void set_upstream_port(const size_t this_port, const size_t remote_port);
96 
101  size_t get_upstream_port(const size_t this_port);
102 
118  template <typename T>
119  UHD_INLINE std::vector<boost::shared_ptr<T> > find_downstream_node(
120  bool active_only = false)
121  {
122  return _find_child_node<T, true>(active_only);
123  }
124 
127  template <typename T>
128  UHD_INLINE std::vector<boost::shared_ptr<T> > find_upstream_node(
129  bool active_only = false)
130  {
131  return _find_child_node<T, false>(active_only);
132  }
133 
146  template <typename T, typename value_type>
148  boost::function<value_type(boost::shared_ptr<T> node, size_t port)> get_property,
149  value_type null_value,
150  const std::set<boost::shared_ptr<T> >& exclude_nodes =
151  std::set<boost::shared_ptr<T> >())
152  {
153  return _find_unique_property<T, value_type, true>(
154  get_property, null_value, exclude_nodes);
155  }
156 
159  template <typename T, typename value_type>
161  boost::function<value_type(boost::shared_ptr<T> node, size_t port)> get_property,
162  value_type null_value,
163  const std::set<boost::shared_ptr<T> >& exclude_nodes =
164  std::set<boost::shared_ptr<T> >())
165  {
166  return _find_unique_property<T, value_type, false>(
167  get_property, null_value, exclude_nodes);
168  }
169 
170 protected:
171  /***********************************************************************
172  * Structors
173  **********************************************************************/
175  virtual ~node_ctrl_base()
176  {
177  disconnect();
178  }
179 
180  /***********************************************************************
181  * Protected members
182  **********************************************************************/
183 
186 
187  // TODO make these private
188 
190  node_map_t _upstream_nodes;
191 
193  node_map_t _downstream_nodes;
194 
198 
202 
210  std::map<size_t, bool> _rx_streamer_active;
211 
219  std::map<size_t, bool> _tx_streamer_active;
220 
221  /***********************************************************************
222  * Connections
223  **********************************************************************/
230  virtual void _register_downstream_node(
231  node_ctrl_base::sptr downstream_node, size_t port);
232 
239  virtual void _register_upstream_node(node_ctrl_base::sptr upstream_node, size_t port);
240 
241 private:
250  template <typename T, bool downstream>
251  std::vector<boost::shared_ptr<T> > _find_child_node(bool active_only = false);
252 
261  template <typename T, typename value_type, bool downstream>
262  value_type _find_unique_property(
263  boost::function<value_type(boost::shared_ptr<T>, size_t)> get_property,
264  value_type NULL_VALUE,
265  const std::set<boost::shared_ptr<T> >& exclude_nodes);
266 
269  std::map<size_t, size_t> _upstream_ports;
270 
273  std::map<size_t, size_t> _downstream_ports;
274 
275 }; /* class node_ctrl_base */
276 
277 }} /* namespace uhd::rfnoc */
278 
280 
281 #endif /* INCLUDED_LIBUHD_NODE_CTRL_BASE_HPP */
UHD_INLINE value_type find_upstream_unique_property(boost::function< value_type(boost::shared_ptr< T > node, size_t port)> get_property, value_type null_value, const std::set< boost::shared_ptr< T > > &exclude_nodes=std::set< boost::shared_ptr< T > >())
Definition: node_ctrl_base.hpp:160
node_map_t list_upstream_nodes()
Definition: node_ctrl_base.hpp:60
boost::noncopyable noncopyable
Definition: noncopyable.hpp:46
std::pair< size_t, wptr > node_map_pair_t
Definition: node_ctrl_base.hpp:41
virtual void _register_upstream_node(node_ctrl_base::sptr upstream_node, size_t port)
virtual ~node_ctrl_base()
Definition: node_ctrl_base.hpp:175
void set_downstream_port(const size_t this_port, const size_t remote_port)
virtual void _register_downstream_node(node_ctrl_base::sptr downstream_node, size_t port)
node_map_t list_downstream_nodes()
Definition: node_ctrl_base.hpp:56
std::map< size_t, wptr > node_map_t
Definition: node_ctrl_base.hpp:40
node_ctrl_base(void)
Definition: node_ctrl_base.hpp:174
Definition: build_info.hpp:13
uhd::device_addr_t _args
Stores default arguments.
Definition: node_ctrl_base.hpp:185
UHD_INLINE std::vector< boost::shared_ptr< T > > find_upstream_node(bool active_only=false)
Definition: node_ctrl_base.hpp:128
void disconnect_input_port(const size_t input_port)
boost::shared_ptr< node_ctrl_base > sptr
Definition: node_ctrl_base.hpp:38
#define UHD_RFNOC_API
Definition: config.hpp:104
size_t get_downstream_port(const size_t this_port)
size_t get_upstream_port(const size_t this_port)
#define UHD_INLINE
Definition: config.h:53
node_map_t _downstream_nodes
List of downstream nodes.
Definition: node_ctrl_base.hpp:193
size_t _num_input_ports
Definition: node_ctrl_base.hpp:197
void set_upstream_port(const size_t this_port, const size_t remote_port)
void disconnect_output_port(const size_t output_port)
std::map< size_t, bool > _rx_streamer_active
Definition: node_ctrl_base.hpp:210
virtual std::string unique_id() const
Returns a unique string that identifies this block.
UHD_INLINE value_type find_downstream_unique_property(boost::function< value_type(boost::shared_ptr< T > node, size_t port)> get_property, value_type null_value, const std::set< boost::shared_ptr< T > > &exclude_nodes=std::set< boost::shared_ptr< T > >())
Definition: node_ctrl_base.hpp:147
std::map< size_t, bool > _tx_streamer_active
Definition: node_ctrl_base.hpp:219
boost::weak_ptr< node_ctrl_base > wptr
Definition: node_ctrl_base.hpp:39
node_map_t _upstream_nodes
List of upstream nodes.
Definition: node_ctrl_base.hpp:190
size_t _num_output_ports
Definition: node_ctrl_base.hpp:201
Definition: device_addr.hpp:38
UHD_INLINE std::vector< boost::shared_ptr< T > > find_downstream_node(bool active_only=false)
Definition: node_ctrl_base.hpp:119
Definition: node_ctrl_base.hpp:31