[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 05/07: gnuradio-runtime/hier_block2: Allow
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 05/07: gnuradio-runtime/hier_block2: Allow changing of IO sig in the constructor |
Date: |
Wed, 3 Feb 2016 20:00:59 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch maint
in repository gnuradio.
commit 86b4f7f14b22c29c1eae69994ea2f71d6731740b
Author: Sylvain Munaut <address@hidden>
Date: Thu Jan 28 09:40:47 2016 +0100
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 <address@hidden>
---
gnuradio-runtime/lib/hier_block2_detail.cc | 40 ++++++++++++++++++++++++++++++
gnuradio-runtime/lib/hier_block2_detail.h | 1 +
2 files changed, 41 insertions(+)
diff --git a/gnuradio-runtime/lib/hier_block2_detail.cc
b/gnuradio-runtime/lib/hier_block2_detail.cc
index 60910d0..0d0ddf55 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());
diff --git a/gnuradio-runtime/lib/hier_block2_detail.h
b/gnuradio-runtime/lib/hier_block2_detail.h
index 8c38c37..a5584fe 100644
--- a/gnuradio-runtime/lib/hier_block2_detail.h
+++ b/gnuradio-runtime/lib/hier_block2_detail.h
@@ -71,6 +71,7 @@ namespace gr {
endpoint_vector_t d_outputs; // Single internal endpoint per
external output
basic_block_vector_t d_blocks;
+ void refresh_io_signature();
void connect_input(int my_port, int port, basic_block_sptr block);
void connect_output(int my_port, int port, basic_block_sptr block);
void disconnect_input(int my_port, int port, basic_block_sptr block);
- [Commit-gnuradio] [gnuradio] branch maint updated (11973c6 -> 15b8f49), git, 2016/02/03
- [Commit-gnuradio] [gnuradio] 02/07: grc: escape run command vars for shlex handling (bug #868), git, 2016/02/03
- [Commit-gnuradio] [gnuradio] 07/07: Merge remote-tracking branch 'tom/issue890' into maint, git, 2016/02/03
- [Commit-gnuradio] [gnuradio] 03/07: qtgui: fixes issue #889., git, 2016/02/03
- [Commit-gnuradio] [gnuradio] 01/07: grc: better message port handling for embedded python blocks, git, 2016/02/03
- [Commit-gnuradio] [gnuradio] 06/07: Merge remote-tracking branch 'tom/issue889' into maint, git, 2016/02/03
- [Commit-gnuradio] [gnuradio] 04/07: digital: addresses issue #890., git, 2016/02/03
- [Commit-gnuradio] [gnuradio] 05/07: gnuradio-runtime/hier_block2: Allow changing of IO sig in the constructor,
git <=