Imported Upstream version 3.2.2
[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 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 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_types.h>
27 #include <gr_tpb_detail.h>
28 #include <stdexcept>
29
30 /*!
31  * \brief Implementation details to support the signal processing abstraction
32  * \ingroup internal
33  *
34  * This class contains implementation detail that should be "out of sight"
35  * of almost all users of GNU Radio.  This decoupling also means that
36  * we can make changes to the guts without having to recompile everything.
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   /*!
77    * \brief Tell the scheduler \p how_many_items were produced on each output stream.
78    */
79   void produce_each (int how_many_items);
80
81
82   gr_tpb_detail                      d_tpb;     // used by thread-per-block scheduler
83
84   // ----------------------------------------------------------------------------
85
86  private:
87   unsigned int                       d_ninputs;
88   unsigned int                       d_noutputs;
89   std::vector<gr_buffer_reader_sptr> d_input;
90   std::vector<gr_buffer_sptr>        d_output;
91   bool                               d_done;
92
93
94   gr_block_detail (unsigned int ninputs, unsigned int noutputs);
95
96   friend class gr_tpb_detail;
97
98   friend gr_block_detail_sptr
99   gr_make_block_detail (unsigned int ninputs, unsigned int noutputs);
100 };
101
102 gr_block_detail_sptr
103 gr_make_block_detail (unsigned int ninputs, unsigned int noutputs);
104
105 long
106 gr_block_detail_ncurrently_allocated ();
107
108 #endif /* INCLUDED_GR_BLOCK_DETAIL_H */