diff options
author | Sylvain Munaut <tnt@246tNt.com> | 2016-01-28 09:40:47 +0100 |
---|---|---|
committer | Johnathan Corgan <johnathan@corganlabs.com> | 2016-02-03 09:40:28 -0800 |
commit | 86b4f7f14b22c29c1eae69994ea2f71d6731740b (patch) | |
tree | 2d931147c8cbe3b4d4d5309569b0a3c9e516e129 /gnuradio-runtime/lib/hier_block2_detail.cc | |
parent | 9a37b65a7b8ba2728dccf161703d3a6a53faed9a (diff) |
gnuradio-runtime/hier_block2: Allow changing of IO sig in the constructor
Fixes #719
The issue is that the hier_block2 detail creates some vectors for the
in/out ports to hold where to connect them to during the flatten and
what the min/max output buffer size are.
But subclasses are allowed to change the io signature in their constructor
so before actually using those vectors, we recheck if we should update
their size.
If there is a new io signature with more port, they're initialized to
default values (i.e. not connected). And if the new signature has less
ports, we just drop the connection (which is fine since it's all in the
subclass constructor, before they've been used for anything).
In both cases, just using .resize() on the vector is enough.
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Diffstat (limited to 'gnuradio-runtime/lib/hier_block2_detail.cc')
-rw-r--r-- | gnuradio-runtime/lib/hier_block2_detail.cc | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/gnuradio-runtime/lib/hier_block2_detail.cc b/gnuradio-runtime/lib/hier_block2_detail.cc index 60910d0dd9..0d0ddf55ba 100644 --- a/gnuradio-runtime/lib/hier_block2_detail.cc +++ b/gnuradio-runtime/lib/hier_block2_detail.cc @@ -328,11 +328,45 @@ namespace gr { } void + hier_block2_detail::refresh_io_signature() + { + int min_inputs = d_owner->input_signature()->min_streams(); + int max_inputs = d_owner->input_signature()->max_streams(); + int min_outputs = d_owner->output_signature()->min_streams(); + int max_outputs = d_owner->output_signature()->max_streams(); + + if(max_inputs == io_signature::IO_INFINITE || + max_outputs == io_signature::IO_INFINITE || + (min_inputs != max_inputs) ||(min_outputs != max_outputs) ) { + std::stringstream msg; + msg << "Hierarchical blocks do not yet support arbitrary or" + << " variable numbers of inputs or outputs (" << d_owner->name() << ")"; + throw std::runtime_error(msg.str()); + } + + // Check for # input change + if ((signed)d_inputs.size() != max_inputs) + { + d_inputs.resize(max_inputs); + } + + // Check for # output change + if ((signed)d_outputs.size() != max_outputs) + { + d_outputs.resize(max_outputs); + d_min_output_buffer.resize(max_outputs, 0); + d_max_output_buffer.resize(max_outputs, 0); + } + } + + void hier_block2_detail::connect_input(int my_port, int port, basic_block_sptr block) { std::stringstream msg; + refresh_io_signature(); + if(my_port < 0 || my_port >= (signed)d_inputs.size()) { msg << "input port " << my_port << " out of range for " << block; throw std::invalid_argument(msg.str()); @@ -356,6 +390,8 @@ namespace gr { { std::stringstream msg; + refresh_io_signature(); + if(my_port < 0 || my_port >= (signed)d_outputs.size()) { msg << "output port " << my_port << " out of range for " << block; throw std::invalid_argument(msg.str()); @@ -376,6 +412,8 @@ namespace gr { { std::stringstream msg; + refresh_io_signature(); + if(my_port < 0 || my_port >= (signed)d_inputs.size()) { msg << "input port number " << my_port << " out of range for " << block; throw std::invalid_argument(msg.str()); @@ -399,6 +437,8 @@ namespace gr { { std::stringstream msg; + refresh_io_signature(); + if(my_port < 0 || my_port >= (signed)d_outputs.size()) { msg << "output port number " << my_port << " out of range for " << block; throw std::invalid_argument(msg.str()); |