Imported Upstream version 3.0
[debian/gnuradio] / gnuradio-core / src / lib / runtime / gr_block_detail.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2004 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 2, 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 detail.
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 #ifndef INCLUDED_GR_BLOCK_DETAIL_H
24 #define INCLUDED_GR_BLOCK_DETAIL_H
25
26 #include <gr_runtime.h>
27 #include <stdexcept>
28
29 /*!
30  * \brief Implementation details to support the signal processing abstraction
31  * \ingroup internal
32  *
33  * This class contains implementation detail that should be "out of sight"
34  * of almost all users of GNU Radio.  This decoupling also means that
35  * we can make changes to the guts without having to recompile everything.
36  */
37
38 class gr_block_detail {
39  public:
40   ~gr_block_detail ();
41
42   int ninputs () const { return d_ninputs; }
43   int noutputs () const { return d_noutputs; }
44   bool sink_p () const { return d_noutputs == 0; }
45   bool source_p () const { return d_ninputs == 0; }
46
47   void set_done (bool done);
48   bool done () const { return d_done; }
49
50   void set_input (unsigned int which, gr_buffer_reader_sptr reader);
51   gr_buffer_reader_sptr input (unsigned int which)
52   {
53     if (which >= d_ninputs)
54       throw std::invalid_argument ("gr_block_detail::input");
55     return d_input[which];
56   }
57
58   void set_output (unsigned int which, gr_buffer_sptr buffer);
59   gr_buffer_sptr output (unsigned int which)
60   {
61     if (which >= d_noutputs)
62       throw std::invalid_argument ("gr_block_detail::output");
63     return d_output[which];
64   }
65
66   /*!
67    * \brief Tell the scheduler \p how_many_items of input stream \p which_input were consumed.
68    */
69   void consume (int which_input, int how_many_items);
70
71   /*!
72    * \brief Tell the scheduler \p how_many_items were consumed on each input stream.
73    */
74   void consume_each (int how_many_items);
75
76   void produce_each (int how_many_items);
77
78   // ----------------------------------------------------------------------------
79
80  private:
81   unsigned int                      d_ninputs;
82   unsigned int                      d_noutputs;
83   std::vector<gr_buffer_reader_sptr> d_input;
84   std::vector<gr_buffer_sptr>       d_output;
85   bool                              d_done;
86     
87   gr_block_detail (unsigned int ninputs, unsigned int noutputs);
88
89   friend gr_block_detail_sptr 
90   gr_make_block_detail (unsigned int ninputs, unsigned int noutputs);
91 };
92
93 gr_block_detail_sptr
94 gr_make_block_detail (unsigned int ninputs, unsigned int noutputs);
95
96 long
97 gr_block_detail_ncurrently_allocated ();
98
99 #endif /* INCLUDED_GR_BLOCK_DETAIL_H */