Imported Upstream version 3.2.2
[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 #include <iostream>
31
32 gr_block::gr_block (const std::string &name,
33                     gr_io_signature_sptr input_signature,
34                     gr_io_signature_sptr output_signature)
35   : gr_basic_block(name, input_signature, output_signature),
36     d_output_multiple (1),
37     d_relative_rate (1.0),
38     d_history(1),
39     d_fixed_rate(false)
40 {
41 }
42   
43 gr_block::~gr_block ()
44 {
45 }
46
47 // stub implementation:  1:1
48
49 void
50 gr_block::forecast (int noutput_items, gr_vector_int &ninput_items_required)
51 {
52   unsigned ninputs = ninput_items_required.size ();
53   for (unsigned i = 0; i < ninputs; i++)
54     ninput_items_required[i] = noutput_items + history() - 1;
55 }
56
57 // default implementation
58
59 bool
60 gr_block::start()
61 {
62   return true;
63 }
64
65 bool
66 gr_block::stop()
67 {
68   return true;
69 }
70
71 void
72 gr_block::set_output_multiple (int multiple)
73 {
74   if (multiple < 1)
75     throw std::invalid_argument ("gr_block::set_output_multiple");
76
77   d_output_multiple = multiple;
78 }
79
80 void
81 gr_block::set_relative_rate (double relative_rate)
82 {
83   if (relative_rate < 0.0)
84     throw std::invalid_argument ("gr_block::set_relative_rate");
85   
86   d_relative_rate = relative_rate;
87 }
88
89
90 void
91 gr_block::consume (int which_input, int how_many_items)
92 {
93   d_detail->consume (which_input, how_many_items);
94 }
95
96 void
97 gr_block::consume_each (int how_many_items)
98 {
99   d_detail->consume_each (how_many_items);
100 }
101
102 int
103 gr_block::fixed_rate_ninput_to_noutput(int ninput)
104 {
105   throw std::runtime_error("Unimplemented");
106 }
107
108 int
109 gr_block::fixed_rate_noutput_to_ninput(int noutput)
110 {
111   throw std::runtime_error("Unimplemented");
112 }
113
114 std::ostream&
115 operator << (std::ostream& os, const gr_block *m)
116 {
117   os << "<gr_block " << m->name() << " (" << m->unique_id() << ")>";
118   return os;
119 }
120