From d1d226abdede58231583369047861cd2216489e9 Mon Sep 17 00:00:00 2001
From: Eric Blossom <eb@comsec.com>
Date: Thu, 18 Nov 2010 18:00:58 -0800
Subject: Disable items that require swig directors when building guile
 bindings.

---
 .../src/lib/general/gr_bin_statistics_f.i          |  7 ++++-
 gnuradio-core/src/lib/general/gr_feval.i           | 30 +++++-----------------
 2 files changed, 13 insertions(+), 24 deletions(-)

(limited to 'gnuradio-core/src')

diff --git a/gnuradio-core/src/lib/general/gr_bin_statistics_f.i b/gnuradio-core/src/lib/general/gr_bin_statistics_f.i
index 5cec882f0b..be98a464ba 100644
--- a/gnuradio-core/src/lib/general/gr_bin_statistics_f.i
+++ b/gnuradio-core/src/lib/general/gr_bin_statistics_f.i
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2006 Free Software Foundation, Inc.
+ * Copyright 2006,2010 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -19,6 +19,9 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+// Directors are only supported in Python, Java and C#.  gr_feval_dd uses directors
+#ifdef SWIGPYTHON
+
 GR_SWIG_BLOCK_MAGIC(gr,bin_statistics_f);
 
 gr_bin_statistics_f_sptr
@@ -40,3 +43,5 @@ private:
 public:
   ~gr_bin_statistics_f();
 };
+
+#endif
diff --git a/gnuradio-core/src/lib/general/gr_feval.i b/gnuradio-core/src/lib/general/gr_feval.i
index 843ca3f2a5..c5522805db 100644
--- a/gnuradio-core/src/lib/general/gr_feval.i
+++ b/gnuradio-core/src/lib/general/gr_feval.i
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2006 Free Software Foundation, Inc.
+ * Copyright 2006,2010 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -43,6 +43,9 @@
  */
 
 
+// Directors are only supported in Python, Java and C#
+#ifdef SWIGPYTHON
+
 // Enable SWIG directors for these classes
 %feature("director") gr_py_feval_dd;
 %feature("director") gr_py_feval_cc;
@@ -65,8 +68,8 @@
 //  catch (Swig::DirectorException &e) { std::cerr << e.getMessage();  SWIG_fail; }
 //}
 
-#ifdef SWIGPYTHON
 %{
+
 // class that ensures we acquire and release the Python GIL
 
 class ensure_py_gil_state {
@@ -77,19 +80,6 @@ public:
 };
 
 %}
