GNU Radio 3.4.2 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2004,2009,2010 Free Software Foundation, Inc. 00004 * 00005 * This file is part of GNU Radio 00006 * 00007 * GNU Radio is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 3, or (at your option) 00010 * any later version. 00011 * 00012 * GNU Radio is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more detail. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with GNU Radio; see the file COPYING. If not, write to 00019 * the Free Software Foundation, Inc., 51 Franklin Street, 00020 * Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #ifndef INCLUDED_GR_BLOCK_DETAIL_H 00024 #define INCLUDED_GR_BLOCK_DETAIL_H 00025 00026 #include <gr_runtime_types.h> 00027 #include <gr_tpb_detail.h> 00028 #include <gr_tag_info.h> 00029 #include <stdexcept> 00030 00031 /*! 00032 * \brief Implementation details to support the signal processing abstraction 00033 * \ingroup internal 00034 * 00035 * This class contains implementation detail that should be "out of sight" 00036 * of almost all users of GNU Radio. This decoupling also means that 00037 * we can make changes to the guts without having to recompile everything. 00038 */ 00039 class gr_block_detail { 00040 public: 00041 ~gr_block_detail (); 00042 00043 int ninputs () const { return d_ninputs; } 00044 int noutputs () const { return d_noutputs; } 00045 bool sink_p () const { return d_noutputs == 0; } 00046 bool source_p () const { return d_ninputs == 0; } 00047 00048 void set_done (bool done); 00049 bool done () const { return d_done; } 00050 00051 void set_input (unsigned int which, gr_buffer_reader_sptr reader); 00052 gr_buffer_reader_sptr input (unsigned int which) 00053 { 00054 if (which >= d_ninputs) 00055 throw std::invalid_argument ("gr_block_detail::input"); 00056 return d_input[which]; 00057 } 00058 00059 void set_output (unsigned int which, gr_buffer_sptr buffer); 00060 gr_buffer_sptr output (unsigned int which) 00061 { 00062 if (which >= d_noutputs) 00063 throw std::invalid_argument ("gr_block_detail::output"); 00064 return d_output[which]; 00065 } 00066 00067 /*! 00068 * \brief Tell the scheduler \p how_many_items of input stream \p which_input were consumed. 00069 */ 00070 void consume (int which_input, int how_many_items); 00071 00072 /*! 00073 * \brief Tell the scheduler \p how_many_items were consumed on each input stream. 00074 */ 00075 void consume_each (int how_many_items); 00076 00077 /*! 00078 * \brief Tell the scheduler \p how_many_items were produced on output stream \p which_output. 00079 */ 00080 void produce (int which_output, int how_many_items); 00081 00082 /*! 00083 * \brief Tell the scheduler \p how_many_items were produced on each output stream. 00084 */ 00085 void produce_each (int how_many_items); 00086 00087 /*! 00088 * Accept msg, place in queue, arrange for thread to be awakened if it's not already. 00089 */ 00090 void _post(pmt::pmt_t msg); 00091 00092 // Return the number of items read on input stream which_input 00093 uint64_t nitems_read(unsigned int which_input); 00094 00095 // Return the number of items written on output stream which_output 00096 uint64_t nitems_written(unsigned int which_output); 00097 00098 00099 /*! 00100 * \brief Adds a new tag to the given output stream. 00101 * 00102 * This takes the input parameters and builds a PMT tuple 00103 * from it. It then calls gr_buffer::add_item_tag(pmt::pmt_t t), 00104 * which appends the tag onto its deque. 00105 * 00106 * \param which_output an integer of which output stream to attach the tag 00107 * \param abs_offset a uint64 number of the absolute item number 00108 * assicated with the tag. Can get from nitems_written. 00109 * \param key the tag key as a PMT symbol 00110 * \param value any PMT holding any value for the given key 00111 * \param srcid a PMT source ID specifier 00112 */ 00113 void add_item_tag(unsigned int which_output, 00114 uint64_t abs_offset, 00115 const pmt::pmt_t &key, 00116 const pmt::pmt_t &value, 00117 const pmt::pmt_t &srcid); 00118 00119 /*! 00120 * \brief Given a [start,end), returns a vector of all tags in the range. 00121 * 00122 * Pass-through function to gr_buffer_reader to get a vector of tags 00123 * in given range. Range of counts is from start to end-1. 00124 * 00125 * Tags are tuples of: 00126 * (item count, source id, key, value) 00127 * 00128 * \param v a vector reference to return tags into 00129 * \param which_input an integer of which input stream to pull from 00130 * \param abs_start a uint64 count of the start of the range of interest 00131 * \param abs_end a uint64 count of the end of the range of interest 00132 */ 00133 void get_tags_in_range(std::vector<pmt::pmt_t> &v, 00134 unsigned int which_input, 00135 uint64_t abs_start, 00136 uint64_t abs_end); 00137 00138 /*! 00139 * \brief Given a [start,end), returns a vector of all tags in the range 00140 * with a given key. 00141 * 00142 * Calls get_tags_in_range(which_input, abs_start, abs_end) to get a vector of 00143 * tags from the buffers. This function then provides a secondary filter to 00144 * the tags to extract only tags with the given 'key'. 00145 * 00146 * Tags are tuples of: 00147 * (item count, source id, key, value) 00148 * 00149 * \param v a vector reference to return tags into 00150 * \param which_input an integer of which input stream to pull from 00151 * \param abs_start a uint64 count of the start of the range of interest 00152 * \param abs_end a uint64 count of the end of the range of interest 00153 * \param key a PMT symbol to select only tags of this key 00154 */ 00155 void get_tags_in_range(std::vector<pmt::pmt_t> &v, 00156 unsigned int which_input, 00157 uint64_t abs_start, 00158 uint64_t abs_end, 00159 const pmt::pmt_t &key); 00160 00161 gr_tpb_detail d_tpb; // used by thread-per-block scheduler 00162 int d_produce_or; 00163 00164 // ---------------------------------------------------------------------------- 00165 00166 private: 00167 unsigned int d_ninputs; 00168 unsigned int d_noutputs; 00169 std::vector<gr_buffer_reader_sptr> d_input; 00170 std::vector<gr_buffer_sptr> d_output; 00171 bool d_done; 00172 00173 gr_block_detail (unsigned int ninputs, unsigned int noutputs); 00174 00175 friend class gr_tpb_detail; 00176 00177 friend gr_block_detail_sptr 00178 gr_make_block_detail (unsigned int ninputs, unsigned int noutputs); 00179 }; 00180 00181 gr_block_detail_sptr 00182 gr_make_block_detail (unsigned int ninputs, unsigned int noutputs); 00183 00184 long 00185 gr_block_detail_ncurrently_allocated (); 00186 00187 #endif /* INCLUDED_GR_BLOCK_DETAIL_H */