GNU Radio 3.6.3 C++ API
gr_block_detail.h
Go to the documentation of this file.
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   // Return the number of items read on input stream which_input
00089   uint64_t nitems_read(unsigned int which_input);
00090 
00091   // Return the number of items written on output stream which_output
00092   uint64_t nitems_written(unsigned int which_output);
00093 
00094 
00095   /*!
00096    * \brief  Adds a new tag to the given output stream.
00097    *
00098    * This takes the input parameters and builds a PMT tuple
00099    * from it. It then calls gr_buffer::add_item_tag(pmt::pmt_t t),
00100    * which appends the tag onto its deque.
00101    *
00102    * \param which_output  an integer of which output stream to attach the tag
00103    * \param tag the tag object to add
00104    */
00105   void add_item_tag(unsigned int which_output, const gr_tag_t &tag);
00106 
00107   /*!
00108    * \brief Given a [start,end), returns a vector of all tags in the range.
00109    *
00110    * Pass-through function to gr_buffer_reader to get a vector of tags
00111    * in given range. Range of counts is from start to end-1.
00112    *
00113    * Tags are tuples of:
00114    *      (item count, source id, key, value)
00115    *
00116    * \param v            a vector reference to return tags into
00117    * \param which_input  an integer of which input stream to pull from
00118    * \param abs_start    a uint64 count of the start of the range of interest
00119    * \param abs_end      a uint64 count of the end of the range of interest
00120    */
00121   void get_tags_in_range(std::vector<gr_tag_t> &v,
00122                          unsigned int which_input,
00123                          uint64_t abs_start,
00124                          uint64_t abs_end);
00125 
00126   /*!
00127    * \brief Given a [start,end), returns a vector of all tags in the range
00128    * with a given key.
00129    *
00130    * Calls get_tags_in_range(which_input, abs_start, abs_end) to get a vector of
00131    * tags from the buffers. This function then provides a secondary filter to
00132    * the tags to extract only tags with the given 'key'.
00133    *
00134    * Tags are tuples of:
00135    *      (item count, source id, key, value)
00136    *
00137    * \param v            a vector reference to return tags into
00138    * \param which_input  an integer of which input stream to pull from
00139    * \param abs_start    a uint64 count of the start of the range of interest
00140    * \param abs_end      a uint64 count of the end of the range of interest
00141    * \param key          a PMT symbol to select only tags of this key
00142    */
00143   void get_tags_in_range(std::vector<gr_tag_t> &v,
00144                          unsigned int which_input,
00145                          uint64_t abs_start,
00146                          uint64_t abs_end,
00147                          const pmt::pmt_t &key);
00148 
00149   gr_tpb_detail                      d_tpb;     // used by thread-per-block scheduler
00150   int                                d_produce_or;
00151 
00152   // ----------------------------------------------------------------------------
00153 
00154  private:
00155   unsigned int                       d_ninputs;
00156   unsigned int                       d_noutputs;
00157   std::vector<gr_buffer_reader_sptr> d_input;
00158   std::vector<gr_buffer_sptr>        d_output;
00159   bool                               d_done;
00160 
00161   gr_block_detail (unsigned int ninputs, unsigned int noutputs);
00162 
00163   friend struct gr_tpb_detail;
00164 
00165   friend GR_CORE_API gr_block_detail_sptr
00166   gr_make_block_detail (unsigned int ninputs, unsigned int noutputs);
00167 };
00168 
00169 GR_CORE_API gr_block_detail_sptr
00170 gr_make_block_detail (unsigned int ninputs, unsigned int noutputs);
00171 
00172 GR_CORE_API long
00173 gr_block_detail_ncurrently_allocated ();
00174 
00175 #endif /* INCLUDED_GR_BLOCK_DETAIL_H */