switch source package format to 3.0 quilt
[debian/gnuradio] / gnuradio-core / src / lib / runtime / gr_block_detail.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2004,2009 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
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)
10  * any later version.
11  * 
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.
16  * 
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.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include <gr_block_detail.h>
28 #include <gr_buffer.h>
29
30 static long s_ncurrently_allocated = 0;
31
32 long
33 gr_block_detail_ncurrently_allocated ()
34 {
35   return s_ncurrently_allocated;
36 }
37
38 gr_block_detail::gr_block_detail (unsigned int ninputs, unsigned int noutputs)
39   : d_produce_or(0),
40     d_ninputs (ninputs), d_noutputs (noutputs),
41     d_input (ninputs), d_output (noutputs),
42     d_done (false)
43 {
44   s_ncurrently_allocated++;
45 }
46
47 gr_block_detail::~gr_block_detail ()
48 {
49   // should take care of itself
50   s_ncurrently_allocated--;
51 }
52
53 void
54 gr_block_detail::set_input (unsigned int which, gr_buffer_reader_sptr reader)
55 {
56   if (which >= d_ninputs)
57     throw std::invalid_argument ("gr_block_detail::set_input");
58
59   d_input[which] = reader;
60 }
61
62 void
63 gr_block_detail::set_output (unsigned int which, gr_buffer_sptr buffer)
64 {
65   if (which >= d_noutputs)
66     throw std::invalid_argument ("gr_block_detail::set_output");
67
68   d_output[which] = buffer;
69 }
70
71 gr_block_detail_sptr
72 gr_make_block_detail (unsigned int ninputs, unsigned int noutputs)
73 {
74   return gr_block_detail_sptr (new gr_block_detail (ninputs, noutputs));
75 }
76
77 void
78 gr_block_detail::set_done (bool done)
79 {
80   d_done = done;
81   for (unsigned int i = 0; i < d_noutputs; i++)
82     d_output[i]->set_done (done);
83
84   for (unsigned int i = 0; i < d_ninputs; i++)
85     d_input[i]->set_done (done);
86 }
87
88 void 
89 gr_block_detail::consume (int which_input, int how_many_items)
90 {
91   if (how_many_items > 0)
92     input (which_input)->update_read_pointer (how_many_items);
93 }
94
95 void
96 gr_block_detail::consume_each (int how_many_items)
97 {
98   if (how_many_items > 0)
99     for (int i = 0; i < ninputs (); i++)
100       d_input[i]->update_read_pointer (how_many_items);
101 }
102
103 void
104 gr_block_detail::produce (int which_output, int how_many_items)
105 {
106   if (how_many_items > 0){
107     d_output[which_output]->update_write_pointer (how_many_items);
108     d_produce_or |= how_many_items;
109   }
110 }
111
112 void
113 gr_block_detail::produce_each (int how_many_items)
114 {
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;
119   }
120 }
121
122
123 void
124 gr_block_detail::_post(pmt::pmt_t msg)
125 {
126   d_tpb.insert_tail(msg);
127 }