#include <gr_flowgraph.h>
#include <gr_io_signature.h>
#include <stdexcept>
-#include <iostream>
+#include <sstream>
#define GR_FLOWGRAPH_DEBUG 0
}
}
- 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
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());
+ }
}
}
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
{
// 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
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
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();
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());
+ }
+ }
}
}
#include <gr_hier_block2_detail.h>
#include <gr_io_signature.h>
#include <stdexcept>
-#include <iostream>
+#include <sstream>
#define GR_HIER_BLOCK2_DETAIL_DEBUG 0
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));
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);
}
<< " -> " << 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));
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);
}
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);
}
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();
}
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();
}
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")
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;
}
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;
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