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 00070 unsigned history () const { return d_history; } 00071 void set_history (unsigned history) { d_history = history; } 00072 00078 bool fixed_rate() const { return d_fixed_rate; } 00079 00080 // ---------------------------------------------------------------- 00081 // override these to define your behavior 00082 // ---------------------------------------------------------------- 00083 00094 virtual void forecast (int noutput_items, 00095 gr_vector_int &ninput_items_required); 00096 00111 virtual int general_work (int noutput_items, 00112 gr_vector_int &ninput_items, 00113 gr_vector_const_void_star &input_items, 00114 gr_vector_void_star &output_items) = 0; 00115 00129 virtual bool check_topology (int ninputs, int noutputs); 00130 00139 virtual bool start(); 00140 00144 virtual bool stop(); 00145 00146 // ---------------------------------------------------------------- 00147 00155 void set_output_multiple (int multiple); 00156 int output_multiple () const { return d_output_multiple; } 00157 00161 void consume (int which_input, int how_many_items); 00162 00166 void consume_each (int how_many_items); 00167 00177 void set_relative_rate (double relative_rate); 00178 00182 double relative_rate () const { return d_relative_rate; } 00183 00184 /* 00185 * The following two methods provide special case info to the 00186 * scheduler in the event that a block has a fixed input to output 00187 * ratio. gr_sync_block, gr_sync_decimator and gr_sync_interpolator 00188 * override these. If you're fixed rate, subclass one of those. 00189 */ 00195 virtual int fixed_rate_ninput_to_noutput(int ninput); 00196 00202 virtual int fixed_rate_noutput_to_ninput(int noutput); 00203 00204 // ---------------------------------------------------------------------------- 00205 00206 private: 00207 00208 std::string d_name; 00209 gr_io_signature_sptr d_input_signature; 00210 gr_io_signature_sptr d_output_signature; 00211 int d_output_multiple; 00212 double d_relative_rate; // approx output_rate / input_rate 00213 gr_block_detail_sptr d_detail; // implementation details 00214 long d_unique_id; // convenient for debugging 00215 unsigned d_history; 00216 bool d_fixed_rate; 00217 00218 00219 protected: 00220 00221 gr_block (const std::string &name, 00222 gr_io_signature_sptr input_signature, 00223 gr_io_signature_sptr output_signature); 00224 00226 void set_input_signature (gr_io_signature_sptr iosig){ 00227 d_input_signature = iosig; 00228 } 00229 00231 void set_output_signature (gr_io_signature_sptr iosig){ 00232 d_output_signature = iosig; 00233 } 00234 00235 void set_fixed_rate(bool fixed_rate){ d_fixed_rate = fixed_rate; } 00236 00237 // These are really only for internal use, but leaving them public avoids 00238 // having to work up an ever-varying list of friends 00239 00240 public: 00241 gr_block_detail_sptr detail () const { return d_detail; } 00242 void set_detail (gr_block_detail_sptr detail) { d_detail = detail; } 00243 }; 00244 00245 long gr_block_ncurrently_allocated (); 00246 00247 #endif /* INCLUDED_GR_BLOCK_H */