root / gnuradio-core / src / lib / runtime / gr_block_detail.h @ 95eaad32
History | View | Annotate | Download (6.4 kB)
| 1 | /* -*- c++ -*- */
|
|---|---|
| 2 | /*
|
| 3 | * Copyright 2004,2009,2010 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 detail. |
| 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_BLOCK_DETAIL_H
|
| 24 | #define INCLUDED_GR_BLOCK_DETAIL_H
|
| 25 | |
| 26 | #include <gr_runtime_types.h> |
| 27 | #include <gr_tpb_detail.h> |
| 28 | #include <stdexcept> |
| 29 | |
| 30 | /*!
|
| 31 | * \brief Implementation details to support the signal processing abstraction |
| 32 | * \ingroup internal |
| 33 | * |
| 34 | * This class contains implementation detail that should be "out of sight" |
| 35 | * of almost all users of GNU Radio. This decoupling also means that |
| 36 | * we can make changes to the guts without having to recompile everything. |
| 37 | */ |
| 38 | class gr_block_detail {
|
| 39 | public:
|
| 40 | ~gr_block_detail (); |
| 41 | |
| 42 | int ninputs () const { return d_ninputs; } |
| 43 | int noutputs () const { return d_noutputs; } |
| 44 | bool sink_p () const { return d_noutputs == 0; } |
| 45 | bool source_p () const { return d_ninputs == 0; } |
| 46 | |
| 47 | void set_done (bool done); |
| 48 | bool done () const { return d_done; } |
| 49 | |
| 50 | void set_input (unsigned int which, gr_buffer_reader_sptr reader); |
| 51 | gr_buffer_reader_sptr input (unsigned int which) |
| 52 | {
|
| 53 | if (which >= d_ninputs)
|
| 54 | throw std::invalid_argument ("gr_block_detail::input");
|
| 55 | return d_input[which];
|
| 56 | } |
| 57 | |
| 58 | void set_output (unsigned int which, gr_buffer_sptr buffer); |
| 59 | gr_buffer_sptr output (unsigned int which) |
| 60 | {
|
| 61 | if (which >= d_noutputs)
|
| 62 | throw std::invalid_argument ("gr_block_detail::output");
|
| 63 | return d_output[which];
|
| 64 | } |
| 65 | |
| 66 | /*!
|
| 67 | * \brief Tell the scheduler \p how_many_items of input stream \p which_input were consumed. |
| 68 | */ |
| 69 | void consume (int which_input, int how_many_items); |
| 70 | |
| 71 | /*!
|
| 72 | * \brief Tell the scheduler \p how_many_items were consumed on each input stream. |
| 73 | */ |
| 74 | void consume_each (int how_many_items); |
| 75 | |
| 76 | /*!
|
| 77 | * \brief Tell the scheduler \p how_many_items were produced on output stream \p which_output. |
| 78 | */ |
| 79 | void produce (int which_output, int how_many_items); |
| 80 | |
| 81 | /*!
|
| 82 | * \brief Tell the scheduler \p how_many_items were produced on each output stream. |
| 83 | */ |
| 84 | void produce_each (int how_many_items); |
| 85 | |
| 86 | /*!
|
| 87 | * Accept msg, place in queue, arrange for thread to be awakened if it's not already. |
| 88 | */ |
| 89 | void _post(pmt::pmt_t msg);
|
| 90 | |
| 91 | // Return the number of items read on input stream which_input
|
| 92 | uint64_t nitems_read(unsigned int which_input); |
| 93 | |
| 94 | // Return the number of items written on output stream which_output
|
| 95 | uint64_t nitems_written(unsigned int which_output); |
| 96 | |
| 97 | |
| 98 | /*!
|
| 99 | * \brief Adds a new tag to the given output stream. |
| 100 | * |
| 101 | * This takes the input parameters and builds a PMT tuple |
| 102 | * from it. It then calls gr_buffer::add_item_tag(pmt::pmt_t t), |
| 103 | * which appends the tag onto its deque. |
| 104 | * |
| 105 | * \param which_ouput an integer of which output stream to attach the tag |
| 106 | * \param abs_offset a uint64 number of the absolute item number |
| 107 | * assicated with the tag. Can get from nitems_written. |
| 108 | * \param key a PMT symbol holding the key name (i.e., a string) |
| 109 | * \param value any PMT holding any value for the given key |
| 110 | * \param srcid a PMT source ID specifier |
| 111 | */ |
| 112 | void add_item_tag(unsigned int which_output, |
| 113 | uint64_t abs_offset, |
| 114 | const pmt::pmt_t &key,
|
| 115 | const pmt::pmt_t &value,
|
| 116 | const pmt::pmt_t &srcid);
|
| 117 | |
| 118 | /*!
|
| 119 | * \brief Given a [start,end), returns a vector of all tags in the range. |
| 120 | * |
| 121 | * Pass-through function to gr_buffer_reader to get a vector of tags |
| 122 | * in given range. Range of counts is from start to end-1. |
| 123 | * |
| 124 | * Tags are tuples of: |
| 125 | * (item count, source id, key, value) |
| 126 | * |
| 127 | * \param which_input an integer of which input stream to pull from |
| 128 | * \param abs_start a uint64 count of the start of the range of interest |
| 129 | * \param abs_end a uint64 count of the end of the range of interest |
| 130 | */ |
| 131 | std::vector<pmt::pmt_t> get_tags_in_range(unsigned int which_input, |
| 132 | uint64_t abs_start, |
| 133 | uint64_t abs_end); |
| 134 | |
| 135 | /*!
|
| 136 | * \brief Given a [start,end), returns a vector of all tags in the range |
| 137 | * with a given key. |
| 138 | * |
| 139 | * Calls get_tags_in_range(which_input, abs_start, abs_end) to get a vector of |
| 140 | * tags from the buffers. This function then provides a secondary filter to |
| 141 | * the tags to extract only tags with the given 'key'. |
| 142 | * |
| 143 | * Tags are tuples of: |
| 144 | * (item count, source id, key, value) |
| 145 | * |
| 146 | * \param which_input an integer of which input stream to pull from |
| 147 | * \param abs_start a uint64 count of the start of the range of interest |
| 148 | * \param abs_end a uint64 count of the end of the range of interest |
| 149 | * \param key a PMT symbol key to select only tags of this key |
| 150 | */ |
| 151 | std::vector<pmt::pmt_t> get_tags_in_range(unsigned int which_input, |
| 152 | uint64_t abs_start, |
| 153 | uint64_t abs_end, |
| 154 | const pmt::pmt_t &key);
|
| 155 | |
| 156 | /*!
|
| 157 | * \brief Default tag handler; moves all tags downstream |
| 158 | * |
| 159 | * Move all tags from input to output and flows them all downstream. Each input |
| 160 | * stream's tags get appended to each output streams tags. |
| 161 | */ |
| 162 | void handle_tags();
|
| 163 | |
| 164 | gr_tpb_detail d_tpb; // used by thread-per-block scheduler
|
| 165 | int d_produce_or;
|
| 166 | |
| 167 | // ----------------------------------------------------------------------------
|
| 168 | |
| 169 | private:
|
| 170 | unsigned int d_ninputs; |
| 171 | unsigned int d_noutputs; |
| 172 | std::vector<gr_buffer_reader_sptr> d_input; |
| 173 | std::vector<gr_buffer_sptr> d_output; |
| 174 | bool d_done;
|
| 175 | |
| 176 | size_t d_last_tag; // keep track of which tags we've already received from upstream
|
| 177 | |
| 178 | gr_block_detail (unsigned int ninputs, unsigned int noutputs); |
| 179 | |
| 180 | friend class gr_tpb_detail; |
| 181 | |
| 182 | friend gr_block_detail_sptr |
| 183 | gr_make_block_detail (unsigned int ninputs, unsigned int noutputs); |
| 184 | }; |
| 185 | |
| 186 | gr_block_detail_sptr |
| 187 | gr_make_block_detail (unsigned int ninputs, unsigned int noutputs); |
| 188 | |
| 189 | long
|
| 190 | gr_block_detail_ncurrently_allocated (); |
| 191 | |
| 192 | #endif /* INCLUDED_GR_BLOCK_DETAIL_H */ |