diff options
Diffstat (limited to 'gnuradio-core/src')
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc | 4 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_flowgraph.cc | 71 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc | 114 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_top_block.i | 3 |
4 files changed, 141 insertions, 51 deletions
diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc index d7f3ffb51..0a73d716d 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc @@ -128,7 +128,7 @@ gr_flat_flowgraph::connect_block_inputs(gr_basic_block_sptr block) { gr_block_sptr grblock = make_gr_block_sptr(block); if (!grblock) - throw std::runtime_error("found non-gr_block"); + throw std::runtime_error("connect_block_inputs found non-gr_block"); // Get its detail and edges that feed into it gr_block_detail_sptr detail = grblock->detail(); @@ -143,7 +143,7 @@ gr_flat_flowgraph::connect_block_inputs(gr_basic_block_sptr block) gr_basic_block_sptr src_block = e->src().block(); gr_block_sptr src_grblock = make_gr_block_sptr(src_block); if (!src_grblock) - throw std::runtime_error("found non-gr_block"); + throw std::runtime_error("connect_block_inputs found non-gr_block"); gr_buffer_sptr src_buffer = src_grblock->detail()->output(src_port); if (GR_FLAT_FLOWGRAPH_DEBUG) diff --git a/gnuradio-core/src/lib/runtime/gr_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flowgraph.cc index 8e96dba75..f4879f085 100644 --- a/gnuradio-core/src/lib/runtime/gr_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flowgraph.cc @@ -27,7 +27,7 @@ #include <gr_flowgraph.h> #include <gr_io_signature.h> #include <stdexcept> -#include <iostream> +#include <sstream> #define GR_FLOWGRAPH_DEBUG 0 @@ -70,7 +70,9 @@ gr_flowgraph::disconnect(const gr_endpoint &src, const gr_endpoint &dst) } } - throw std::invalid_argument("edge to disconnect not found"); + std::stringstream msg; + msg << "cannot disconnect edge " << gr_edge(src, dst) << ", not found"; + throw std::invalid_argument(msg.str()); } void @@ -93,8 +95,13 @@ gr_flowgraph::validate() noutputs = used_ports.size(); check_contiguity(*p, used_ports, false); // outputs - if (!((*p)->check_topology(ninputs, noutputs))) - throw std::runtime_error("check topology failed"); + if (!((*p)->check_topology(ninputs, noutputs))) { + std::stringstream msg; + msg << "check topology failed on " << (*p) + << " using ninputs=" << ninputs + << ", noutputs=" << noutputs; + throw std::runtime_error(msg.str()); + } } } @@ -109,10 +116,22 @@ gr_flowgraph::clear() void gr_flowgraph::check_valid_port(gr_io_signature_sptr sig, int port) { - if (port < 0) - throw std::invalid_argument("negative port number"); - if (sig->max_streams() >= 0 && port >= sig->max_streams()) - throw std::invalid_argument("port number exceeds max"); + std::stringstream msg; + + if (port < 0) { + msg << "negative port number " << port << " is invalid"; + throw std::invalid_argument(msg.str()); + } + + int max = sig->max_streams(); + if (max >= 0 && port >= max) { + msg << "port number " << port << " exceeds max of "; + if (max == 0) + msg << "(none)"; + else + msg << max-1; + throw std::invalid_argument(msg.str()); + } } void @@ -120,8 +139,11 @@ gr_flowgraph::check_dst_not_used(const gr_endpoint &dst) { // A destination is in use if it is already on the edge list for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) - if (p->dst() == dst) - throw std::invalid_argument("dst already in use"); + if (p->dst() == dst) { + std::stringstream msg; + msg << "destination already in use by edge " << (*p); + throw std::invalid_argument(msg.str()); + } } void @@ -130,8 +152,12 @@ gr_flowgraph::check_type_match(const gr_endpoint &src, const gr_endpoint &dst) int src_size = src.block()->output_signature()->sizeof_stream_item(src.port()); int dst_size = dst.block()->input_signature()->sizeof_stream_item(dst.port()); - if (src_size != dst_size) - throw std::invalid_argument("itemsize mismatch between src and dst"); + if (src_size != dst_size) { + std::stringstream msg; + msg << "itemsize mismatch: " << src << " using " << src_size + << ", " << dst << " using " << dst_size; + throw std::invalid_argument(msg.str()); + } } gr_basic_block_vector_t @@ -197,6 +223,8 @@ gr_flowgraph::check_contiguity(gr_basic_block_sptr block, const std::vector<int> &used_ports, bool check_inputs) { + std::stringstream msg; + gr_io_signature_sptr sig = check_inputs ? block->input_signature() : block->output_signature(); @@ -206,14 +234,23 @@ gr_flowgraph::check_contiguity(gr_basic_block_sptr block, if (nports == 0) { if (min_ports == 0) return; - else - throw std::runtime_error("insufficient ports"); + else { + msg << block << ": insufficient connected " + << (check_inputs ? "input ports " : "output ports ") + << "(" << min_ports+1 << " needed, " << nports+1 << " connected)"; + throw std::runtime_error(msg.str()); + } } if (used_ports[nports-1]+1 != nports) { - for (int i = 0; i < nports; i++) - if (used_ports[i] != i) - throw std::runtime_error("missing input assignment"); + for (int i = 0; i < nports; i++) { + if (used_ports[i] != i) { + msg << block << ": missing connection " + << (check_inputs ? "to input port " : "from output port ") + << i; + throw std::runtime_error(msg.str()); + } + } } } diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index e1b11205a..1412a284c 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -26,7 +26,7 @@ #include <gr_hier_block2_detail.h> #include <gr_io_signature.h> #include <stdexcept> -#include <iostream> +#include <sstream> #define GR_HIER_BLOCK2_DETAIL_DEBUG 0 @@ -48,12 +48,14 @@ void gr_hier_block2_detail::connect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port) { + std::stringstream msg; + if (GR_HIER_BLOCK2_DETAIL_DEBUG) std::cout << "connecting: " << gr_endpoint(src, src_port) << " -> " << gr_endpoint(dst, dst_port) << std::endl; if (src.get() == dst.get()) - throw std::invalid_argument("src and destination blocks cannot be the same"); + throw std::invalid_argument("connect: src and destination blocks cannot be the same"); gr_hier_block2_sptr src_block(boost::dynamic_pointer_cast<gr_hier_block2, gr_basic_block>(src)); gr_hier_block2_sptr dst_block(boost::dynamic_pointer_cast<gr_hier_block2, gr_basic_block>(dst)); @@ -74,15 +76,21 @@ gr_hier_block2_detail::connect(gr_basic_block_sptr src, int src_port, int max_port; if (src.get() == d_owner) { max_port = src->input_signature()->max_streams(); - if ((max_port != -1 && (src_port >= max_port)) || src_port < 0) - throw std::invalid_argument("source port out of range"); + if ((max_port != -1 && (src_port >= max_port)) || src_port < 0) { + msg << "source port " << src_port << " out of range for " << src; + throw std::invalid_argument(msg.str()); + } + return connect_input(src_port, dst_port, dst); } if (dst.get() == d_owner) { max_port = dst->output_signature()->max_streams(); - if ((max_port != -1 && (dst_port >= max_port)) || dst_port < 0) - throw std::invalid_argument("source port out of range"); + if ((max_port != -1 && (dst_port >= max_port)) || dst_port < 0) { + msg << "destination port " << dst_port << " out of range for " << dst; + throw std::invalid_argument(msg.str()); + } + return connect_output(dst_port, src_port, src); } @@ -101,7 +109,7 @@ gr_hier_block2_detail::disconnect(gr_basic_block_sptr src, int src_port, << " -> " << gr_endpoint(dst, dst_port) << std::endl; if (src.get() == dst.get()) - throw std::invalid_argument("src and destination blocks cannot be the same"); + throw std::invalid_argument("disconnect: source and destination blocks cannot be the same"); gr_hier_block2_sptr src_block(boost::dynamic_pointer_cast<gr_hier_block2, gr_basic_block>(src)); gr_hier_block2_sptr dst_block(boost::dynamic_pointer_cast<gr_hier_block2, gr_basic_block>(dst)); @@ -128,14 +136,22 @@ gr_hier_block2_detail::disconnect(gr_basic_block_sptr src, int src_port, d_fg->disconnect(src, src_port, dst, dst_port); } +// FIXME: ticket:161 will be implemented here void gr_hier_block2_detail::connect_input(int my_port, int port, gr_basic_block_sptr block) { - if (my_port < 0 || my_port >= (signed)d_inputs.size()) - throw std::invalid_argument("input port number out of range"); + std::stringstream msg; + + 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()); + } - if (d_inputs[my_port].block()) - throw std::invalid_argument("input port in use"); + if (d_inputs[my_port].block()) { + msg << "external input port " << my_port << " already wired to " + << d_inputs[my_port]; + throw std::invalid_argument(msg.str()); + } d_inputs[my_port] = gr_endpoint(block, port); } @@ -143,11 +159,18 @@ gr_hier_block2_detail::connect_input(int my_port, int port, gr_basic_block_sptr void gr_hier_block2_detail::connect_output(int my_port, int port, gr_basic_block_sptr block) { - if (my_port < 0 || my_port >= (signed)d_outputs.size()) - throw std::invalid_argument("output port number out of range"); + std::stringstream msg; - if (d_outputs[my_port].block()) - throw std::invalid_argument("output port in use"); + 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()); + } + + if (d_outputs[my_port].block()) { + msg << "external output port " << my_port << " already connected from " + << d_outputs[my_port]; + throw std::invalid_argument(msg.str()); + } d_outputs[my_port] = gr_endpoint(block, port); } @@ -155,11 +178,18 @@ gr_hier_block2_detail::connect_output(int my_port, int port, gr_basic_block_sptr void gr_hier_block2_detail::disconnect_input(int my_port, int port, gr_basic_block_sptr block) { - if (my_port < 0 || my_port >= (signed)d_inputs.size()) - throw std::invalid_argument("input port number out of range"); + std::stringstream msg; + + 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()); + } - if (d_inputs[my_port].block() != block) - throw std::invalid_argument("block not assigned to given input, can't disconnect"); + if (d_inputs[my_port].block() != block) { + msg << "block " << block << " not assigned to input " + << my_port << ", can't disconnect"; + throw std::invalid_argument(msg.str()); + } d_inputs[my_port] = gr_endpoint(); } @@ -167,11 +197,18 @@ gr_hier_block2_detail::disconnect_input(int my_port, int port, gr_basic_block_sp void gr_hier_block2_detail::disconnect_output(int my_port, int port, gr_basic_block_sptr block) { - if (my_port < 0 || my_port >= (signed)d_outputs.size()) - throw std::invalid_argument("input port number out of range"); + std::stringstream msg; - if (d_outputs[my_port].block() != block) - throw std::invalid_argument("block not assigned to given output, can't disconnect"); + 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()); + } + + if (d_outputs[my_port].block() != block) { + msg << "block " << block << " not assigned to output " + << my_port << ", can't disconnect"; + throw std::invalid_argument(msg.str()); + } d_outputs[my_port] = gr_endpoint(); } @@ -179,6 +216,8 @@ gr_hier_block2_detail::disconnect_output(int my_port, int port, gr_basic_block_s gr_endpoint gr_hier_block2_detail::resolve_port(int port, bool is_input) { + std::stringstream msg; + if (GR_HIER_BLOCK2_DETAIL_DEBUG) std::cout << "Resolving port " << port << " as an " << (is_input ? "input" : "output") @@ -187,18 +226,28 @@ gr_hier_block2_detail::resolve_port(int port, bool is_input) gr_endpoint result; if (is_input) { - if (port < 0 || port >= (signed)d_inputs.size()) - throw std::runtime_error("input port number out of range"); + if (port < 0 || port >= (signed)d_inputs.size()) { + msg << "resolve_port: input " << port << " is out of range"; + throw std::runtime_error(msg.str()); + } + result = resolve_endpoint(d_inputs[port], true); } else { - if (port < 0 || port >= (signed)d_outputs.size()) - throw std::runtime_error("output port number out of range"); + if (port < 0 || port >= (signed)d_outputs.size()) { + msg << "resolve_port: output " << port << " is out of range"; + throw std::runtime_error(msg.str()); + } + result = resolve_endpoint(d_outputs[port], false); } - if (!result.block()) - throw std::runtime_error("unable to resolve port"); + if (!result.block()) { + msg << "unable to resolve " + << (is_input ? "input port " : "output port ") + << port; + throw std::runtime_error(msg.str()); + } return result; } @@ -206,6 +255,8 @@ gr_hier_block2_detail::resolve_port(int port, bool is_input) gr_endpoint gr_hier_block2_detail::resolve_endpoint(const gr_endpoint &endp, bool is_input) const { + std::stringstream msg; + // Check if endpoint is a leaf node if (boost::dynamic_pointer_cast<gr_block, gr_basic_block>(endp.block())) return endp; @@ -220,8 +271,9 @@ gr_hier_block2_detail::resolve_endpoint(const gr_endpoint &endp, bool is_input) return hier_block2->d_detail->resolve_port(endp.port(), is_input); } - // Shouldn't ever get here - throw std::runtime_error("block is not a valid gr_block or gr_hier_block2!"); + msg << "unable to resolve" << (is_input ? " input " : " output ") + << "endpoint " << endp; + throw std::runtime_error(msg.str()); } void diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.i b/gnuradio-core/src/lib/runtime/gr_top_block.i index d310f2aea..63ceec8b2 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.i +++ b/gnuradio-core/src/lib/runtime/gr_top_block.i @@ -29,7 +29,8 @@ typedef boost::shared_ptr<gr_top_block> gr_top_block_sptr; // Hack to have a Python shim implementation of gr.top_block // that instantiates one of these and passes through calls %rename(top_block_swig) gr_make_top_block; -gr_top_block_sptr gr_make_top_block(const std::string name); +gr_top_block_sptr gr_make_top_block(const std::string name) + throw (std::logic_error); class gr_top_block : public gr_hier_block2 { |