diff options
author | Eric Blossom | 2010-10-31 20:03:35 -0700 |
---|---|---|
committer | Eric Blossom | 2010-11-10 12:15:43 -0800 |
commit | 8fe7f0fe5fe89f6ec32732dd802608060e973f0d (patch) | |
tree | 9584dac95988639767033f985dd9bb8bdffc9155 /gnuradio-core/src/lib | |
parent | 3d4f2b9a3888c7d5684b70c89f0be3101d43879d (diff) | |
download | gnuradio-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/lib')
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_hier_block2.i | 5 | ||||
-rw-r--r-- | gnuradio-core/src/lib/swig/gnuradio/coerce.scm | 56 |
2 files changed, 31 insertions, 30 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) |