USRP Hardware Driver and USRP Manual  Version: 3.11.0.HEAD-0-gdca39145
UHD and USRP Manual
device3.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2014-2016 Ettus Research LLC
3 //
4 // SPDX-License-Identifier: GPL-3.0
5 //
6 
7 #ifndef INCLUDED_UHD_DEVICE3_HPP
8 #define INCLUDED_UHD_DEVICE3_HPP
9 
10 #include <uhd/device.hpp>
11 #include <uhd/rfnoc/graph.hpp>
12 #include <uhd/rfnoc/block_ctrl_base.hpp>
13 #include <boost/units/detail/utility.hpp>
14 #include <boost/thread/mutex.hpp>
15 #include <vector>
16 
17 namespace uhd {
18 
26 class UHD_API device3 : public uhd::device {
27 
28  public:
29  typedef boost::shared_ptr<device3> sptr;
30 
32  static sptr make(const device_addr_t &hint, const size_t which = 0);
33 
34  virtual rfnoc::graph::sptr create_graph(const std::string &name="") = 0;
35 
40  void clear();
41 
48  bool has_block(const rfnoc::block_id_t &block_id) const;
49 
55  template <typename T>
56  bool has_block(const rfnoc::block_id_t &block_id) const
57  {
58  if (has_block(block_id)) {
59  return bool(boost::dynamic_pointer_cast<T>(get_block_ctrl(block_id)));
60  } else {
61  return false;
62  }
63  }
64 
73  rfnoc::block_ctrl_base::sptr get_block_ctrl(const rfnoc::block_id_t &block_id) const;
74 
89  template <typename T>
90  boost::shared_ptr<T> get_block_ctrl(const rfnoc::block_id_t &block_id) const
91  {
92  boost::shared_ptr<T> blk = boost::dynamic_pointer_cast<T>(get_block_ctrl(block_id));
93  if (blk) {
94  return blk;
95  } else {
96  throw uhd::lookup_error(str(boost::format("This device does not have a block of type %s with ID: %s")
97  % boost::units::detail::demangle(typeid(T).name())
98  % block_id.to_string()));
99  }
100  }
101 
114  std::vector<rfnoc::block_id_t> find_blocks(const std::string &block_id_hint) const;
115 
118  template <typename T>
119  std::vector<rfnoc::block_id_t> find_blocks(const std::string &block_id_hint) const
120  {
121  std::vector<rfnoc::block_id_t> all_block_ids = find_blocks(block_id_hint);
122  std::vector<rfnoc::block_id_t> filt_block_ids;
123  for (size_t i = 0; i < all_block_ids.size(); i++) {
124  if (has_block<T>(all_block_ids[i])) {
125  filt_block_ids.push_back(all_block_ids[i]);
126  }
127  }
128  return filt_block_ids;
129  }
130 
131  protected:
133  // It is the responsibility of the deriving class to make
134  // sure this gets correctly populated.
135  std::vector< rfnoc::block_ctrl_base::sptr > _rfnoc_block_ctrl;
137  boost::mutex _block_ctrl_mutex;
138 };
139 
140 } //namespace uhd
141 
142 #endif /* INCLUDED_UHD_DEVICE3_HPP */
143 // vim: sw=4 et:
Definition: exception.hpp:48
std::vector< rfnoc::block_id_t > find_blocks(const std::string &block_id_hint) const
Definition: device3.hpp:119
Extends uhd::device for third-generation USRP devices.
Definition: device3.hpp:26
Definition: build_info.hpp:14
boost::mutex _block_ctrl_mutex
Mutex to protect access to members.
Definition: device3.hpp:137
std::vector< rfnoc::block_ctrl_base::sptr > _rfnoc_block_ctrl
List of all RFNoC blocks available on this device.
Definition: device3.hpp:135
#define UHD_API
Definition: config.h:62
bool has_block(const rfnoc::block_id_t &block_id) const
Definition: device3.hpp:56
boost::shared_ptr< T > get_block_ctrl(const rfnoc::block_id_t &block_id) const
Definition: device3.hpp:90
Definition: device.hpp:27
boost::shared_ptr< device3 > sptr
Definition: device3.hpp:29
Definition: device_addr.hpp:36