GNU Radio Manual and C++ API Reference  3.10.7.0
The Free & Open Software Radio Ecosystem
io_signature.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2004,2007 Free Software Foundation, Inc.
4  * Copyright 2023 Marcus Müller
5  *
6  * This file is part of GNU Radio
7  *
8  * SPDX-License-Identifier: GPL-3.0-or-later
9  *
10  */
11 
12 #ifndef INCLUDED_IO_SIGNATURE_H
13 #define INCLUDED_IO_SIGNATURE_H
14 
15 #include <gnuradio/api.h>
16 #include <spdlog/fmt/fmt.h>
17 #include <string_view>
18 #include <memory>
19 
20 #include <gnuradio/buffer_type.h>
21 // For testing purposes, force single mapped buffers to make all QA use them
22 // #define FORCE_SINGLE_MAPPED
23 #ifdef FORCE_SINGLE_MAPPED
24 #include <gnuradio/host_buffer.h>
25 #else
27 #endif
28 
29 
30 namespace gr {
31 
32 /*!
33  * \brief i/o signature for input and output ports.
34  * \brief misc
35  */
37 {
38  int d_min_streams;
39  int d_max_streams;
40  std::vector<size_t> d_sizeof_stream_item;
41  gr_vector_buffer_type d_stream_buffer_type;
42 
43  io_signature(int min_streams,
44  int max_streams,
45  const std::vector<size_t>& sizeof_stream_items,
46  const gr_vector_buffer_type& buftypes);
47 
48 public:
49  typedef std::shared_ptr<io_signature> sptr;
50 
51 #ifdef FORCE_SINGLE_MAPPED
53 #else
55 #endif
56 
57  static constexpr int IO_INFINITE = -1;
58 
59  ~io_signature();
60 
61  /*!
62  * \brief Create an i/o signature
63  *
64  * \ingroup internal
65  * \param min_streams specify minimum number of streams (>= 0)
66  * \param max_streams specify maximum number of streams (>= min_streams or -1 ->
67  * infinite) \param sizeof_stream_item specify the size of the items in each stream
68  * \param buftype type of buffers the streams should use (defaults to standard host
69  * double mapped buffer)
70  */
71  static sptr make(int min_streams,
72  int max_streams,
73  int sizeof_stream_item,
74  buffer_type buftype = default_buftype::type);
75 
76 
77  /*!
78  * \brief Create an i/o signature
79  *
80  * \ingroup internal
81  * \param min_streams specify minimum number of streams (>= 0)
82  * \param max_streams specify maximum number of streams (>= min_streams or -1 ->
83  * infinite)
84  * \param sizeof_stream_items specify the size of the items in each stream
85  * \param buftypes type of buffers the streams should use (defaults to standard host
86  * double mapped buffer)
87  */
88  static sptr make(int min_streams,
89  int max_streams,
90  const std::vector<size_t>& sizeof_stream_items,
91  const gr::gr_vector_buffer_type& buftypes =
92  gr::gr_vector_buffer_type(1, default_buftype::type));
93 
94  /*!
95  * \brief Create an i/o signature
96  *
97  * \param min_streams specify minimum number of streams (>= 0)
98  * \param max_streams specify maximum number of streams (>= min_streams or -1 ->
99  * infinite) \param sizeof_stream_item1 specify the size of the items in the first
100  * stream \param sizeof_stream_item2 specify the size of the items in the second and
101  * subsequent streams
102  * \param buftype1 type of buffers the first stream should use (defaults to standard
103  * host double mapped buffer)
104  * \param buftype2 type of buffers the second and subsequent streams should use
105  * (defaults to standard host double mapped buffer)
106  */
107  //[[deprecated("Use generic make(min, max, {…})")]]
108  static sptr make2(int min_streams,
109  int max_streams,
110  int sizeof_stream_item1,
111  int sizeof_stream_item2,
112  buffer_type buftype1 = default_buftype::type,
113  buffer_type buftype2 = default_buftype::type);
114 
115  /*!
116  * \brief Create an i/o signature
117  *
118  * \param min_streams specify minimum number of streams (>= 0)
119  * \param max_streams specify maximum number of streams (>= min_streams or -1 ->
120  * infinite) \param sizeof_stream_item1 specify the size of the items in the first
121  * stream \param sizeof_stream_item2 specify the size of the items in the second
122  * stream \param sizeof_stream_item3 specify the size of the items in the third and
123  * subsequent streams
124  * \param buftype1 type of buffers the first stream should use (defaults to standard
125  * host double mapped buffer)
126  * \param buftype2 type of buffers the second stream should use (defaults to standard
127  * host double mapped buffer)
128  * \param buftype3 type of buffers the third and subsequent streams should use
129  * (defaults to standard host double mapped buffer)
130  */
131  //[[deprecated("Use generic make(min, max, {…})")]]
132  static sptr make3(int min_streams,
133  int max_streams,
134  int sizeof_stream_item1,
135  int sizeof_stream_item2,
136  int sizeof_stream_item3,
137  buffer_type buftype1 = default_buftype::type,
138  buffer_type buftype2 = default_buftype::type,
139  buffer_type buftype3 = default_buftype::type);
140 
141  /*!
142  * \brief Create an i/o signature
143  *
144  * \param min_streams specify minimum number of streams (>= 0)
145  * \param max_streams specify maximum number of streams (>= min_streams or -1 ->
146  * infinite) \param sizeof_stream_items specify the size of the items in the streams
147  *
148  * If there are more streams than there are entries in
149  * sizeof_stream_items, the value of the last entry in
150  * sizeof_stream_items is used for the missing values.
151  * sizeof_stream_items must contain at least 1 entry.
152  */
153  //[[deprecated("Use generic make(min, max, {…})")]]
154  static sptr
155  makev(int min_streams, int max_streams, const std::vector<int>& sizeof_stream_items);
156 
157  /*!
158  * \brief Create an i/o signature
159  *
160  * \param min_streams specify minimum number of streams (>= 0)
161  * \param max_streams specify maximum number of streams (>= min_streams or -1 ->
162  * infinite)
163  * \param sizeof_stream_items specify the size of the items in the streams
164  * \param buftypes the type of buffer each stream will should use
165  *
166  * If there are more streams than there are entries in
167  * sizeof_stream_items, the value of the last entry in
168  * sizeof_stream_items is used for the missing values.
169  * sizeof_stream_items must contain at least 1 entry.
170  */
171  //[[deprecated("Use generic make(min, max, {…})")]]
172  static sptr makev(int min_streams,
173  int max_streams,
174  const std::vector<int>& sizeof_stream_items,
175  const gr_vector_buffer_type& buftypes);
176 
177  int min_streams() const { return d_min_streams; }
178  int max_streams() const { return d_max_streams; }
179  int sizeof_stream_item(int index) const;
180  // TODO: convert API to <size_t>
181  std::vector<int> sizeof_stream_items() const;
182  buffer_type stream_buffer_type(size_t index) const;
183  gr_vector_buffer_type stream_buffer_types() const;
184  friend bool operator==(const io_signature& lhs, const io_signature& rhs);
185 };
186 
187 bool operator==(const io_signature& lhs, const io_signature& rhs);
188 } /* namespace gr */
189 
190 template <>
191 struct GR_RUNTIME_API fmt::formatter<gr::io_signature> : formatter<std::string_view> {
192  fmt::format_context::iterator format(const gr::io_signature& iosig,
193  format_context& ctx) const;
194 };
195 #endif /* INCLUDED_IO_SIGNATURE_H */
Definition: host_buffer.h:18
std::shared_ptr< io_signature > sptr
Definition: io_signature.h:49
Single writer, multiple reader fifo.
Definition: buffer_double_mapped.h:28
int max_streams() const
Definition: io_signature.h:178
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:18
int min_streams() const
Definition: io_signature.h:177
GNU Radio logging wrapper.
Definition: basic_block.h:29
Template used to create buffer types. Note that the factory_class parameter must contain a static fun...
Definition: buffer_type.h:94
i/o signature for input and output ports.
Definition: io_signature.h:36
bool operator==(const io_signature &lhs, const io_signature &rhs)
Base class for describing a buffer&#39;s type.
Definition: buffer_type.h:27
std::vector< std::reference_wrapper< const buffer_type_base > > gr_vector_buffer_type
Definition: buffer_type.h:86
enables PMTs to be formatted with fmt
Definition: io_signature.h:191