diff options
author | Eric Blossom | 2011-01-06 21:46:55 -0800 |
---|---|---|
committer | Eric Blossom | 2011-01-06 21:46:55 -0800 |
commit | 1dc1dbeef3eb15e1316857d4dd7ba32c4304bf69 (patch) | |
tree | d7819200dd83236652e495921086c89905ef670e /gnuradio-core | |
parent | b6005d9e5823d871c091f3b4a048ca67cd885821 (diff) | |
download | gnuradio-1dc1dbeef3eb15e1316857d4dd7ba32c4304bf69.tar.gz gnuradio-1dc1dbeef3eb15e1316857d4dd7ba32c4304bf69.tar.bz2 gnuradio-1dc1dbeef3eb15e1316857d4dd7ba32c4304bf69.zip |
Augment gr_nop to count received pmt messages by way of set_msg_handler.
Diffstat (limited to 'gnuradio-core')
-rw-r--r-- | gnuradio-core/src/lib/general/gr_nop.cc | 24 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_nop.h | 9 |
2 files changed, 26 insertions, 7 deletions
diff --git a/gnuradio-core/src/lib/general/gr_nop.cc b/gnuradio-core/src/lib/general/gr_nop.cc index 950ef878e..bd5e4fd81 100644 --- a/gnuradio-core/src/lib/general/gr_nop.cc +++ b/gnuradio-core/src/lib/general/gr_nop.cc @@ -25,18 +25,30 @@ #endif #include <gr_nop.h> #include <gr_io_signature.h> +#include <boost/bind.hpp> + +gr_nop_sptr +gr_make_nop (size_t sizeof_stream_item) +{ + return gnuradio::get_initial_sptr (new gr_nop (sizeof_stream_item)); +} gr_nop::gr_nop (size_t sizeof_stream_item) : gr_block ("nop", - gr_make_io_signature (0, -1, sizeof_stream_item), - gr_make_io_signature (0, -1, sizeof_stream_item)) + gr_make_io_signature (0, -1, sizeof_stream_item), + gr_make_io_signature (0, -1, sizeof_stream_item)), + d_nmsgs_recvd(0) { + // Arrange to have count_received_msgs called when messages are received. + set_msg_handler(boost::bind(&gr_nop::count_received_msgs, this, _1)); } -gr_nop_sptr -gr_make_nop (size_t sizeof_stream_item) +// Trivial message handler that just counts them. +// (N.B., This feature is used in qa_set_msg_handler) +void +gr_nop::count_received_msgs(pmt::pmt_t msg) { - return gnuradio::get_initial_sptr (new gr_nop (sizeof_stream_item)); + d_nmsgs_recvd++; } int @@ -51,5 +63,3 @@ gr_nop::general_work (int noutput_items, return noutput_items; } - - diff --git a/gnuradio-core/src/lib/general/gr_nop.h b/gnuradio-core/src/lib/general/gr_nop.h index 4f18c9183..354c2f9fc 100644 --- a/gnuradio-core/src/lib/general/gr_nop.h +++ b/gnuradio-core/src/lib/general/gr_nop.h @@ -41,11 +41,20 @@ class gr_nop : public gr_block friend gr_nop_sptr gr_make_nop (size_t sizeof_stream_item); gr_nop (size_t sizeof_stream_item); +protected: + int d_nmsgs_recvd; + + // Method that just counts any received messages. + void count_received_msgs(pmt::pmt_t msg); + public: virtual int general_work (int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); + + int nmsgs_received() const { return d_nmsgs_recvd; } + }; #endif /* INCLUDED_GR_NOP_H */ |