commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r6207 - gnuradio/trunk/gnuradio-core/src/lib/runtime


From: jcorgan
Subject: [Commit-gnuradio] r6207 - gnuradio/trunk/gnuradio-core/src/lib/runtime
Date: Wed, 29 Aug 2007 13:03:41 -0600 (MDT)

Author: jcorgan
Date: 2007-08-29 13:03:41 -0600 (Wed, 29 Aug 2007)
New Revision: 6207

Modified:
   gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc
   gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_flowgraph.cc
   gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc
   gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_top_block.i
Log:
Fixes ticket:172 and ticket:174

Modified: gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc   
2007-08-29 04:26:31 UTC (rev 6206)
+++ gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc   
2007-08-29 19:03:41 UTC (rev 6207)
@@ -128,7 +128,7 @@
 {
   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_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)

Modified: gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_flowgraph.cc
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_flowgraph.cc        
2007-08-29 04:26:31 UTC (rev 6206)
+++ gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_flowgraph.cc        
2007-08-29 19:03:41 UTC (rev 6207)
@@ -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 @@
     }
   }
 
-  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 @@
     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 @@
 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 @@
 {
   // 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 @@
   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 @@
                               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 @@
   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());
+      }
+    }
   }
 }
 

Modified: gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc       
2007-08-29 04:26:31 UTC (rev 6206)
+++ gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc       
2007-08-29 19:03:41 UTC (rev 6207)
@@ -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 @@
 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 @@
   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_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,57 +136,88 @@
   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 (d_inputs[my_port].block())
-    throw std::invalid_argument("input port in use");
+  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()) {
+    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 (d_inputs[my_port].block() != block)
-    throw std::invalid_argument("block not assigned to given input, can't 
disconnect");
+  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) {
+    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")
@@ -187,18 +226,28 @@
   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_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 @@
     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

Modified: gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_top_block.i
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_top_block.i 2007-08-29 
04:26:31 UTC (rev 6206)
+++ gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_top_block.i 2007-08-29 
19:03:41 UTC (rev 6207)
@@ -29,7 +29,8 @@
 // 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
 {





reply via email to

[Prev in Thread] Current Thread [Next in Thread]