-#endif
-
-#ifdef SWIGGUILE
-#if 0
-// FIXME: this is a bogus stub, just here so things build
-class ensure_py_gil_state {
-public:
-  ensure_py_gil_state()  { }
-  ~ensure_py_gil_state() { }
-};
-#endif
-#warning "class ensure_py_gil_state needs to be implemented!"
-#endif
 
 /*
  * These are the real C++ base classes, however we don't want these exposed.
@@ -158,9 +148,7 @@ class gr_py_feval_dd : public gr_feval_dd
  public:
   double calleval(double x)
   {
-#ifdef PYTHON
     ensure_py_gil_state _lock;
-#endif
     return eval(x);
   }
 };
@@ -170,9 +158,7 @@ class gr_py_feval_cc : public gr_feval_cc
  public:
   gr_complex calleval(gr_complex x)
   {
-#ifdef PYTHON
     ensure_py_gil_state _lock;
-#endif
     return eval(x);
   }
 };
@@ -182,9 +168,7 @@ class gr_py_feval_ll : public gr_feval_ll
  public:
   long calleval(long x)
   {
-#ifdef PYTHON
     ensure_py_gil_state _lock;
-#endif
     return eval(x);
   }
 };
@@ -194,9 +178,7 @@ class gr_py_feval : public gr_feval
  public:
   void calleval()
   {
-#ifdef PYTHON
     ensure_py_gil_state _lock;
-#endif
     eval();
   }
 };
@@ -218,3 +200,5 @@ long gr_feval_ll_example(gr_feval_ll *f, long x);
 
 %rename(feval_example) gr_feval_example;
 void gr_feval_example(gr_feval *f);
+
+#endif // SWIGPYTHON
-- 
cgit v1.2.3


From 6237fafa53938db53a3e2a82b79e80b524dd05db Mon Sep 17 00:00:00 2001
From: Eric Blossom <eb@comsec.com>
Date: Thu, 18 Nov 2010 22:22:23 -0800
Subject: gr_msg_queue now working correctly from within guile.

---
 .../src/guile/tests/00_runtime_ctors.test          | 19 +++++++
 gnuradio-core/src/lib/runtime/gr_msg_queue.i       | 58 ++++++++++++++++++++--
 2 files changed, 74 insertions(+), 3 deletions(-)

(limited to 'gnuradio-core/src')

diff --git a/gnuradio-core/src/guile/tests/00_runtime_ctors.test b/gnuradio-core/src/guile/tests/00_runtime_ctors.test
index 0c131f5bdf..966d8c9096 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 5b8fea49fe..9327476880 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
-- 
cgit v1.2.3


From 31b5e27fbf72eca257bc4dd548e127ce16eef9ec Mon Sep 17 00:00:00 2001
From: Eric Blossom <eb@comsec.com>
Date: Fri, 19 Nov 2010 00:13:28 -0800
Subject: Enable a couple more tests

---
 gnuradio-core/src/guile/tests/general_ctors.test   | 20 ++++++++++----------
 gnuradio-core/src/lib/general/gr_ofdm_mapper_bcv.i |  2 +-
 2 files changed, 11 insertions(+), 11 deletions(-)

(limited to 'gnuradio-core/src')

diff --git a/gnuradio-core/src/guile/tests/general_ctors.test b/gnuradio-core/src/guile/tests/general_ctors.test
index d09766a95c..ff5ee74fab 100644
--- a/gnuradio-core/src/guile/tests/general_ctors.test
+++ b/gnuradio-core/src/guile/tests/general_ctors.test
@@ -259,18 +259,18 @@
 ;;; ./general/gr_ofdm_frame_acquisition.h
 (pass-if (true? (gr:ofdm-frame-acquisition 1 1 1 #(1+3i 23+5i) 1)))
 
-;;; ./general/gr_ofdm_frame_sink.h FIXME: "No matching method for generic function `ofdm_frame_sink'"
-;; (pass-if (true? (gr:ofdm-frame-sink #(1+3i 23+5i) #('a' 'b') (gr:msg-queue) 1 0.25 0)))
+;;; ./general/gr_ofdm_frame_sink.h
+(pass-if (true? (gr:ofdm-frame-sink #(1+3i 23+5i) #(0 1) (gr:msg-queue) 128 0.25 0)))
 
 ;;; ./general/gr_ofdm_insert_preamble.h FIXME: "Wrong type argument in position ~A: ~S"
-;; (pass-if (true? (gr:ofdm-insert-preamble 1 #(#(1+3i 23+5i)))))
-
-;;; ./general/gr_ofdm_mapper_bcv.h FIXME: Wrong type argument in position ~A:
-;; gr_ofdm_mapper_bcv (const std::vector<gr_complex> &constellation,
-;;                       unsigned int msgq_limit,
-;;                       unsigned int bits_per_symbol,
-;;                       unsigned int fft_length);
-;; (pass-if (true? (gr:ofdm-mapper-bcv #(1+3i 23+5i) 1 1 1)))
+;;;                                     WONTFIX: Need vector<vector<complex<float>>>
+;;(pass-if (true? (gr:ofdm-insert-preamble 2 #(#(1+3i 23+5i) #(1+3i 23+5i)))))
+
+;;; ./general/gr_ofdm_mapper_bcv.h
+(pass-if (true? (gr:ofdm-mapper-bcv #(0+1i 0-1i) 1 100 128)))
+(pass-if-throw "confirm throw gr:ofdm-mapper-bcv" #t
+  (true? (gr:ofdm-mapper-bcv #(0+1i 0-1i) 1 10 128)))
+
 
 ;;; ./general/gr_ofdm_sampler.h
 (pass-if (true? (gr:ofdm-sampler 1 1 1)))
diff --git a/gnuradio-core/src/lib/general/gr_ofdm_mapper_bcv.i b/gnuradio-core/src/lib/general/gr_ofdm_mapper_bcv.i
index 30c6929262..3850220bad 100644
--- a/gnuradio-core/src/lib/general/gr_ofdm_mapper_bcv.i
+++ b/gnuradio-core/src/lib/general/gr_ofdm_mapper_bcv.i
@@ -26,7 +26,7 @@ gr_ofdm_mapper_bcv_sptr
 gr_make_ofdm_mapper_bcv (const std::vector<gr_complex> &constellation,
 			 unsigned int msgq_limit,
 			 unsigned int bits_per_symbol, 
-			 unsigned int fft_length);
+			 unsigned int fft_length) throw(std::exception);
 
 
 class gr_ofdm_mapper_bcv : public gr_sync_block
-- 
cgit v1.2.3


From 37a1e931c11f2ba0bdd8ef9ff07c6710e83c6139 Mon Sep 17 00:00:00 2001
From: Eric Blossom <eb@comsec.com>
Date: Fri, 19 Nov 2010 00:47:07 -0800
Subject: Enable more tests

---
 gnuradio-core/src/guile/tests/gengen_ctors.test | 18 ++++-----
 gnuradio-core/src/guile/tests/io_ctors.test     | 49 ++++++++++++-------------
 2 files changed, 33 insertions(+), 34 deletions(-)

(limited to 'gnuradio-core/src')

diff --git a/gnuradio-core/src/guile/tests/gengen_ctors.test b/gnuradio-core/src/guile/tests/gengen_ctors.test
index 43996c0012..6e1213c630 100644
--- a/gnuradio-core/src/guile/tests/gengen_ctors.test
+++ b/gnuradio-core/src/guile/tests/gengen_ctors.test
@@ -198,16 +198,16 @@
 (pass-if (true? (gr:multiply-ss 1)))
 
 ;;; ./gengen/gr_mute_cc.h FIXME: not found
-;; (pass-if (true? (gr:mute-cc false)))
+(pass-if (true? (gr:mute-cc #f)))
 
 ;;; ./gengen/gr_mute_ff.h FIXME: not found
-;;(pass-if (true? (gr:mute-ff false)))
+(pass-if (true? (gr:mute-ff #f)))
 
 ;;; ./gengen/gr_mute_ii.h FIXME: not found
-;; (pass-if (true? (gr:mute-ii false)))
+(pass-if (true? (gr:mute-ii #f)))
 
 ;;; ./gengen/gr_mute_ss.h FIXME: not found
-;; (pass-if (true? (gr:mute-ss false)))
+(pass-if (true? (gr:mute-ss #f)))
 
 ;;; ./gengen/gr_noise_source_c.h
 (pass-if (true? (gr:noise-source-c 1 0 3021)))
@@ -318,19 +318,19 @@
 (pass-if (true? (gr:vector-sink-s 1)))
 
 ;;; ./gengen/gr_vector_source_b.h
-;; (pass-if (true? (gr:vector-source-b #(1 2) false 1)))
+;; (pass-if (true? (gr:vector-source-b #(1 2) #f 1)))
 
 ;; ;;; ./gengen/gr_vector_source_c.h
-;; (pass-if (true? (gr:vector-source-c #(1+3i 23+5i) false 1)))
+;; (pass-if (true? (gr:vector-source-c #(1+3i 23+5i) #f 1)))
 
 ;; ;;; ./gengen/gr_vector_source_f.h
-;; (pass-if (true? (gr:vector-source-f #(1.0 2.0) false 1)))
+;; (pass-if (true? (gr:vector-source-f #(1.0 2.0) #f 1)))
 
 ;;; ./gengen/gr_vector_source_i.h
-;; (pass-if (true? (gr:vector-source-i #(1 2) false 1)))
+;; (pass-if (true? (gr:vector-source-i #(1 2) #f 1)))
 
 ;;; ./gengen/gr_vector_source_s.h FIXME: not found
-;; (pass-if (true? (gr:vector-source-s #(1 2) false 1)))
+;; (pass-if (true? (gr:vector-source-s #(1 2) #f 1)))
 
 ;;; ./gengen/gr_xor_bb.h
 (pass-if (true? (gr:xor-bb)))
diff --git a/gnuradio-core/src/guile/tests/io_ctors.test b/gnuradio-core/src/guile/tests/io_ctors.test
index 99c84ae372..1c5c9a771f 100644
--- a/gnuradio-core/src/guile/tests/io_ctors.test
+++ b/gnuradio-core/src/guile/tests/io_ctors.test
@@ -37,20 +37,21 @@
 ;;;
 
 ;;; ./io/gr_file_descriptor_sink.h
-(pass-if (true? (gr:file-descriptor-sink 1 1)))
+(pass-if (true? (gr:file-descriptor-sink 1 (dup 1))))
 
-;;; ./io/gr_file_descriptor_source.h  FIXME: not found
-;; (pass-if (true? (gr:file-descriptor-source 1 1 #f)))
+;;; ./io/gr_file_descriptor_source.h
+(pass-if (true? (gr:file-descriptor-source 1 (dup 0) #f)))
 
 ;;; ./io/gr_file_sink.h
 (pass-if (true? (gr:file-sink 1 "foo")))
 
-;;; ./io/gr_file_source.h FIXME: not found
-;; (pass-if (true? (gr:file-source 1 "foo" #f)))
+;;; ./io/gr_file_source.h
+(pass-if (true? (gr:file-source 1 "foo" #f)))
+(rm-foo)
 
-;;; ./io/gr_histo_sink_f.h FIXME: not found
+;;; ./io/gr_histo_sink_f.h
 ;; gr_make_histo_sink_f (gr_msg_queue_sptr msgq);
-;; (pass-if (true? (gr:histo-sink-f 1)))
+(pass-if (true? (gr:histo-sink-f (gr:msg-queue))))
 
 ;;; ./io/gr_message_sink.h
 (pass-if (true? (gr:message-sink 1 (gr:msg-queue) #f)))
@@ -59,25 +60,23 @@
 (pass-if (true? (gr:message-source 1 1)))
 (pass-if (true? (gr:message-source 1 (gr:msg-queue))))
 
-;;; ./io/gr_oscope_sink_f.h FIXME: not found
-;; _oscope_sink_x (const std::string name, gr_io_signature_sptr input_sig,
-;;                     double sample_rate);
-;; (pass-if (true? (gr:oscope-sink-f "foo" 1 1)))
+;;; ./io/gr_oscope_sink_f.h
+(pass-if (true? (gr:oscope-sink-f 1000 (gr:msg-queue))))
 
-;;; ./io/gr_oscope_sink_x.h FIXME: not found
-;; gr_oscope_sink_x (const std::string name, gr_io_signature_sptr input_sig,
-;;                     double sampling_rate);
-;; (pass-if (true? (gr:oscope_sink_x "foo" 1 1)))
+;;; ./io/gr_udp_sink.h
+(pass-if (true? (gr:udp-sink 4 "localhost" 80 1472 #f)))
+(pass-if-throw "confirm throw gr:udp-sink" #t
+  (true? (gr:udp-sink 4 "localhostx" 80 1472 #f)))
 
-;;; ./io/gr_udp_sink.h FIXME: not found
-;; (pass-if (true? (gr:udp-sink 1 "foo" 1472 #t)))
+;;; ./io/gr_udp_source.h
+(pass-if (true? (gr:udp-source 4 "localhost" 0 1472 #f #t)))
+(pass-if-throw "confirm throw gr:udp-sink" #t
+  (true? (gr:udp-source 4 "localhostx" 0 1472 #f #t)))
 
-;;; ./io/gr_udp_source.h FIXME: not found
-;; (pass-if (true? (gr:message-source 0 "foo" 0 1472 #t #t)))
-
-;;; ./io/gr_wavfile_sink.h FIXME: not found
-;; (pass-if (true? (gr:message-source "foo" 1 1 1)))
-
-;;; ./io/gr_wavfile_source.h FIXME: not found
-;; (pass-if (true? (gr:message-source "foo" #f)))
+;;; ./io/gr_wavfile_sink.h
+(pass-if (true? (gr:wavfile-sink "foo" 2 48000 16)))
 
+;;; ./io/gr_wavfile_source.h WONTFIX: buggy source won't accept file
+;;;                                   created immediately above.
+;;(pass-if (true? (gr:wavfile-source "foo" #f)))
+(rm-foo)
-- 
cgit v1.2.3


From 6551f537ed235bbb0ddfadb50744ea3b3fcbc2e6 Mon Sep 17 00:00:00 2001
From: Eric Blossom <eb@comsec.com>
Date: Sat, 20 Nov 2010 16:30:43 -0800
Subject: Add guile shim to gr_top_block::wait that exits guile mode before
 blocking.

---
 gnuradio-core/src/guile/gnuradio/runtime-shim.scm | 13 +++++++-
 gnuradio-core/src/lib/runtime/gr_top_block.i      | 37 ++++++++++++++++++++---
 2 files changed, 44 insertions(+), 6 deletions(-)

(limited to 'gnuradio-core/src')

diff --git a/gnuradio-core/src/guile/gnuradio/runtime-shim.scm b/gnuradio-core/src/guile/gnuradio/runtime-shim.scm
index c08d3947c9..105f4ddb86 100644
--- a/gnuradio-core/src/guile/gnuradio/runtime-shim.scm
+++ b/gnuradio-core/src/guile/gnuradio/runtime-shim.scm
@@ -86,4 +86,15 @@
 		  (loop (1+ n))))))))))
 
 
-(export-safely <gr-endpoint> gr:ep gr:connect gr:disconnect)
+
+
+(define-method (gr:run (self <gr-top-block-sptr>))
+  (gr:start self)
+  (gr:wait self))
+
+(define-method (gr:wait (self <gr-top-block-sptr>))
+  ;; FIXME Set up SIGINT handling here...
+  (gr:top-block-wait-unlocked self))
+
+
+(export-safely <gr-endpoint> gr:ep gr:connect gr:disconnect gr:run gr:wait)
diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.i b/gnuradio-core/src/lib/runtime/gr_top_block.i
index f18d8890b2..90fa18b94d 100644
--- a/gnuradio-core/src/lib/runtime/gr_top_block.i
+++ b/gnuradio-core/src/lib/runtime/gr_top_block.i
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2007,2008 Free Software Foundation, Inc.
+ * Copyright 2007,2008,2010 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -42,8 +42,8 @@ public:
 
   void start() throw (std::runtime_error);
   void stop();
-  void wait();
-  void run() throw (std::runtime_error);
+  //void wait();
+  //void run() throw (std::runtime_error);
   void lock();
   void unlock() throw (std::runtime_error);
   void dump();
@@ -71,6 +71,33 @@ void top_block_wait_unlocked(gr_top_block_sptr r) throw (std::runtime_error)
 
 #endif
 
-#ifdef SWIG_GUILE
-#warning "gr_top_block.i: top_block_run_unlocked needs to be implemented!"
+#ifdef SWIGGUILE
+
+%{
+  struct tb_arg_holder {
+    gr_top_block_sptr	tb;
+  };
+
+  static void *
+  tb_wait_shim(void *arg)
+  {
+    tb_arg_holder *a = (tb_arg_holder *)arg;
+    a->tb->wait();
+    return 0;
+  }
+
+%}
+
+%inline %{
+
+  static void
+  top_block_wait_unlocked(gr_top_block_sptr r) throw (std::runtime_error)
+  {
+    tb_arg_holder a;
+    a.tb = r;
+    scm_without_guile(tb_wait_shim, (void *) &a);
+  }
+
+%}
+
 #endif
-- 
cgit v1.2.3


From 5c91f873301a6eca0895788b0b03862fc0060a19 Mon Sep 17 00:00:00 2001
From: Eric Blossom <eb@comsec.com>
Date: Sat, 20 Nov 2010 16:34:04 -0800
Subject: Minor tweaks: comments, static

---
 gnuradio-core/src/lib/runtime/gr_msg_queue.i | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

(limited to 'gnuradio-core/src')

diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.i b/gnuradio-core/src/lib/runtime/gr_msg_queue.i
index 9327476880..c9214bef32 100644
--- a/gnuradio-core/src/lib/runtime/gr_msg_queue.i
+++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.i
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2005,2009 Free Software Foundation, Inc.
+ * Copyright 2005,2009,2010 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -117,14 +117,16 @@ gr_msg_queue_sptr.handle = gr_py_msg_queue__insert_tail
     gr_message_sptr	msg;
   };
 
-  void *insert_tail_shim(void *arg)
+  static 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)
+  static void *
+  delete_head_shim(void *arg)
   {
     arg_holder *a = (arg_holder *)arg;
     a->msg = a->q->delete_head();
@@ -135,7 +137,8 @@ gr_msg_queue_sptr.handle = gr_py_msg_queue__insert_tail
 %inline %{
 
   // handle and insert_tail are equivalent
-  static void handle(gr_msg_queue_sptr q, gr_message_sptr msg)
+  static void
+  handle(gr_msg_queue_sptr q, gr_message_sptr msg)
   {
     arg_holder	a;
     a.q = q;
@@ -143,7 +146,8 @@ gr_msg_queue_sptr.handle = gr_py_msg_queue__insert_tail
     scm_without_guile(insert_tail_shim, (void *) &a);
   }
 
-  static void insert_tail(gr_msg_queue_sptr q, gr_message_sptr msg)
+  static void
+  insert_tail(gr_msg_queue_sptr q, gr_message_sptr msg)
   {
     arg_holder	a;
     a.q = q;
@@ -151,7 +155,8 @@ gr_msg_queue_sptr.handle = gr_py_msg_queue__insert_tail
     scm_without_guile(insert_tail_shim, (void *) &a);
   }
 
-  static gr_message_sptr delete_head(gr_msg_queue_sptr q)
+  static gr_message_sptr
+  delete_head(gr_msg_queue_sptr q)
   {
     arg_holder	a;
     a.q = q;
-- 
cgit v1.2.3


From da6620e6a3d23b78e7231ba70b914974988d3ae1 Mon Sep 17 00:00:00 2001
From: Eric Blossom <eb@comsec.com>
Date: Sat, 20 Nov 2010 18:27:04 -0800
Subject: Add guile SIGINT handler to gr:wait.

---
 Guile-TODO                                        |  4 +--
 gnuradio-core/src/guile/gnuradio/runtime-shim.scm | 35 +++++++++++++++++++++--
 2 files changed, 34 insertions(+), 5 deletions(-)

(limited to 'gnuradio-core/src')

diff --git a/Guile-TODO b/Guile-TODO
index 93d96fa179..6f770c936e 100644
--- a/Guile-TODO
+++ b/Guile-TODO
@@ -1,7 +1,5 @@
 In no particular order:
 
-2)  SIGINT handling in gr_top_block::wait
-
 3)  Ensure that all 4 combinations of
     --{enable,disable}-python --{enable,disable}-guile
     work correctly.
@@ -72,6 +70,8 @@ These are done:
 1)  [DONE] Ensure that libraries containing swig generated code are regenerated
     when any relevant .i file is touched.
 
+2)  [DONE] SIGINT handling in gr_top_block::wait
+
 4)  [DONE] Fix GR_SWIG_BLOCK_MAGIC so that in the guile case we don't map all
     the constructors into the same name.  E.g. audio_alsa_sink -> sink.
     (Causes problem when multiple gr-* modules are used.)
diff --git a/gnuradio-core/src/guile/gnuradio/runtime-shim.scm b/gnuradio-core/src/guile/gnuradio/runtime-shim.scm
index 105f4ddb86..bba7026708 100644
--- a/gnuradio-core/src/guile/gnuradio/runtime-shim.scm
+++ b/gnuradio-core/src/guile/gnuradio/runtime-shim.scm
@@ -19,6 +19,7 @@
 
 (define-module (gnuradio runtime-shim)
   #:use-module (oop goops)
+  #:use-module (ice-9 threads)
   #:use-module (gnuradio gnuradio_core_runtime)
   #:duplicates (merge-generics replace check))
 
@@ -92,9 +93,37 @@
   (gr:start self)
   (gr:wait self))
 
-(define-method (gr:wait (self <gr-top-block-sptr>))
-  ;; FIXME Set up SIGINT handling here...
-  (gr:top-block-wait-unlocked self))
+
+(define-method (gr:wait (tb <gr-top-block-sptr>))
+
+  (define (sigint-handler sig)
+    ;;(display "\nSIGINT!\n" (current-error-port))
+    ;; tell flow graph to stop
+    (gr:stop tb))
+
+  (let ((old-handler #f))
+    (dynamic-wind
+
+	;; Called at entry
+	(lambda ()
+	  ;; Install SIGINT handler
+	  (set! old-handler (sigaction SIGINT sigint-handler)))
+
+	;; Protected thunk
+	(lambda ()
+	  (let ((waiter (begin-thread (gr:top-block-wait-unlocked tb))))
+	    (join-thread waiter)
+	    ;;(display "\nAfter join-thread\n" (current-error-port))
+	    ))
+
+	;; Called at exit
+	(lambda ()
+	  ;; Restore SIGINT handler
+	  (if (not (car old-handler))
+	      ;; restore original C handler
+	      (sigaction SIGINT #f)
+	      ;; restore Scheme handler, SIG_IGN or SIG_DFL
+	      (sigaction SIGINT (car old-handler) (cdr old-handler)))))))
 
 
 (export-safely <gr-endpoint> gr:ep gr:connect gr:disconnect gr:run gr:wait)
-- 
cgit v1.2.3


From ff62557a42b6ce89a711f9d0603c0fe52a891ed8 Mon Sep 17 00:00:00 2001
From: Eric Blossom <eb@comsec.com>
Date: Sun, 21 Nov 2010 16:01:48 -0800
Subject: Make Guile bindings work with --with-gnuradio-core et al.

---
 Guile-TODO                                 |   6 +-
 config/grc_build.m4                        |   1 +
 config/grc_gnuradio_core.m4                |   2 +
 configure.ac                               |   1 +
 gnuradio-core/gnuradio-core.pc.in          |   1 +
 gnuradio-core/src/guile/run_guile_tests.in |  12 +--
 setup_guile_test_env.in                    | 129 ++++++++++++++++++++++-------
 7 files changed, 115 insertions(+), 37 deletions(-)

(limited to 'gnuradio-core/src')

diff --git a/Guile-TODO b/Guile-TODO
index bd81e96b46..7cbf5ac609 100644
--- a/Guile-TODO
+++ b/Guile-TODO
@@ -34,9 +34,6 @@ In no particular order:
 
 13) Change guile libnames to libguile-gnuradio-<module-name>
 
-14) Add support to setup_guile_test_env.in for
-    "withlibs", OS/X (DYLD_LIBRARY_PATH), windows (PATH)
-
 15) Rewrite gr-run-waveform as C/C++ code that embeds guile.
     See if we can't statically link libguile into this.
     Will need to figure out which packages provide libguile.a.
@@ -84,4 +81,7 @@ These are done:
 8)  [DONE] Fix gr_message_{sink,source} so that they work under guile.
     (Not sure if I disabled one or both of these...)
 
+14) [DONE] Add support to setup_guile_test_env.in for
+    "withlibs", OS/X (DYLD_LIBRARY_PATH), windows (PATH)
+
 17) [DONE] Get std::vector< std::complex<float> > working
diff --git a/config/grc_build.m4 b/config/grc_build.m4
index 77b59db6bd..121c4feb63 100644
--- a/config/grc_build.m4
+++ b/config/grc_build.m4
@@ -259,6 +259,7 @@ AC_DEFUN([_GRC_BUILD_CONDITIONAL],[
 	    GRC_ADD_TO_LIST($3, PYDIRPATH, ":")
 	    GRC_ADD_TO_LIST($3, SWIGDIRPATH, ":")
 	    GRC_ADD_TO_LIST($3, LIBDIRPATH, ":")
+	    GRC_ADD_TO_LIST($3, GUILE_LOAD_PATH, ":")
 	    AC_MSG_RESULT([Component $1 will be included from a pre-installed library and includes.])
 	    $3[_with]=yes
 	else
diff --git a/config/grc_gnuradio_core.m4 b/config/grc_gnuradio_core.m4
index 8cbba49efa..ff3df8c600 100644
--- a/config/grc_gnuradio_core.m4
+++ b/config/grc_gnuradio_core.m4
@@ -26,6 +26,8 @@ AC_DEFUN([GRC_GNURADIO_CORE],[
 	gnuradio_core_I="$gnuradio_core_SWIGDIRPATH/gnuradio.i"
 	gnuradio_core_SWIG_INCLUDES="-I$gnuradio_core_SWIGDIRPATH"
 	gnuradio_core_PYDIRPATH=$pythondir
+	gnuradio_core_GUILE_LOAD_PATH="`pkg-config --variable=guile_load_path gnuradio-core`"
+	gnuradio_core_LIBDIRPATH="`pkg-config --variable=libdir gnuradio-core`"
     ])
 
     dnl Don't do gnuradio-core if gruel skipped
diff --git a/configure.ac b/configure.ac
index fe32ccf5e4..00527d3837 100644
--- a/configure.ac
+++ b/configure.ac
@@ -411,6 +411,7 @@ AC_SUBST(with_SWIG_INCLUDES)
 AC_SUBST(with_PYDIRPATH)
 AC_SUBST(with_SWIGDIRPATH)
 AC_SUBST(with_LIBDIRPATH)
+AC_SUBST(with_GUILE_LOAD_PATH)
 
 # Local files tweaked by AC
 AC_CONFIG_FILES([\
diff --git a/gnuradio-core/gnuradio-core.pc.in b/gnuradio-core/gnuradio-core.pc.in
index 5d743a4e90..40c26a129d 100644
--- a/gnuradio-core/gnuradio-core.pc.in
+++ b/gnuradio-core/gnuradio-core.pc.in
@@ -2,6 +2,7 @@ prefix=@prefix@
 exec_prefix=@exec_prefix@
 libdir=@libdir@
 includedir=@includedir@/gnuradio
+guile_load_path=@prefix@/share/guile/site
 
 Name: gnuradio-core
 Description: GNU Software Radio toolkit
diff --git a/gnuradio-core/src/guile/run_guile_tests.in b/gnuradio-core/src/guile/run_guile_tests.in
index 3aca7bdb09..61968065e8 100644
--- a/gnuradio-core/src/guile/run_guile_tests.in
+++ b/gnuradio-core/src/guile/run_guile_tests.in
@@ -2,14 +2,16 @@
 
 . @top_builddir@/setup_guile_test_env
 
+# Since we're in gnuradio-core, we don't need to add anything,
+# but we do need to call add_local_paths to set everything up
+
 # 1st argument is absolute path to hand coded guile source directory
 # 2nd argument is absolute path to component C++ shared library build directory
 # 3nd argument is absolute path to component SWIG build directory
 
-# We're in gnuradio-core, we don't need these
-# add_local_paths \
-#    "" \
-#    "" \
-#    ""
+add_local_paths \
+    "" \
+    "" \
+    ""
 
 @GUILE@ -e main -c '(use-modules (gnuradio test-suite guile-test))' -t @srcdir@/tests
diff --git a/setup_guile_test_env.in b/setup_guile_test_env.in
index ee7e9ea466..f143685c0c 100644
--- a/setup_guile_test_env.in
+++ b/setup_guile_test_env.in
@@ -1,16 +1,26 @@
-#!/bin/sh
+#
+# 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 <http://www.gnu.org/licenses/>.
+#
 
 # This is sourced by run_guile_tests to establish the environment
 # variables required to run the tests in the build tree.
 
-abs_top_srcdir=@abs_top_srcdir@
-abs_top_builddir=@abs_top_builddir@
-
-
-# FIXME add in OS/X DYLD_LIBRARY_PATH
-# FIXME add in cywin*/win*/mingw* PATH
-# FIXME add in withdirs
-
+# add_local_paths is the only "public" function in this file
 
 # 1st argument is absolute path to hand coded guile source directory
 # 2nd argument is absolute path to component C++ shared library build directory
