summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gnuradio-core/src/lib/io/gr_message_source.cc15
-rw-r--r--gnuradio-core/src/lib/io/gr_message_source.h4
-rw-r--r--gnuradio-core/src/lib/io/gr_message_source.i2
-rwxr-xr-xgnuradio-core/src/python/gnuradio/gr/qa_message.py15
4 files changed, 36 insertions, 0 deletions
diff --git a/gnuradio-core/src/lib/io/gr_message_source.cc b/gnuradio-core/src/lib/io/gr_message_source.cc
index 3fbe3708e..3efc5b321 100644
--- a/gnuradio-core/src/lib/io/gr_message_source.cc
+++ b/gnuradio-core/src/lib/io/gr_message_source.cc
@@ -43,6 +43,13 @@ gr_make_message_source(size_t itemsize, int msgq_limit)
return gr_message_source_sptr(new gr_message_source(itemsize, msgq_limit));
}
+// public constructor that takes existing message queue
+gr_message_source_sptr
+gr_make_message_source(size_t itemsize, gr_msg_queue_sptr msgq)
+{
+ return gr_message_source_sptr(new gr_message_source(itemsize, msgq));
+}
+
gr_message_source::gr_message_source (size_t itemsize, int msgq_limit)
: gr_sync_block("message_source",
gr_make_io_signature(0, 0, 0),
@@ -51,6 +58,14 @@ gr_message_source::gr_message_source (size_t itemsize, int msgq_limit)
{
}
+gr_message_source::gr_message_source (size_t itemsize, gr_msg_queue_sptr msgq)
+ : gr_sync_block("message_source",
+ gr_make_io_signature(0, 0, 0),
+ gr_make_io_signature(1, 1, itemsize)),
+ d_itemsize(itemsize), d_msgq(msgq), d_msg_offset(0), d_eof(false)
+{
+}
+
gr_message_source::~gr_message_source()
{
}
diff --git a/gnuradio-core/src/lib/io/gr_message_source.h b/gnuradio-core/src/lib/io/gr_message_source.h
index 5a5c6a5d8..46a808754 100644
--- a/gnuradio-core/src/lib/io/gr_message_source.h
+++ b/gnuradio-core/src/lib/io/gr_message_source.h
@@ -31,6 +31,7 @@ class gr_message_source;
typedef boost::shared_ptr<gr_message_source> gr_message_source_sptr;
gr_message_source_sptr gr_make_message_source (size_t itemsize, int msgq_limit=0);
+gr_message_source_sptr gr_make_message_source (size_t itemsize, gr_msg_queue_sptr msgq);
/*!
* \brief Turn received messages into a stream
@@ -47,9 +48,12 @@ class gr_message_source : public gr_sync_block
friend gr_message_source_sptr
gr_make_message_source(size_t itemsize, int msgq_limit);
+ friend gr_message_source_sptr
+ gr_make_message_source(size_t itemsize, gr_msg_queue_sptr msgq);
protected:
gr_message_source (size_t itemsize, int msgq_limit);
+ gr_message_source (size_t itemsize, gr_msg_queue_sptr msgq);
public:
~gr_message_source ();
diff --git a/gnuradio-core/src/lib/io/gr_message_source.i b/gnuradio-core/src/lib/io/gr_message_source.i
index fdc74741e..8a9c762d0 100644
--- a/gnuradio-core/src/lib/io/gr_message_source.i
+++ b/gnuradio-core/src/lib/io/gr_message_source.i
@@ -23,11 +23,13 @@
GR_SWIG_BLOCK_MAGIC(gr,message_source);
gr_message_source_sptr gr_make_message_source (size_t itemsize, int msgq_limit=0);
+gr_message_source_sptr gr_make_message_source (size_t itemsize, gr_msg_queue_sptr msgq);
class gr_message_source : public gr_sync_block
{
protected:
gr_message_source (size_t itemsize, int msgq_limit);
+ gr_message_source (size_t itemsize, gr_msg_queue_sptr msgq);
public:
~gr_message_source ();
diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_message.py b/gnuradio-core/src/python/gnuradio/gr/qa_message.py
index 6e85083bd..cb6c4c33c 100755
--- a/gnuradio-core/src/python/gnuradio/gr/qa_message.py
+++ b/gnuradio-core/src/python/gnuradio/gr/qa_message.py
@@ -99,6 +99,7 @@ class test_message (gr_unittest.TestCase):
self.assertEquals(input_data, dst.data())
def test_301(self):
+ # Use itemsize, limit constructor
src = gr.message_source(gr.sizeof_char)
dst = gr.vector_sink_b()
tb = gr.top_block()
@@ -111,6 +112,20 @@ class test_message (gr_unittest.TestCase):
tb.run()
self.assertEquals(tuple(map(ord, '0123456789')), dst.data())
+ def test_302(self):
+ # Use itemsize, msgq constructor
+ msgq = gr.msg_queue()
+ src = gr.message_source(gr.sizeof_char, msgq)
+ dst = gr.vector_sink_b()
+ tb = gr.top_block()
+ tb.connect(src, dst)
+ src.msgq().insert_tail(gr.message_from_string('01234'))
+ src.msgq().insert_tail(gr.message_from_string('5'))
+ src.msgq().insert_tail(gr.message_from_string(''))
+ src.msgq().insert_tail(gr.message_from_string('6789'))
+ src.msgq().insert_tail(gr.message(1)) # send EOF
+ tb.run()
+ self.assertEquals(tuple(map(ord, '0123456789')), dst.data())
if __name__ == '__main__':
gr_unittest.main ()