gr_block.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2004,2007 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 details.
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_H
00024 #define INCLUDED_GR_BLOCK_H
00025 
00026 #include <gr_basic_block.h>
00027 
00056 class gr_block : public gr_basic_block {
00057 
00058  public:
00059   
00060   virtual ~gr_block ();
00061 
00069   unsigned history () const { return d_history; }
00070   void  set_history (unsigned history) { d_history = history; }
00071   
00077   bool fixed_rate() const { return d_fixed_rate; }
00078 
00079   // ----------------------------------------------------------------
00080   //            override these to define your behavior
00081   // ----------------------------------------------------------------
00082 
00093   virtual void forecast (int noutput_items,
00094                          gr_vector_int &ninput_items_required);
00095 
00110   virtual int general_work (int noutput_items,
00111                             gr_vector_int &ninput_items,
00112                             gr_vector_const_void_star &input_items,
00113                             gr_vector_void_star &output_items) = 0;
00114 
00123   virtual bool start();
00124 
00128   virtual bool stop();
00129 
00130   // ----------------------------------------------------------------
00131 
00139   void set_output_multiple (int multiple);
00140   int  output_multiple () const { return d_output_multiple; }
00141 
00145   void consume (int which_input, int how_many_items);
00146 
00150   void consume_each (int how_many_items);
00151 
00161   void  set_relative_rate (double relative_rate);
00162 
00166   double relative_rate () const { return d_relative_rate; }
00167 
00168   /*
00169    * The following two methods provide special case info to the
00170    * scheduler in the event that a block has a fixed input to output
00171    * ratio.  gr_sync_block, gr_sync_decimator and gr_sync_interpolator
00172    * override these.  If you're fixed rate, subclass one of those.
00173    */
00179   virtual int fixed_rate_ninput_to_noutput(int ninput);
00180 
00186   virtual int fixed_rate_noutput_to_ninput(int noutput);
00187 
00188   // ----------------------------------------------------------------------------
00189 
00190  private:
00191 
00192   int                   d_output_multiple;
00193   double                d_relative_rate;        // approx output_rate / input_rate
00194   gr_block_detail_sptr  d_detail;                   // implementation details
00195   unsigned              d_history;
00196   bool                  d_fixed_rate;
00197     
00198  protected:
00199 
00200   gr_block (const std::string &name,
00201             gr_io_signature_sptr input_signature,
00202             gr_io_signature_sptr output_signature);
00203 
00204   void set_fixed_rate(bool fixed_rate){ d_fixed_rate = fixed_rate; }
00205 
00206   // These are really only for internal use, but leaving them public avoids
00207   // having to work up an ever-varying list of friends
00208 
00209  public:
00210   gr_block_detail_sptr detail () const { return d_detail; }
00211   void set_detail (gr_block_detail_sptr detail) { d_detail = detail; }
00212 };
00213 
00214 typedef std::vector<gr_block_sptr> gr_block_vector_t;
00215 typedef std::vector<gr_block_sptr>::iterator gr_block_viter_t;
00216 
00217 inline gr_block_sptr make_gr_block_sptr(gr_basic_block_sptr p)
00218 {
00219   return boost::dynamic_pointer_cast<gr_block, gr_basic_block>(p);
00220 }
00221 
00222 #endif /* INCLUDED_GR_BLOCK_H */

Generated on Thu Mar 5 09:01:10 2009 for GNU Radio 3.1.3 by  doxygen 1.5.8