summaryrefslogtreecommitdiff
path: root/gnuradio-core/src
diff options
context:
space:
mode:
authorEric Blossom2010-10-31 20:03:35 -0700
committerEric Blossom2010-11-10 12:15:43 -0800
commit8fe7f0fe5fe89f6ec32732dd802608060e973f0d (patch)
tree9584dac95988639767033f985dd9bb8bdffc9155 /gnuradio-core/src
parent3d4f2b9a3888c7d5684b70c89f0be3101d43879d (diff)
downloadgnuradio-8fe7f0fe5fe89f6ec32732dd802608060e973f0d.tar.gz
gnuradio-8fe7f0fe5fe89f6ec32732dd802608060e973f0d.tar.bz2
gnuradio-8fe7f0fe5fe89f6ec32732dd802608060e973f0d.zip
Cleanup gr:connect and gr:disconnect for Guile.
Rename {dis,}connect to {dis,}primitive_connect in .i file. Update python code to reflect change.
Diffstat (limited to 'gnuradio-core/src')
-rw-r--r--gnuradio-core/src/lib/runtime/gr_hier_block2.i5
-rw-r--r--gnuradio-core/src/lib/swig/gnuradio/coerce.scm56
-rw-r--r--gnuradio-core/src/python/gnuradio/gr/hier_block2.py14
-rw-r--r--gnuradio-core/src/python/gnuradio/gr/top_block.py16
4 files changed, 46 insertions, 45 deletions
diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.i b/gnuradio-core/src/lib/runtime/gr_hier_block2.i
index 1b974fd6b..32b656e24 100644
--- a/gnuradio-core/src/lib/runtime/gr_hier_block2.i
+++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.i
@@ -34,6 +34,11 @@ gr_hier_block2_sptr gr_make_hier_block2(const std::string name,
gr_io_signature_sptr output_signature)
throw (std::runtime_error);
+// Rename connect and disconnect so that we can more easily build a
+// better interface in scripting land.
+%rename(primitive_connect) gr_hier_block2::connect;
+%rename(primitive_disconnect) gr_hier_block2::disconnect;
+
class gr_hier_block2 : public gr_basic_block
{
private:
diff --git a/gnuradio-core/src/lib/swig/gnuradio/coerce.scm b/gnuradio-core/src/lib/swig/gnuradio/coerce.scm
index 2c508c6a4..81bc187a6 100644
--- a/gnuradio-core/src/lib/swig/gnuradio/coerce.scm
+++ b/gnuradio-core/src/lib/swig/gnuradio/coerce.scm
@@ -49,40 +49,36 @@
((false-if-exception (gr:to-hier-block2 block)) => (lambda (x) x))
(else (error "Cannot coerce to a gr_hier_block2: " block))))
-;;; The gr:connect variants
-;;; These work for anything derived from gr_hier_block2
-(define-method (gr:connect hb block)
- (let ((hb (coerce-to-hier-block2 hb))
- (bb (coerce-to-basic-block block)))
- (gr:connect hb bb)))
-(define-method (gr:connect hb (src <gr-endpoint>) (dst <gr-endpoint>))
- (let ((hb (coerce-to-hier-block2 hb)))
- (gr:connect hb (block src) (port src) (block dst) (port dst))))
+;;; Connect one or more block endpoints. An endpoint is either a <gr-endpoint>,
+;;; a 2-list (block port), or a block instance. In the latter case, the port number
+;;; is assumed to be zero.
+;;;
+;;; If multiple arguments are provided, connect will attempt to wire them in series,
+;;; interpreting the endpoints as inputs or outputs as appropriate.
+(define-method (gr:connect hb . points)
+ (dis/connect "connect" gr:primitive-connect hb points))
+
+;;; Disconnect one or more block endpoints...
+(define-method (gr:disconnect hb . points)
+ (dis/connect "disconnect" gr:primitive-disconnect hb points))
-(define-method (gr:connect hb src dst)
+(define (dis/connect name gf hb points)
(let ((hb (coerce-to-hier-block2 hb))
- (src (coerce-to-endpoint src))
- (dst (coerce-to-endpoint dst)))
- (gr:connect hb src dst)))
+ (points (list->vector (map coerce-to-endpoint points))))
-;;; The gr:disconnect variants
-;;; These work for anything derived from gr_hier_block2
-(define-method (gr:disconnect-all hb)
- (let ((hb (coerce-to-hier-block2 hb)))
- (gr:disconnect-all hb)))
+ (define (op2 p0 p1)
+ (gf hb (block p0) (port p0) (block p1) (port p1)))
-(define-method (gr:disconnect hb block)
- (let ((hb (coerce-to-hier-block2 hb))
- (bb (coerce-to-basic-block block)))
- (gr:disconnect hb bb)))
+ (let ((len (vector-length points)))
+ (case len
+ ((0) (error (string-append name " requires at least 1 endpoint; None provided.")))
+ ((1) (gf hb (vector-ref points 0)))
+ (else
+ (let loop ((n 1))
+ (cond ((< n len)
+ (op2 (vector-ref points (1- n)) (vector-ref points n))
+ (loop (1+ n))))))))))
-(define-method (gr:disconnect hb (src <gr-endpoint>) (dst <gr-endpoint>))
- (let ((hb (coerce-to-hier-block2 hb)))
- (gr:disconnect hb (block src) (port src) (block dst) (port dst))))
-(define-method (gr:disconnect hb src dst)
- (let ((hb (coerce-to-hier-block2 hb))
- (src (coerce-to-endpoint src))
- (dst (coerce-to-endpoint dst)))
- (gr:disconnect hb src dst)))
+(export-safely gr:connect gr:disconnect)
diff --git a/gnuradio-core/src/python/gnuradio/gr/hier_block2.py b/gnuradio-core/src/python/gnuradio/gr/hier_block2.py
index 370f8a9d9..debb65d91 100644
--- a/gnuradio-core/src/python/gnuradio/gr/hier_block2.py
+++ b/gnuradio-core/src/python/gnuradio/gr/hier_block2.py
@@ -66,7 +66,7 @@ class hier_block2(object):
raise ValueError, ("connect requires at least one endpoint; %d provided." % (len (points),))
else:
if len(points) == 1:
- self._hb.connect(points[0].to_basic_block())
+ self._hb.primitive_connect(points[0].to_basic_block())
else:
for i in range (1, len (points)):
self._connect(points[i-1], points[i])
@@ -74,8 +74,8 @@ class hier_block2(object):
def _connect(self, src, dst):
(src_block, src_port) = self._coerce_endpoint(src)
(dst_block, dst_port) = self._coerce_endpoint(dst)
- self._hb.connect(src_block.to_basic_block(), src_port,
- dst_block.to_basic_block(), dst_port)
+ self._hb.primitive_connect(src_block.to_basic_block(), src_port,
+ dst_block.to_basic_block(), dst_port)
def _coerce_endpoint(self, endp):
if hasattr(endp, 'to_basic_block'):
@@ -97,10 +97,10 @@ class hier_block2(object):
"""
if len (points) < 1:
- raise ValueError, ("disconnect requires at least two endpoints; %d provided." % (len (points),))
+ raise ValueError, ("disconnect requires at least one endpoint; %d provided." % (len (points),))
else:
if len (points) == 1:
- self._hb.disconnect(points[0].to_basic_block())
+ self._hb.primitive_disconnect(points[0].to_basic_block())
else:
for i in range (1, len (points)):
self._disconnect(points[i-1], points[i])
@@ -108,6 +108,6 @@ class hier_block2(object):
def _disconnect(self, src, dst):
(src_block, src_port) = self._coerce_endpoint(src)
(dst_block, dst_port) = self._coerce_endpoint(dst)
- self._hb.disconnect(src_block.to_basic_block(), src_port,
- dst_block.to_basic_block(), dst_port)
+ self._hb.primitive_disconnect(src_block.to_basic_block(), src_port,
+ dst_block.to_basic_block(), dst_port)
diff --git a/gnuradio-core/src/python/gnuradio/gr/top_block.py b/gnuradio-core/src/python/gnuradio/gr/top_block.py
index 8fe5303c8..1e36d3b48 100644
--- a/gnuradio-core/src/python/gnuradio/gr/top_block.py
+++ b/gnuradio-core/src/python/gnuradio/gr/top_block.py
@@ -118,7 +118,7 @@ class top_block(object):
raise ValueError, ("connect requires at least one endpoint; %d provided." % (len (points),))
else:
if len(points) == 1:
- self._tb.connect(points[0].to_basic_block())
+ self._tb.primitive_connect(points[0].to_basic_block())
else:
for i in range (1, len (points)):
self._connect(points[i-1], points[i])
@@ -126,8 +126,8 @@ class top_block(object):
def _connect(self, src, dst):
(src_block, src_port) = self._coerce_endpoint(src)
(dst_block, dst_port) = self._coerce_endpoint(dst)
- self._tb.connect(src_block.to_basic_block(), src_port,
- dst_block.to_basic_block(), dst_port)
+ self._tb.primitive_connect(src_block.to_basic_block(), src_port,
+ dst_block.to_basic_block(), dst_port)
def _coerce_endpoint(self, endp):
if hasattr(endp, 'to_basic_block'):
@@ -139,14 +139,14 @@ class top_block(object):
raise ValueError("unable to coerce endpoint")
def disconnect(self, *points):
- '''connect requires one or more arguments that can be coerced to endpoints.
+ '''disconnect requires one or more arguments that can be coerced to endpoints.
If more than two arguments are provided, they are disconnected successively.
'''
if len (points) < 1:
- raise ValueError, ("disconnect requires at least two endpoints; %d provided." % (len (points),))
+ raise ValueError, ("disconnect requires at least one endpoint; %d provided." % (len (points),))
else:
if len(points) == 1:
- self._tb.disconnect(points[0].to_basic_block())
+ self._tb.primitive_disconnect(points[0].to_basic_block())
else:
for i in range (1, len (points)):
self._disconnect(points[i-1], points[i])
@@ -154,6 +154,6 @@ class top_block(object):
def _disconnect(self, src, dst):
(src_block, src_port) = self._coerce_endpoint(src)
(dst_block, dst_port) = self._coerce_endpoint(dst)
- self._tb.disconnect(src_block.to_basic_block(), src_port,
- dst_block.to_basic_block(), dst_port)
+ self._tb.primitive_disconnect(src_block.to_basic_block(), src_port,
+ dst_block.to_basic_block(), dst_port)