@@ -22,12 +32,23 @@ function add_local_paths(){
     echo "$0: requires 3 args" 1>&2
     exit 1
   fi
-  [ -n "$1" ] && prepend GUILE_LOAD_PATH "$1"
-  [ -n "$2" ] && prepend LTDL_LIBRARY_PATH "$2/.libs"
-  [ -n "$3" -a "$2" != "$3" ] && prepend LTDL_LIBRARY_PATH "$3/.libs"
-  [ -n "$3" ] && prepend GUILE_LOAD_PATH "$3"
+
+  # Add local dirs to the front
+  prepend_to_guile_load_path "$1"
+  prepend_to_libpath "$2/.libs"
+  [ "$2" != "$3" ] && prepend_to_libpath "$3/.libs"
+  prepend_to_guile_load_path "$3"
+
+  # Add withdirs to the end
+  append_to_guile_load_path "@with_GUILE_LOAD_PATH@"
+  append_to_libpath "@with_LIBDIRPATH@"
 }
 
+# ------------------------------------------------------------------------
+
+abs_top_srcdir=@abs_top_srcdir@
+abs_top_builddir=@abs_top_builddir@
+
 # usage: prepend <path-varname> <dir>
 function prepend(){
   if [ $# -ne 2 ]
@@ -37,9 +58,6 @@ function prepend(){
   fi
   local path="$1" dir="$2" contents=""
   eval "contents=\$$path"
-  #echo "path = $path"
-  #echo "dir = $dir"
-  #echo "contents = $contents"
   if [ "$dir" != "" ]
   then
     if [ "$contents" = "" ]
@@ -49,32 +67,85 @@ function prepend(){
       eval "$path=\"$dir:$contents\""
     fi
   fi
-
   #echo end-of-prepend: $path=${!path}
 }
 
+# usage: append <path-varname> <dir>
+function append(){
+  if [ $# -ne 2 ]
+  then
+    echo "$0: append needs 2 args" 1>&2
+    exit 1
+  fi
+  local path="$1" dir="$2" contents=""
+  eval "contents=\$$path"
+  if [ "$dir" != "" ]
+  then
+    if [ "$contents" = "" ]
+    then
+      eval "$path=\"$dir\""
+    else
+      eval "$path=\"$contents:$dir\""
+    fi
+  fi
+  #echo end-of-append: $path=${!path}
+}
+
+function prepend_to_guile_load_path(){
+    prepend GUILE_LOAD_PATH "$1"
+    export GUILE_LOAD_PATH
+}
+
+function append_to_guile_load_path(){
+    append GUILE_LOAD_PATH "$1"
+    export GUILE_LOAD_PATH
+}
+
+function prepend_to_libpath(){
+    prepend LTDL_LIBRARY_PATH "$1"
+    export LTDL_LIBRARY_PATH
+    case "@host_os@" in
+	darwin*)
+	    prepend DYLD_LIBRARY_PATH "$1"
+	    export DYLD_LIBRARY_PATH
+	    ;;
+	cygwin*|win*|mingw*)
+	    prepend PATH "$1"
+	    export PATH
+	    ;;
+    esac
+}
+
+function append_to_libpath(){
+    append LTDL_LIBRARY_PATH "$1"
+    export LTDL_LIBRARY_PATH
+    case "@host_os@" in
+	darwin*)
+	    append DYLD_LIBRARY_PATH "$1"
+	    export DYLD_LIBRARY_PATH
+	    ;;
+	cygwin*|win*|mingw*)
+	    append PATH "$1"
+	    export PATH
+	    ;;
+    esac
+}
+
 # ------------------------------------------------------------------------
 # Everybody gets gruel and gnuradio-core for free.
 # FIXME Eventually this should be gruel and gnuradio-runtime.
 # ------------------------------------------------------------------------
 
 # Where to search for not yet installed C++ shared libraries
