GNU Radio Manual and C++ API Reference 3.10.5.1
The Free & Open Software Radio Ecosystem
tagged_stream_block.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2013 Free Software Foundation, Inc.
4 *
5 * This file is part of GNU Radio
6 *
7 * SPDX-License-Identifier: GPL-3.0-or-later
8 *
9 */
10
11#ifndef INCLUDED_GR_RUNTIME_TAGGED_STREAM_BLOCK_H
12#define INCLUDED_GR_RUNTIME_TAGGED_STREAM_BLOCK_H
13
14#include <gnuradio/api.h>
15#include <gnuradio/block.h>
16
17namespace gr {
18
19/*!
20 * \brief Block that operates on PDUs in form of tagged streams
21 * \ingroup base_blk
22 *
23 * Override work to provide the signal processing implementation.
24 */
26{
27private:
29 d_length_tag_key; //!< This is the key for the tag that stores the PDU length
31 d_n_input_items_reqd; //!< How many input items do I need to process the next PDU?
32
33protected:
35 tagged_stream_block(void) {} // allows pure virtual interface sub-classes
36 tagged_stream_block(const std::string& name,
37 gr::io_signature::sptr input_signature,
38 gr::io_signature::sptr output_signature,
39 const std::string& length_tag_key);
40
41 /*!
42 * \brief Parse all tags on the first sample of a PDU, return the
43 * number of items per input and prune the length tags.
44 *
45 * In most cases, you don't need to override this, unless the
46 * number of items read is not directly coded in one single tag.
47 *
48 * Default behaviour:
49 * - Go through all input ports
50 * - On every input port, search for the tag with the key specified in \p
51 * length_tag_key
52 * - Copy that value as an int to the corresponding position in \p n_input_items_reqd
53 * - Remove the length tag.
54 *
55 * \param[in] tags All the tags found on the first item of every input port.
56 * \param[out] n_input_items_reqd Number of items which will be read from every input
57 */
58 virtual void parse_length_tags(const std::vector<std::vector<tag_t>>& tags,
59 gr_vector_int& n_input_items_reqd);
60
61 /*!
62 * \brief Calculate the number of output items.
63 *
64 * This is basically the inverse function to forecast(): Given a
65 * number of input items, it returns the maximum number of output
66 * items.
67 *
68 * You most likely need to override this function, unless your
69 * block is a sync block or integer interpolator/decimator.
70 */
71 virtual int calculate_output_stream_length(const gr_vector_int& ninput_items);
72
73 /*!
74 * \brief Set the new length tags on the output stream
75 *
76 * Default behaviour: Set a tag with key \p length_tag_key and the
77 * number of produced items on every output port.
78 *
79 * For anything else, override this.
80 *
81 * \param n_produced Length of the new PDU
82 * \param n_ports Number of output ports
83 */
84 virtual void update_length_tags(int n_produced, int n_ports);
85
86public:
87 /*! \brief Don't override this.
88 */
89 void /* final */ forecast(int noutput_items,
90 gr_vector_int& ninput_items_required) override;
91
92 bool check_topology(int ninputs, int /* noutputs */) override;
93
94 /*!
95 * - Reads the number of input items from the tags using parse_length_tags()
96 * - Checks there's enough data on the input and output buffers
97 * - If not, inform the scheduler and do nothing
98 * - Calls work() with the exact number of items per PDU
99 * - Updates the tags using update_length_tags()
100 */
101 int general_work(int noutput_items,
102 gr_vector_int& ninput_items,
103 gr_vector_const_void_star& input_items,
104 gr_vector_void_star& output_items) override;
105
106 /*!
107 * \brief Just like gr::block::general_work, but makes sure the input is valid
108 *
109 * The user must override work to define the signal processing
110 * code. Check the documentation for general_work() to see what
111 * happens here.
112 *
113 * Like gr::sync_block, this calls consume() for you (it consumes
114 * ninput_items[i] items from the i-th port).
115 *
116 * A note on tag propagation: The PDU length tags are handled by
117 * other functions, but all other tags are handled just as in any
118 * other \p gr::block. So, most likely, you either set the tag
119 * propagation policy to TPP_DONT and handle the tag propagation
120 * manually, or you propagate tags through the scheduler and don't
121 * do anything here.
122 *
123 * \param noutput_items The size of the writable output buffer
124 * \param ninput_items The exact size of the items on every input for this particular
125 * PDU. These will be consumed if a length tag key is provided! \param input_items See
126 * gr::block \param output_items See gr::block
127 */
128 virtual int work(int noutput_items,
129 gr_vector_int& ninput_items,
130 gr_vector_const_void_star& input_items,
131 gr_vector_void_star& output_items) = 0;
132};
133
134} /* namespace gr */
135
136#endif /* INCLUDED_GR_RUNTIME_TAGGED_STREAM_BLOCK_H */
The abstract base class for all 'terminal' processing blocks.
Definition: gnuradio-runtime/include/gnuradio/block.h:63
std::shared_ptr< io_signature > sptr
Definition: io_signature.h:47
Block that operates on PDUs in form of tagged streams.
Definition: tagged_stream_block.h:26
std::string d_length_tag_key_str
Definition: tagged_stream_block.h:34
int general_work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) override
tagged_stream_block(const std::string &name, gr::io_signature::sptr input_signature, gr::io_signature::sptr output_signature, const std::string &length_tag_key)
tagged_stream_block(void)
Definition: tagged_stream_block.h:35
bool check_topology(int ninputs, int) override
Confirm that ninputs and noutputs is an acceptable combination.
virtual int calculate_output_stream_length(const gr_vector_int &ninput_items)
Calculate the number of output items.
virtual void parse_length_tags(const std::vector< std::vector< tag_t > > &tags, gr_vector_int &n_input_items_reqd)
Parse all tags on the first sample of a PDU, return the number of items per input and prune the lengt...
void forecast(int noutput_items, gr_vector_int &ninput_items_required) override
Don't override this.
virtual void update_length_tags(int n_produced, int n_ports)
Set the new length tags on the output stream.
virtual int work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)=0
Just like gr::block::general_work, but makes sure the input is valid.
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:18
GNU Radio logging wrapper.
Definition: basic_block.h:29
std::shared_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting).
Definition: pmt.h:83
std::vector< const void * > gr_vector_const_void_star
Definition: types.h:28
std::vector< void * > gr_vector_void_star
Definition: types.h:27
std::vector< int > gr_vector_int
Definition: types.h:23