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 00077 virtual void forecast (int noutput_items, 00078 gr_vector_int &ninput_items_required); 00079 00094 virtual int general_work (int noutput_items, 00095 gr_vector_int &ninput_items, 00096 gr_vector_const_void_star &input_items, 00097 gr_vector_void_star &output_items) = 0; 00098 00112 virtual bool check_topology (int ninputs, int noutputs); 00113 00114 // ---------------------------------------------------------------- 00115 00123 void set_output_multiple (int multiple); 00124 int output_multiple () const { return d_output_multiple; } 00125 00129 void consume (int which_input, int how_many_items); 00130 00134 void consume_each (int how_many_items); 00135 00145 void set_relative_rate (double relative_rate); 00146 00150 double relative_rate () const { return d_relative_rate; } 00151 00152 00153 // ---------------------------------------------------------------------------- 00154 00155 private: 00156 00157 std::string d_name; 00158 gr_io_signature_sptr d_input_signature; 00159 gr_io_signature_sptr d_output_signature; 00160 int d_output_multiple; 00161 double d_relative_rate; // approx output_rate / input_rate 00162 gr_block_detail_sptr d_detail; // implementation details 00163 long d_unique_id; // convenient for debugging 00164 00165 protected: 00166 00167 gr_block (const std::string &name, 00168 gr_io_signature_sptr input_signature, 00169 gr_io_signature_sptr output_signature); 00170 00172 void set_input_signature (gr_io_signature_sptr iosig){ 00173 d_input_signature = iosig; 00174 } 00175 00177 void set_output_signature (gr_io_signature_sptr iosig){ 00178 d_output_signature = iosig; 00179 } 00180 00181 // These are really only for internal use, but leaving them public avoids 00182 // having to work up an ever-varying list of friends 00183 00184 public: 00185 gr_block_detail_sptr detail () const { return d_detail; } 00186 void set_detail (gr_block_detail_sptr detail) { d_detail = detail; } 00187 }; 00188 00189 long gr_block_ncurrently_allocated (); 00190 00191 #endif /* INCLUDED_GR_BLOCK_H */