3 * Copyright 2004 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
27 #include <gr_block_detail.h>
28 #include <gr_buffer.h>
30 static long s_ncurrently_allocated = 0;
33 gr_block_detail_ncurrently_allocated ()
35 return s_ncurrently_allocated;
38 gr_block_detail::gr_block_detail (unsigned int ninputs, unsigned int noutputs)
39 : d_ninputs (ninputs), d_noutputs (noutputs),
40 d_input (ninputs), d_output (noutputs),
43 s_ncurrently_allocated++;
46 gr_block_detail::~gr_block_detail ()
48 // should take care of itself
49 s_ncurrently_allocated--;
53 gr_block_detail::set_input (unsigned int which, gr_buffer_reader_sptr reader)
55 if (which >= d_ninputs)
56 throw std::invalid_argument ("gr_block_detail::set_input");
58 d_input[which] = reader;
62 gr_block_detail::set_output (unsigned int which, gr_buffer_sptr buffer)
64 if (which >= d_noutputs)
65 throw std::invalid_argument ("gr_block_detail::set_output");
67 d_output[which] = buffer;
71 gr_make_block_detail (unsigned int ninputs, unsigned int noutputs)
73 return gr_block_detail_sptr (new gr_block_detail (ninputs, noutputs));
77 gr_block_detail::set_done (bool done)
80 for (unsigned int i = 0; i < d_noutputs; i++)
81 d_output[i]->set_done (done);
83 for (unsigned int i = 0; i < d_ninputs; i++)
84 d_input[i]->set_done (done);
88 gr_block_detail::consume (int which_input, int how_many_items)
90 if (how_many_items > 0)
91 input (which_input)->update_read_pointer (how_many_items);
95 gr_block_detail::consume_each (int how_many_items)
97 if (how_many_items > 0)
98 for (int i = 0; i < ninputs (); i++)
99 d_input[i]->update_read_pointer (how_many_items);
103 gr_block_detail::produce_each (int how_many_items)
105 if (how_many_items > 0)
106 for (int i = 0; i < noutputs (); i++)
107 d_output[i]->update_write_pointer (how_many_items);