GNU Radio 2.x: gr_block.h Source File

Main Page | Modules | Namespace List | Class Hierarchy | Compound List | File List | Namespace Members | Compound Members | File Members

# gr_block.h

Go to the documentation of this file.

    00001 /* -*- c++ -*- */
    00002 /*
    00003  * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
    00020  * Boston, MA 02111-1307, USA.
    00021  */
    00022
    00023 #ifndef INCLUDED_GR_BLOCK_H
    00024 #define INCLUDED_GR_BLOCK_H
    00025
    00026 #include <gr_runtime.h>
    00027 #include <string>
    00028
    00052 class gr_block {
    00053
    00054  public:
    00055
    00056   virtual ~gr_block ();
    00057
    00058   std::string name () const { return d_name; }
    00059   gr_io_signature_sptr input_signature () const  { return d_input_signature; }
    00060   gr_io_signature_sptr output_signature () const { return d_output_signature; }
    00061   long unique_id () const { return d_unique_id; }
    00062
    00063   // ----------------------------------------------------------------
    00064   //            override these to define your behavior
    00065   // ----------------------------------------------------------------
    00066
    00074   virtual void forecast (int noutput_items, gr_vector_int &ninput_items_required);
    00075
    00090   virtual int general_work (int noutput_items,
    00091                             gr_vector_int &ninput_items,
    00092                             gr_vector_const_void_star &input_items,
    00093                             gr_vector_void_star &output_items) = 0;
    00094
    00108   virtual bool check_topology (int ninputs, int noutputs);
    00109
    00110   // ----------------------------------------------------------------
    00111
    00119   void set_output_multiple (int multiple);
    00120   int  output_multiple () const { return d_output_multiple; }
    00121
    00125   void consume (int which_input, int how_many_items);
    00126
    00130   void consume_each (int how_many_items);
    00131
    00141   void  set_relative_rate (double relative_rate);
    00142
    00146   double relative_rate () const { return d_relative_rate; }
    00147
    00148
    00149   // ----------------------------------------------------------------------------
    00150
    00151  private:
    00152
    00153   std::string           d_name;
    00154   gr_io_signature_sptr  d_input_signature;
    00155   gr_io_signature_sptr  d_output_signature;
    00156   int                   d_output_multiple;
    00157   double                d_relative_rate;        // approx output_rate / input_rate
    00158   gr_block_detail_sptr  d_detail;               // implementation details
    00159   long                  d_unique_id;            // convenient for debugging
    00160
    00161  protected:
    00162
    00163   gr_block (const std::string &name,
    00164              gr_io_signature_sptr input_signature,
    00165              gr_io_signature_sptr output_signature);
    00166
    00167   // These are really only for internal use, but leaving them public avoids
    00168   // having to work up an ever-varying list of friends
    00169
    00170  public:
    00171   gr_block_detail_sptr detail () const { return d_detail; }
    00172   void set_detail (gr_block_detail_sptr detail) { d_detail = detail; }
    00173 };
    00174
    00175 long gr_block_ncurrently_allocated ();
    00176
    00177 #endif /* INCLUDED_GR_BLOCK_H */