3 * Copyright 2004,2009 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)
40 d_ninputs (ninputs), d_noutputs (noutputs),
41 d_input (ninputs), d_output (noutputs),
44 s_ncurrently_allocated++;
47 gr_block_detail::~gr_block_detail ()
49 // should take care of itself
50 s_ncurrently_allocated--;
54 gr_block_detail::set_input (unsigned int which, gr_buffer_reader_sptr reader)
56 if (which >= d_ninputs)
57 throw std::invalid_argument ("gr_block_detail::set_input");
59 d_input[which] = reader;
63 gr_block_detail::set_output (unsigned int which, gr_buffer_sptr buffer)
65 if (which >= d_noutputs)
66 throw std::invalid_argument ("gr_block_detail::set_output");
68 d_output[which] = buffer;
72 gr_make_block_detail (unsigned int ninputs, unsigned int noutputs)
74 return gr_block_detail_sptr (new gr_block_detail (ninputs, noutputs));
78 gr_block_detail::set_done (bool done)
81 for (unsigned int i = 0; i < d_noutputs; i++)
82 d_output[i]->set_done (done);
84 for (unsigned int i = 0; i < d_ninputs; i++)
85 d_input[i]->set_done (done);
89 gr_block_detail::consume (int which_input, int how_many_items)
91 if (how_many_items > 0)
92 input (which_input)->update_read_pointer (how_many_items);
96 gr_block_detail::consume_each (int how_many_items)
98 if (how_many_items > 0)
99 for (int i = 0; i < ninputs (); i++)
100 d_input[i]->update_read_pointer (how_many_items);
104 gr_block_detail::produce (int which_output, int how_many_items)
106 if (how_many_items > 0){
107 d_output[which_output]->update_write_pointer (how_many_items);
108 d_produce_or |= how_many_items;
113 gr_block_detail::produce_each (int how_many_items)
115 if (how_many_items > 0){
116 for (int i = 0; i < noutputs (); i++)
117 d_output[i]->update_write_pointer (how_many_items);
118 d_produce_or |= how_many_items;
124 gr_block_detail::_post(pmt::pmt_t msg)
126 d_tpb.insert_tail(msg);