USRP Hardware Driver and USRP Manual  Version: 4.4.0.HEAD-0-g5fac246b
UHD and USRP Manual
res_source_info.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2019 Ettus Research, a National Instruments Brand
3 //
4 // SPDX-License-Identifier: GPL-3.0-or-later
5 //
6 
7 #pragma once
8 
9 #include <uhd/exception.hpp>
10 #include <cstdint>
11 #include <string>
12 
13 namespace uhd { namespace rfnoc {
14 
18 {
21  enum source_t {
22  USER,
26  };
27 
28  // No default ctor: The source type must be specified
29  res_source_info() = delete;
30 
31  res_source_info(source_t source_type, size_t instance_ = 0)
32  : type(source_type), instance(instance_)
33  {
34  // nop
35  }
36 
39 
41  // corresponds to the port number
42  size_t instance = 0;
43 
44  bool operator==(const res_source_info& rhs) const
45  {
46  return rhs.type == type && rhs.instance == instance;
47  }
48 
49  bool operator!=(const res_source_info& rhs) const
50  {
51  return !(*this == rhs);
52  }
53 
55  std::string to_string() const
56  {
57  const std::string type_repr =
58  type == USER
59  ? "USER"
60  : type == INPUT_EDGE ? "INPUT_EDGE"
61  : type == OUTPUT_EDGE ? "OUTPUT_EDGE" : "INVALID";
62  return type_repr + ":" + std::to_string(instance);
63  }
64 
73  static source_t invert_edge(const source_t edge_direction)
74  {
75  UHD_ASSERT_THROW(edge_direction == INPUT_EDGE || edge_direction == OUTPUT_EDGE);
76  return edge_direction == INPUT_EDGE ? OUTPUT_EDGE : INPUT_EDGE;
77  }
78 };
79 
80 }} /* namespace uhd::rfnoc */
81 
82 namespace std {
83 template <>
84 struct hash<uhd::rfnoc::res_source_info>
85 {
86  size_t operator()(const uhd::rfnoc::res_source_info& src_info) const
87  {
88  const size_t hash_type = std::hash<size_t>{}(src_info.type);
89  const size_t hash_inst = std::hash<size_t>{}(src_info.instance);
90  return hash_type ^ (hash_inst << 1);
91  }
92 };
93 } // namespace std
uhd::rfnoc::res_source_info::OUTPUT_EDGE
@ OUTPUT_EDGE
An input edge sources this resource.
Definition: res_source_info.hpp:24
uhd::rfnoc::res_source_info
Definition: res_source_info.hpp:17
UHD_ASSERT_THROW
#define UHD_ASSERT_THROW(code)
Definition: exception.hpp:321
uhd::rfnoc::res_source_info::invert_edge
static source_t invert_edge(const source_t edge_direction)
Definition: res_source_info.hpp:73
uhd::rfnoc::res_source_info::FRAMEWORK
@ FRAMEWORK
This is a special resource, only accessed by the framework.
Definition: res_source_info.hpp:25
uhd::rfnoc::res_source_info::to_string
std::string to_string() const
Returns a string representation of the source.
Definition: res_source_info.hpp:55
uhd::rfnoc::res_source_info::INPUT_EDGE
@ INPUT_EDGE
An input edge sources this resource.
Definition: res_source_info.hpp:23
uhd::rfnoc::res_source_info::source_t
source_t
Definition: res_source_info.hpp:21
std::hash< uhd::rfnoc::res_source_info >::operator()
size_t operator()(const uhd::rfnoc::res_source_info &src_info) const
Definition: res_source_info.hpp:86
uhd::rfnoc::res_source_info::res_source_info
res_source_info(source_t source_type, size_t instance_=0)
Definition: res_source_info.hpp:31
uhd
Definition: build_info.hpp:12
uhd::rfnoc::res_source_info::USER
@ USER
The user API sources this resource.
Definition: res_source_info.hpp:22
uhd::rfnoc::res_source_info::type
source_t type
The type of source (user or edge)
Definition: res_source_info.hpp:38
exception.hpp
uhd::rfnoc::res_source_info::operator!=
bool operator!=(const res_source_info &rhs) const
Definition: res_source_info.hpp:49
uhd::rfnoc::res_source_info::operator==
bool operator==(const res_source_info &rhs) const
Definition: res_source_info.hpp:44
uhd::rfnoc::res_source_info::res_source_info
res_source_info()=delete
uhd::rfnoc::res_source_info::instance
size_t instance
The instance of the source. For resource that is sourced by a edge, it.
Definition: res_source_info.hpp:42