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 00122 virtual bool start(); 00123 00127 virtual bool stop(); 00128 00129 // ---------------------------------------------------------------- 00130 00138 void set_output_multiple (int multiple); 00139 int output_multiple () const { return d_output_multiple; } 00140 00144 void consume (int which_input, int how_many_items); 00145 00149 void consume_each (int how_many_items); 00150 00160 void set_relative_rate (double relative_rate); 00161 00165 double relative_rate () const { return d_relative_rate; } 00166 00167 00168 // ---------------------------------------------------------------------------- 00169 00170 private: 00171 00172 std::string d_name; 00173 gr_io_signature_sptr d_input_signature; 00174 gr_io_signature_sptr d_output_signature; 00175 int d_output_multiple; 00176 double d_relative_rate; // approx output_rate / input_rate 00177 gr_block_detail_sptr d_detail; // implementation details 00178 long d_unique_id; // convenient for debugging 00179 00180 protected: 00181 00182 gr_block (const std::string &name, 00183 gr_io_signature_sptr input_signature, 00184 gr_io_signature_sptr output_signature); 00185 00187 void set_input_signature (gr_io_signature_sptr iosig){ 00188 d_input_signature = iosig; 00189 } 00190 00192 void set_output_signature (gr_io_signature_sptr iosig){ 00193 d_output_signature = iosig; 00194 } 00195 00196 // These are really only for internal use, but leaving them public avoids 00197 // having to work up an ever-varying list of friends 00198 00199 public: 00200 gr_block_detail_sptr detail () const { return d_detail; } 00201 void set_detail (gr_block_detail_sptr detail) { d_detail = detail; } 00202 }; 00203 00204 long gr_block_ncurrently_allocated (); 00205 00206 #endif /* INCLUDED_GR_BLOCK_H */