GNU Radio 3.5.1 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_core_api.h> 00027 #include <gr_runtime_types.h> 00028 #include <gr_tpb_detail.h> 00029 #include <gr_tags.h> 00030 #include <stdexcept> 00031 00032 /*! 00033 * \brief Implementation details to support the signal processing abstraction 00034 * \ingroup internal 00035 * 00036 * This class contains implementation detail that should be "out of sight" 00037 * of almost all users of GNU Radio. This decoupling also means that 00038 * we can make changes to the guts without having to recompile everything. 00039 */ 00040 class GR_CORE_API gr_block_detail { 00041 public: 00042 ~gr_block_detail (); 00043 00044 int ninputs () const { return d_ninputs; } 00045 int noutputs () const { return d_noutputs; } 00046 bool sink_p () const { return d_noutputs == 0; } 00047 bool source_p () const { return d_ninputs == 0; } 00048 00049 void set_done (bool done); 00050 bool done () const { return d_done; } 00051 00052 void set_input (unsigned int which, gr_buffer_reader_sptr reader); 00053 gr_buffer_reader_sptr input (unsigned int which) 00054 { 00055 if (which >= d_ninputs) 00056 throw std::invalid_argument ("gr_block_detail::input"); 00057 return d_input[which]; 00058 } 00059 00060 void set_output (unsigned int which, gr_buffer_sptr buffer); 00061 gr_buffer_sptr output (unsigned int which) 00062 { 00063 if (which >= d_noutputs) 00064 throw std::invalid_argument ("gr_block_detail::output"); 00065 return d_output[which]; 00066 } 00067 00068 /*! 00069 * \brief Tell the scheduler \p how_many_items of input stream \p which_input were consumed. 00070 */ 00071 void consume (int which_input, int how_many_items); 00072 00073 /*! 00074 * \brief Tell the scheduler \p how_many_items were consumed on each input stream. 00075 */ 00076 void consume_each (int how_many_items); 00077 00078 /*! 00079 * \brief Tell the scheduler \p how_many_items were produced on output stream \p which_output. 00080 */ 00081 void produce (int which_output, int how_many_items); 00082 00083 /*! 00084 * \brief Tell the scheduler \p how_many_items were produced on each output stream. 00085 */ 00086 void produce_each (int how_many_items); 00087 00088 /*! 00089 * Accept msg, place in queue, arrange for thread to be awakened if it's not already. 00090 */ 00091 void _post(pmt::pmt_t msg); 00092 00093 // Return the number of items read on input stream which_input 00094 uint64_t nitems_read(unsigned int which_input); 00095 00096 // Return the number of items written on output stream which_output 00097 uint64_t nitems_written(unsigned int which_output); 00098 00099 00100 /*! 00101 * \brief Adds a new tag to the given output stream. 00102 * 00103 * This takes the input parameters and builds a PMT tuple 00104 * from it. It then calls gr_buffer::add_item_tag(pmt::pmt_t t), 00105 * which appends the tag onto its deque. 00106 * 00107 * \param which_output an integer of which output stream to attach the tag 00108 * \param tag the tag object to add 00109 */ 00110 void add_item_tag(unsigned int which_output, const gr_tag_t &tag); 00111 00112 /*! 00113 * \brief Given a [start,end), returns a vector of all tags in the range. 00114 * 00115 * Pass-through function to gr_buffer_reader to get a vector of tags 00116 * in given range. Range of counts is from start to end-1. 00117 * 00118 * Tags are tuples of: 00119 * (item count, source id, key, value) 00120 * 00121 * \param v a vector reference to return tags into 00122 * \param which_input an integer of which input stream to pull from 00123 * \param abs_start a uint64 count of the start of the range of interest 00124 * \param abs_end a uint64 count of the end of the range of interest 00125 */ 00126 void get_tags_in_range(std::vector<gr_tag_t> &v, 00127 unsigned int which_input, 00128 uint64_t abs_start, 00129 uint64_t abs_end); 00130 00131 /*! 00132 * \brief Given a [start,end), returns a vector of all tags in the range 00133 * with a given key. 00134 * 00135 * Calls get_tags_in_range(which_input, abs_start, abs_end) to get a vector of 00136 * tags from the buffers. This function then provides a secondary filter to 00137 * the tags to extract only tags with the given 'key'. 00138 * 00139 * Tags are tuples of: 00140 * (item count, source id, key, value) 00141 * 00142 * \param v a vector reference to return tags into 00143 * \param which_input an integer of which input stream to pull from 00144 * \param abs_start a uint64 count of the start of the range of interest 00145 * \param abs_end a uint64 count of the end of the range of interest 00146 * \param key a PMT symbol to select only tags of this key 00147 */ 00148 void get_tags_in_range(std::vector<gr_tag_t> &v, 00149 unsigned int which_input, 00150 uint64_t abs_start, 00151 uint64_t abs_end, 00152 const pmt::pmt_t &key); 00153 00154 gr_tpb_detail d_tpb; // used by thread-per-block scheduler 00155 int d_produce_or; 00156 00157 // ---------------------------------------------------------------------------- 00158 00159 private: 00160 unsigned int d_ninputs; 00161 unsigned int d_noutputs; 00162 std::vector<gr_buffer_reader_sptr> d_input; 00163 std::vector<gr_buffer_sptr> d_output; 00164 bool d_done; 00165 00166 gr_block_detail (unsigned int ninputs, unsigned int noutputs); 00167 00168 friend struct gr_tpb_detail; 00169 00170 friend GR_CORE_API gr_block_detail_sptr 00171 gr_make_block_detail (unsigned int ninputs, unsigned int noutputs); 00172 }; 00173 00174 GR_CORE_API gr_block_detail_sptr 00175 gr_make_block_detail (unsigned int ninputs, unsigned int noutputs); 00176 00177 GR_CORE_API long 00178 gr_block_detail_ncurrently_allocated (); 00179 00180 #endif /* INCLUDED_GR_BLOCK_DETAIL_H */