USRP Hardware Driver and USRP Manual  Version: 3.12.0.0-0-unknown
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 
12 #include <uhd/rfnoc/constants.hpp>
13 #include <uhd/utils/log.hpp>
14 #include <stdint.h>
15 #include <boost/shared_ptr.hpp>
16 #include <boost/utility.hpp>
17 #include <boost/enable_shared_from_this.hpp>
18 #include <boost/function.hpp>
19 #include <map>
20 #include <set>
21 
22 namespace uhd {
23  namespace rfnoc {
24 
25 #define UHD_RFNOC_BLOCK_TRACE() UHD_LOGGER_TRACE("RFNOC")
26 
31 class node_ctrl_base : boost::noncopyable, public boost::enable_shared_from_this<node_ctrl_base>
32 {
33 public:
34  /***********************************************************************
35  * Types
36  **********************************************************************/
37  typedef boost::shared_ptr<node_ctrl_base> sptr;
38  typedef boost::weak_ptr<node_ctrl_base> wptr;
39  typedef std::map< size_t, wptr > node_map_t;
40  typedef std::pair< size_t, wptr > node_map_pair_t;
41 
42  /***********************************************************************
43  * Node control
44  **********************************************************************/
46  virtual std::string unique_id() const;
47 
48  /***********************************************************************
49  * Connections
50  **********************************************************************/
53  virtual void clear();
54 
55  node_map_t list_downstream_nodes() { return _downstream_nodes; };
56  node_map_t list_upstream_nodes() { return _upstream_nodes; };
57 
60  void disconnect();
61 
64  void disconnect_output_port(const size_t output_port);
65 
68  void disconnect_input_port(const size_t input_port);
69 
70  // TODO we need a more atomic connect procedure, this is too error-prone.
71 
76  void set_downstream_port(const size_t this_port, const size_t remote_port);
77 
82  size_t get_downstream_port(const size_t this_port);
83 
88  void set_upstream_port(const size_t this_port, const size_t remote_port);
89 
94  size_t get_upstream_port(const size_t this_port);
95 
111  template <typename T>
112  UHD_INLINE std::vector< boost::shared_ptr<T> > find_downstream_node(bool active_only = false)
113  {
114  return _find_child_node<T, true>(active_only);
115  }
116 
119  template <typename T>
120  UHD_INLINE std::vector< boost::shared_ptr<T> > find_upstream_node(bool active_only = false)
121  {
122  return _find_child_node<T, false>(active_only);
123  }
124 
137  template <typename T, typename value_type>
139  boost::function<value_type(boost::shared_ptr<T> node, size_t port)> get_property,
140  value_type null_value,
141  const std::set< boost::shared_ptr<T> > &exclude_nodes=std::set< boost::shared_ptr<T> >()
142  ) {
143  return _find_unique_property<T, value_type, true>(get_property, null_value, exclude_nodes);
144  }
145 
148  template <typename T, typename value_type>
150  boost::function<value_type(boost::shared_ptr<T> node, size_t port)> get_property,
151  value_type null_value,
152  const std::set< boost::shared_ptr<T> > &exclude_nodes=std::set< boost::shared_ptr<T> >()
153  ) {
154  return _find_unique_property<T, value_type, false>(get_property, null_value, exclude_nodes);
155  }
156 
157 protected:
158  /***********************************************************************
159  * Structors
160  **********************************************************************/
161  node_ctrl_base(void) {}
162  virtual ~node_ctrl_base() { disconnect(); }
163 
164  /***********************************************************************
165  * Protected members
166  **********************************************************************/
167 
170 
171  // TODO make these private
172 
174  node_map_t _upstream_nodes;
175 
177  node_map_t _downstream_nodes;
178 
186  std::map<size_t, bool> _rx_streamer_active;
187 
195  std::map<size_t, bool> _tx_streamer_active;
196 
197  /***********************************************************************
198  * Connections
199  **********************************************************************/
206  virtual void _register_downstream_node(
207  node_ctrl_base::sptr downstream_node,
208  size_t port
209  );
210 
217  virtual void _register_upstream_node(
218  node_ctrl_base::sptr upstream_node,
219  size_t port
220  );
221 
222 private:
231  template <typename T, bool downstream>
232  std::vector< boost::shared_ptr<T> > _find_child_node(bool active_only = false);
233 
242  template <typename T, typename value_type, bool downstream>
243  value_type _find_unique_property(
244  boost::function<value_type(boost::shared_ptr<T>, size_t)> get_property,
245  value_type NULL_VALUE,
246  const std::set< boost::shared_ptr<T> > &exclude_nodes
247  );
248 
251  std::map<size_t, size_t> _upstream_ports;
252 
255  std::map<size_t, size_t> _downstream_ports;
256 
257 }; /* class node_ctrl_base */
258 
259 }} /* namespace uhd::rfnoc */
260 
262 
263 #endif /* INCLUDED_LIBUHD_NODE_CTRL_BASE_HPP */
264 // vim: sw=4 et:
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:149
node_map_t list_upstream_nodes()
Definition: node_ctrl_base.hpp:56
UHD_INLINE std::vector< boost::shared_ptr< T > > find_downstream_node(bool active_only=false)
Definition: node_ctrl_base.hpp:112
virtual void _register_upstream_node(node_ctrl_base::sptr upstream_node, size_t port)
std::map< size_t, wptr > node_map_t
Definition: node_ctrl_base.hpp:39
virtual ~node_ctrl_base()
Definition: node_ctrl_base.hpp:162
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:55
UHD_INLINE std::vector< boost::shared_ptr< T > > find_upstream_node(bool active_only=false)
Definition: node_ctrl_base.hpp:120
node_ctrl_base(void)
Definition: node_ctrl_base.hpp:161
std::pair< size_t, wptr > node_map_pair_t
Definition: node_ctrl_base.hpp:40
Definition: build_info.hpp:14
uhd::device_addr_t _args
Stores default arguments.
Definition: node_ctrl_base.hpp:169
void disconnect_input_port(const size_t input_port)
boost::shared_ptr< node_ctrl_base > sptr
Definition: node_ctrl_base.hpp:37
#define UHD_RFNOC_API
Definition: config.hpp:93
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:177
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:186
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:138
std::map< size_t, bool > _tx_streamer_active
Definition: node_ctrl_base.hpp:195
boost::weak_ptr< node_ctrl_base > wptr
Definition: node_ctrl_base.hpp:38
node_map_t _upstream_nodes
List of upstream nodes.
Definition: node_ctrl_base.hpp:174
Definition: device_addr.hpp:38
Definition: node_ctrl_base.hpp:31