USRP Hardware Driver and USRP Manual  Version: 003.010.000.HEAD-0-g6e1ac3fc
UHD and USRP Manual
node_ctrl_base.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2014-2016 Ettus Research LLC
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 //
17 
18 #ifndef INCLUDED_LIBUHD_NODE_CTRL_BASE_HPP
19 #define INCLUDED_LIBUHD_NODE_CTRL_BASE_HPP
20 
22 #include <uhd/rfnoc/constants.hpp>
23 #include <uhd/utils/log.hpp>
24 #include <boost/cstdint.hpp>
25 #include <boost/shared_ptr.hpp>
26 #include <boost/utility.hpp>
27 #include <boost/enable_shared_from_this.hpp>
28 #include <boost/function.hpp>
29 #include <map>
30 #include <set>
31 
32 namespace uhd {
33  namespace rfnoc {
34 
35 #define UHD_RFNOC_BLOCK_TRACE() UHD_LOGV(never) << "[" << unique_id() << "] "
36 
41 class node_ctrl_base : boost::noncopyable, public boost::enable_shared_from_this<node_ctrl_base>
42 {
43 public:
44  /***********************************************************************
45  * Types
46  **********************************************************************/
47  typedef boost::shared_ptr<node_ctrl_base> sptr;
48  typedef boost::weak_ptr<node_ctrl_base> wptr;
49  typedef std::map< size_t, wptr > node_map_t;
50  typedef std::pair< size_t, wptr > node_map_pair_t;
51 
52  /***********************************************************************
53  * Node control
54  **********************************************************************/
56  virtual std::string unique_id() const;
57 
58  /***********************************************************************
59  * Connections
60  **********************************************************************/
63  virtual void clear();
64 
65  node_map_t list_downstream_nodes() { return _downstream_nodes; };
66  node_map_t list_upstream_nodes() { return _upstream_nodes; };
67 
68  // TODO we need a more atomic connect procedure, this is too error-prone.
69 
74  void set_downstream_port(const size_t this_port, const size_t remote_port);
75 
80  size_t get_downstream_port(const size_t this_port);
81 
86  void set_upstream_port(const size_t this_port, const size_t remote_port);
87 
92  size_t get_upstream_port(const size_t this_port);
93 
109  template <typename T>
110  UHD_INLINE std::vector< boost::shared_ptr<T> > find_downstream_node()
111  {
112  return _find_child_node<T, true>();
113  }
114 
117  template <typename T>
118  UHD_INLINE std::vector< boost::shared_ptr<T> > find_upstream_node()
119  {
120  return _find_child_node<T, false>();
121  }
122 
135  template <typename T, typename value_type>
137  boost::function<value_type(boost::shared_ptr<T> node, size_t port)> get_property,
138  value_type null_value,
139  const std::set< boost::shared_ptr<T> > &exclude_nodes=std::set< boost::shared_ptr<T> >()
140  ) {
141  return _find_unique_property<T, value_type, true>(get_property, null_value, exclude_nodes);
142  }
143 
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=std::set< boost::shared_ptr<T> >()
151  ) {
152  return _find_unique_property<T, value_type, false>(get_property, null_value, exclude_nodes);
153  }
154 
155 protected:
156  /***********************************************************************
157  * Structors
158  **********************************************************************/
159  node_ctrl_base(void) {};
160  virtual ~node_ctrl_base() {};
161 
162  /***********************************************************************
163  * Protected members
164  **********************************************************************/
165 
168 
169  // TODO make these private
170 
172  node_map_t _upstream_nodes;
173 
175  node_map_t _downstream_nodes;
176 
177  /***********************************************************************
178  * Connections
179  **********************************************************************/
186  virtual void _register_downstream_node(
187  node_ctrl_base::sptr downstream_node,
188  size_t port
189  );
190 
197  virtual void _register_upstream_node(
198  node_ctrl_base::sptr upstream_node,
199  size_t port
200  );
201 
202 private:
211  template <typename T, bool downstream>
212  std::vector< boost::shared_ptr<T> > _find_child_node();
213 
222  template <typename T, typename value_type, bool downstream>
223  value_type _find_unique_property(
224  boost::function<value_type(boost::shared_ptr<T>, size_t)> get_property,
225  value_type NULL_VALUE,
226  const std::set< boost::shared_ptr<T> > &exclude_nodes
227  );
228 
231  std::map<size_t, size_t> _upstream_ports;
232 
235  std::map<size_t, size_t> _downstream_ports;
236 
237 }; /* class node_ctrl_base */
238 
239 }} /* namespace uhd::rfnoc */
240 
242 
243 #endif /* INCLUDED_LIBUHD_NODE_CTRL_BASE_HPP */
244 // 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:147
node_map_t list_upstream_nodes()
Definition: node_ctrl_base.hpp:66
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:49
virtual ~node_ctrl_base()
Definition: node_ctrl_base.hpp:160
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:65
node_ctrl_base(void)
Definition: node_ctrl_base.hpp:159
std::pair< size_t, wptr > node_map_pair_t
Definition: node_ctrl_base.hpp:50
Definition: build_info.hpp:25
uhd::device_addr_t _args
Stores default arguments.
Definition: node_ctrl_base.hpp:160
boost::shared_ptr< node_ctrl_base > sptr
Definition: node_ctrl_base.hpp:47
#define UHD_RFNOC_API
Definition: config.hpp:103
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:63
node_map_t _downstream_nodes
List of downstream nodes.
Definition: node_ctrl_base.hpp:175
UHD_INLINE std::vector< boost::shared_ptr< T > > find_upstream_node()
Definition: node_ctrl_base.hpp:118
void set_upstream_port(const size_t this_port, const size_t remote_port)
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:136
UHD_INLINE std::vector< boost::shared_ptr< T > > find_downstream_node()
Definition: node_ctrl_base.hpp:110
boost::weak_ptr< node_ctrl_base > wptr
Definition: node_ctrl_base.hpp:48
node_map_t _upstream_nodes
List of upstream nodes.
Definition: node_ctrl_base.hpp:172
Definition: device_addr.hpp:47
Definition: node_ctrl_base.hpp:41