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