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