diff options
author | Eric Blossom | 2010-11-18 22:22:23 -0800 |
---|---|---|
committer | Eric Blossom | 2010-11-18 23:02:55 -0800 |
commit | 6237fafa53938db53a3e2a82b79e80b524dd05db (patch) | |
tree | aa95a9db143c5454ed3b22c87fbc1dcc29797947 /gnuradio-core/src | |
parent | d1d226abdede58231583369047861cd2216489e9 (diff) | |
download | gnuradio-6237fafa53938db53a3e2a82b79e80b524dd05db.tar.gz gnuradio-6237fafa53938db53a3e2a82b79e80b524dd05db.tar.bz2 gnuradio-6237fafa53938db53a3e2a82b79e80b524dd05db.zip |
gr_msg_queue now working correctly from within guile.
Diffstat (limited to 'gnuradio-core/src')
-rw-r--r-- | gnuradio-core/src/guile/tests/00_runtime_ctors.test | 19 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_msg_queue.i | 58 |
2 files changed, 74 insertions, 3 deletions
diff --git a/gnuradio-core/src/guile/tests/00_runtime_ctors.test b/gnuradio-core/src/guile/tests/00_runtime_ctors.test index 0c131f5bd..966d8c909 100644 --- a/gnuradio-core/src/guile/tests/00_runtime_ctors.test +++ b/gnuradio-core/src/guile/tests/00_runtime_ctors.test @@ -32,4 +32,23 @@ ;;; Add test code for all constructors in these files ;;; ;;; ./runtime/gr_hier_block2.h + ;;; ./runtime/gr_msg_queue.h + +(define (equal-message? a b) + (equal? (gr:to-string a) (gr:to-string b))) + +(with-test-prefix "gr:message/gr:msg-queue" + (let ((msg1 (gr:message-from-string "Hello")) + (msg2 (gr:message-from-string "World!")) + (q (gr:msg-queue))) + (pass-if (equal? "Hello" (gr:to-string msg1))) + (pass-if (equal? "World!" (gr:to-string msg2))) + (pass-if (gr:empty-p q)) + (gr:insert-tail q msg1) + (pass-if (not (gr:empty-p q))) + (gr:insert-tail q msg2) + (let ((r1 (gr:delete-head q)) + (r2 (gr:delete-head q))) + (pass-if (equal-message? r1 msg1)) + (pass-if (equal-message? r2 msg2))))) diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.i b/gnuradio-core/src/lib/runtime/gr_msg_queue.i index 5b8fea49f..932747688 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_queue.i +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.i @@ -104,8 +104,60 @@ gr_msg_queue_sptr.delete_head = gr_py_msg_queue__delete_head gr_msg_queue_sptr.insert_tail = gr_py_msg_queue__insert_tail gr_msg_queue_sptr.handle = gr_py_msg_queue__insert_tail %} -#endif +#endif // SWIGPYTHON +/* + * Similar trickery as above, only this time for Guile + */ #ifdef SWIGGUILE -#warning "gr_msg_queue.i: gr_msg_queue_sptr needs to be implemented!" -#endif + +%{ + struct arg_holder { + gr_msg_queue_sptr q; + gr_message_sptr msg; + }; + + void *insert_tail_shim(void *arg) + { + arg_holder *a = (arg_holder *)arg; + a->q->insert_tail(a->msg); + return 0; + } + + void *delete_head_shim(void *arg) + { + arg_holder *a = (arg_holder *)arg; + a->msg = a->q->delete_head(); + return 0; + } +%} + +%inline %{ + + // handle and insert_tail are equivalent + static void handle(gr_msg_queue_sptr q, gr_message_sptr msg) + { + arg_holder a; + a.q = q; + a.msg = msg; + scm_without_guile(insert_tail_shim, (void *) &a); + } + + static void insert_tail(gr_msg_queue_sptr q, gr_message_sptr msg) + { + arg_holder a; + a.q = q; + a.msg = msg; + scm_without_guile(insert_tail_shim, (void *) &a); + } + + static gr_message_sptr delete_head(gr_msg_queue_sptr q) + { + arg_holder a; + a.q = q; + scm_without_guile(delete_head_shim, (void *) &a); + return a.msg; + } +%} + +#endif // SWIGGUILE |