-prepend mylibdir $abs_top_builddir/gruel/src/lib/.libs
-prepend mylibdir $abs_top_builddir/gnuradio-core/src/lib/.libs
+prepend_to_libpath $abs_top_builddir/gruel/src/lib/.libs
+prepend_to_libpath $abs_top_builddir/gnuradio-core/src/lib/.libs
 
 # Where to search for not yet installed swig generated guile libs
-prepend mylibdir $abs_top_builddir/gnuradio-core/src/lib/swig/.libs
+prepend_to_libpath $abs_top_builddir/gnuradio-core/src/lib/swig/.libs
 
 # Where to seach for guile code.
-prepend guile_load_path $abs_top_srcdir/gnuradio-core/src/guile
-prepend guile_load_path $abs_top_builddir/gnuradio-core/src/lib/swig
-
-#echo "mylibdir = $mylibdir"
-#echo "guile_load_path = $guile_load_path"
+prepend_to_guile_load_path $abs_top_srcdir/gnuradio-core/src/guile
+prepend_to_guile_load_path $abs_top_builddir/gnuradio-core/src/lib/swig
 
-prepend LTDL_LIBRARY_PATH "$mylibdir"
-prepend GUILE_LOAD_PATH "$guile_load_path"
 
-export LTDL_LIBRARY_PATH
-export GUILE_LOAD_PATH
 export GUILE_WARN_DEPRECATED=no
-- 
cgit v1.2.3