From df6f365b6b703971efc9f29471e0cf1660938fbf Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Sat, 30 Oct 2010 20:22:54 -0700 Subject: Routines to coerce blocks and connect them --- gnuradio-core/src/lib/swig/gnuradio/coerce.scm | 88 ++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 gnuradio-core/src/lib/swig/gnuradio/coerce.scm (limited to 'gnuradio-core') diff --git a/gnuradio-core/src/lib/swig/gnuradio/coerce.scm b/gnuradio-core/src/lib/swig/gnuradio/coerce.scm new file mode 100644 index 000000000..2c508c6a4 --- /dev/null +++ b/gnuradio-core/src/lib/swig/gnuradio/coerce.scm @@ -0,0 +1,88 @@ +;;; +;;; Copyright 2010 Free Software Foundation, Inc. +;;; +;;; This file is part of GNU Radio +;;; +;;; GNU Radio is free software; you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3, or (at your option) +;;; any later version. +;;; +;;; GNU Radio is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with this program. If not, see . +;;; + +(define-class () + (block #:accessor block #:init-keyword #:block) + (port #:init-value 0 #:accessor port #:init-keyword #:port)) + +(define (gr:ep block port) + (make + #:block (coerce-to-basic-block block) #:port port)) + +(define (coerce-to-endpoint ep) + (cond ((is-a? ep ) ep) + ((false-if-exception (gr:to-basic-block ep)) + => (lambda (x) (gr:ep x 0))) + ((and (pair? ep) (= 2 (length ep)) + (false-if-exception (gr:to-basic-block (car ep)))) + => (lambda (x) (gr:ep x (cadr ep)))) + (else (error "Cannot coerce to an endpoint: " ep)))) + +(define (coerce-to-basic-block block) + (cond ((is-a? block ) block) + ((false-if-exception (gr:to-basic-block block)) => (lambda (x) x)) + (else (error "Cannot coerce to a gr_basic_block: " block)))) + +(define (coerce-to-top-block block) + (cond ((is-a? block ) block) + ((false-if-exception (gr:to-top-block block)) => (lambda (x) x)) + (else (error "Cannot coerce to a gr_top_block: " block)))) + +(define (coerce-to-hier-block2 block) + (cond ((is-a? block ) block) + ((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 ) (dst )) + (let ((hb (coerce-to-hier-block2 hb))) + (gr:connect hb (block src) (port src) (block dst) (port dst)))) + +(define-method (gr:connect hb src dst) + (let ((hb (coerce-to-hier-block2 hb)) + (src (coerce-to-endpoint src)) + (dst (coerce-to-endpoint dst))) + (gr:connect hb src dst))) + +;;; 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-method (gr:disconnect hb block) + (let ((hb (coerce-to-hier-block2 hb)) + (bb (coerce-to-basic-block block))) + (gr:disconnect hb bb))) + +(define-method (gr:disconnect hb (src ) (dst )) + (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))) -- cgit