Imported Upstream version 3.0.4
[debian/gnuradio] / gnuradio-core / src / lib / runtime / gr_block.cc
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 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.h>
28 #include <gr_block_detail.h>
29 #include <stdexcept>
30
31 static long s_next_id = 0;
32 static long s_ncurrently_allocated = 0;
33
34 long
35 gr_block_ncurrently_allocated ()
36 {
37   return s_ncurrently_allocated;
38 }
39
40 gr_block::gr_block (const std::string &name,
41                     gr_io_signature_sptr input_signature,
42                     gr_io_signature_sptr output_signature)
43   : d_name (name),
44     d_input_signature (input_signature),
45     d_output_signature (output_signature),
46     d_output_multiple (1),
47     d_relative_rate (1.0),
48     d_unique_id (s_next_id++),
49     d_history(1),
50     d_fixed_rate(false)
51 {
52   s_ncurrently_allocated++;
53 }
54   
55 gr_block::~gr_block ()
56 {
57   s_ncurrently_allocated--;
58 }
59
60 // stub implementation:  1:1
61
62 void
63 gr_block::forecast (int noutput_items, gr_vector_int &ninput_items_required)
64 {
65   unsigned ninputs = ninput_items_required.size ();
66   for (unsigned i = 0; i < ninputs; i++)
67     ninput_items_required[i] = noutput_items;
68 }
69
70 // default implementation
71
72 bool
73 gr_block::check_topology (int ninputs, int noutputs)
74 {
75   return true;
76 }
77
78 bool
79 gr_block::start()
80 {
81   return true;
82 }
83
84 bool
85 gr_block::stop()
86 {
87   return true;
88 }
89
90 void
91 gr_block::set_output_multiple (int multiple)
92 {
93   if (multiple < 1)
94     throw std::invalid_argument ("gr_block::set_output_multiple");
95
96   d_output_multiple = multiple;
97 }
98
99 void
100 gr_block::set_relative_rate (double relative_rate)
101 {
102   if (relative_rate < 0.0)
103     throw std::invalid_argument ("gr_block::set_relative_rate");
104   
105   d_relative_rate = relative_rate;
106 }
107
108
109 void
110 gr_block::consume (int which_input, int how_many_items)
111 {
112   d_detail->consume (which_input, how_many_items);
113 }
114
115 void
116 gr_block::consume_each (int how_many_items)
117 {
118   d_detail->consume_each (how_many_items);
119 }
120
121 int
122 gr_block::fixed_rate_ninput_to_noutput(int ninput)
123 {
124   throw std::runtime_error("Unimplemented");
125 }
126
127 int
128 gr_block::fixed_rate_noutput_to_ninput(int noutput)
129 {
130   throw std::runtime_error("Unimplemented");
131 }