diff options
author | Tom Rondeau | 2010-11-07 16:05:08 -0500 |
---|---|---|
committer | Tom Rondeau | 2010-11-07 16:05:08 -0500 |
commit | 95eaad323daecbd2c4c0a7aaf5176f9a1b33eec0 (patch) | |
tree | 7f21b697155bfc2b61b44d66a4f9317fad0c899b /gnuradio-core/src/lib/runtime | |
parent | cafe83aa6bd47f8e05bd347cc4495d3662b5440f (diff) | |
download | gnuradio-95eaad323daecbd2c4c0a7aaf5176f9a1b33eec0.tar.gz gnuradio-95eaad323daecbd2c4c0a7aaf5176f9a1b33eec0.tar.bz2 gnuradio-95eaad323daecbd2c4c0a7aaf5176f9a1b33eec0.zip |
Cleaning up. Better use of PMTs; comment mods; returning vectors when getting tags.
Diffstat (limited to 'gnuradio-core/src/lib/runtime')
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_block.cc | 14 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_block.h | 38 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_block.i | 4 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_block_detail.cc | 50 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_block_detail.h | 42 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_buffer.cc | 10 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_buffer.h | 23 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_random_annotator.cc | 20 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/qa_block_tags.cc | 6 |
9 files changed, 98 insertions, 109 deletions
diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 51eb5b498..73a86e38b 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -117,7 +117,7 @@ gr_block::fixed_rate_noutput_to_ninput(int noutput) throw std::runtime_error("Unimplemented"); } -gr_uint64 +uint64_t gr_block::nitems_read(unsigned int which_input) { if(d_detail) { @@ -129,7 +129,7 @@ gr_block::nitems_read(unsigned int which_input) } } -gr_uint64 +uint64_t gr_block::nitems_written(unsigned int which_output) { if(d_detail) { @@ -143,7 +143,7 @@ gr_block::nitems_written(unsigned int which_output) void gr_block::add_item_tag(unsigned int which_output, - gr_uint64 offset, + uint64_t offset, const pmt::pmt_t &key, const pmt::pmt_t &value, const pmt::pmt_t &srcid) @@ -151,16 +151,16 @@ gr_block::add_item_tag(unsigned int which_output, d_detail->add_item_tag(which_output, offset, key, value, srcid); } -std::deque<pmt::pmt_t> +std::vector<pmt::pmt_t> gr_block::get_tags_in_range(unsigned int which_output, - gr_uint64 start, gr_uint64 end) + uint64_t start, uint64_t end) { return d_detail->get_tags_in_range(which_output, start, end); } -std::deque<pmt::pmt_t> +std::vector<pmt::pmt_t> gr_block::get_tags_in_range(unsigned int which_output, - gr_uint64 start, gr_uint64 end, + uint64_t start, uint64_t end, const pmt::pmt_t &key) { return d_detail->get_tags_in_range(which_output, start, end, key); diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 89d762847..4d1d6f875 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -24,7 +24,6 @@ #define INCLUDED_GR_BLOCK_H #include <gr_basic_block.h> -#include <deque> /*! * \brief The abstract base class for all 'terminal' processing blocks. @@ -202,12 +201,12 @@ class gr_block : public gr_basic_block { /*! * \brief Return the number of items read on input stream which_input */ - gr_uint64 nitems_read(unsigned int which_input); + uint64_t nitems_read(unsigned int which_input); /*! * \brief Return the number of items written on output stream which_output */ - gr_uint64 nitems_written(unsigned int which_output); + uint64_t nitems_written(unsigned int which_output); /*! @@ -238,28 +237,25 @@ class gr_block : public gr_basic_block { /*! - * \brief Adds a new tag to the deque of tags on a given buffer. + * \brief Adds a new tag onto the given output buffer. * - * This is a call-through method to gr_block_detail to add the new tag. - * gr_block_detail takes care of formatting the tuple from the inputs here, - * it then calls gr_buffer::add_item_tag(pmt::pmt_t t), which appends the - * tag onto its deque of tags. + * This is a call-through method to gr_block_detail. * * \param which_ouput an integer of which output stream to attach the tag * \param abs_offset a uint64 number of the absolute item number * assicated with the tag. Can get from nitems_written. - * \param key a PMT symbol holding the key name (i.e., a string) + * \param key a PMT symbol holding the key name * \param value any PMT holding any value for the given key - * \param srcid optional source ID specifier; defauls to string "NA" + * \param srcid optional source ID specifier; defaults to PMT_F */ void add_item_tag(unsigned int which_output, - gr_uint64 abs_offset, + uint64_t abs_offset, const pmt::pmt_t &key, const pmt::pmt_t &value, - const pmt::pmt_t &srcid=pmt::pmt_string_to_symbol("NA")); + const pmt::pmt_t &srcid=pmt::PMT_F); /*! - * \brief Given a [start,end), returns a deque copy of all tags in the range. + * \brief Given a [start,end), returns a vector of all tags in the range. * * Pass-through function to gr_block_detail. Range of counts is from * start to end-1. @@ -271,12 +267,12 @@ class gr_block : public gr_basic_block { * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest */ - std::deque<pmt::pmt_t> get_tags_in_range(unsigned int which_input, - gr_uint64 abs_start, - gr_uint64 abs_end); + std::vector<pmt::pmt_t> get_tags_in_range(unsigned int which_input, + uint64_t abs_start, + uint64_t abs_end); /*! - * \brief Given a [start,end), returns a deque copy of all tags in the range + * \brief Given a [start,end), returns a vector of all tags in the range * with a given key. * * Pass-through function to gr_block_detail. Range of counts is from @@ -290,10 +286,10 @@ class gr_block : public gr_basic_block { * \param abs_end a uint64 count of the end of the range of interest * \param key a PMT symbol key to filter only tags of this key */ - std::deque<pmt::pmt_t> get_tags_in_range(unsigned int which_input, - gr_uint64 abs_start, - gr_uint64 abs_end, - const pmt::pmt_t &key); + std::vector<pmt::pmt_t> get_tags_in_range(unsigned int which_input, + uint64_t abs_start, + uint64_t abs_end, + const pmt::pmt_t &key); // These are really only for internal use, but leaving them public avoids diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i index e6ea06060..2de354878 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.i +++ b/gnuradio-core/src/lib/runtime/gr_block.i @@ -49,8 +49,8 @@ class gr_block : public gr_basic_block { bool start(); bool stop(); - gr_uint64 nitems_read(unsigned int which_input); - gr_uint64 nitems_written(unsigned int which_output); + uint64_t nitems_read(unsigned int which_input); + uint64_t nitems_written(unsigned int which_output); // internal use gr_block_detail_sptr detail () const { return d_detail; } diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 7994919d4..b3d1a7194 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -27,6 +27,8 @@ #include <gr_block_detail.h> #include <gr_buffer.h> +using namespace pmt; + static long s_ncurrently_allocated = 0; long @@ -127,12 +129,12 @@ gr_block_detail::produce_each (int how_many_items) void -gr_block_detail::_post(pmt::pmt_t msg) +gr_block_detail::_post(pmt_t msg) { d_tpb.insert_tail(msg); } -gr_uint64 +uint64_t gr_block_detail::nitems_read(unsigned int which_input) { if(which_input >= d_ninputs) @@ -140,7 +142,7 @@ gr_block_detail::nitems_read(unsigned int which_input) return d_input[which_input]->nitems_read(); } -gr_uint64 +uint64_t gr_block_detail::nitems_written(unsigned int which_output) { if(which_output >= d_noutputs) @@ -150,50 +152,50 @@ gr_block_detail::nitems_written(unsigned int which_output) void gr_block_detail::add_item_tag(unsigned int which_output, - gr_uint64 abs_offset, - const pmt::pmt_t &key, - const pmt::pmt_t &value, - const pmt::pmt_t &srcid) + uint64_t abs_offset, + const pmt_t &key, + const pmt_t &value, + const pmt_t &srcid) { - if(pmt::pmt_is_symbol(key) == false) { - throw pmt::pmt_wrong_type("gr_block_detail::set_item_tag key", key); + if(!pmt_is_symbol(key)) { + throw pmt_wrong_type("gr_block_detail::set_item_tag key", key); } else { // build tag tuple - pmt::pmt_t nitem = pmt::pmt_from_uint64(abs_offset); - pmt::pmt_t tuple = pmt::pmt_make_tuple(nitem, srcid, key, value); + pmt_t nitem = pmt_from_uint64(abs_offset); + pmt_t tuple = pmt_make_tuple(nitem, srcid, key, value); // Add tag to gr_buffer's deque tags d_output[which_output]->add_item_tag(tuple); } } -std::deque<pmt::pmt_t> +std::vector<pmt_t> gr_block_detail::get_tags_in_range(unsigned int which_input, - gr_uint64 abs_start, - gr_uint64 abs_end) + uint64_t abs_start, + uint64_t abs_end) { // get from gr_buffer_reader's deque of tags return d_input[which_input]->get_tags_in_range(abs_start, abs_end); } -std::deque<pmt::pmt_t> +std::vector<pmt_t> gr_block_detail::get_tags_in_range(unsigned int which_input, - gr_uint64 abs_start, - gr_uint64 abs_end, - const pmt::pmt_t &key) + uint64_t abs_start, + uint64_t abs_end, + const pmt_t &key) { - std::deque<pmt::pmt_t> found_items, found_items_by_key; + std::vector<pmt_t> found_items, found_items_by_key; // get from gr_buffer_reader's deque of tags found_items = d_input[which_input]->get_tags_in_range(abs_start, abs_end); // Filter further by key name - pmt::pmt_t itemkey; - std::deque<pmt::pmt_t>::iterator itr; + pmt_t itemkey; + std::vector<pmt_t>::iterator itr; for(itr = found_items.begin(); itr != found_items.end(); itr++) { - itemkey = pmt::pmt_tuple_ref(*itr, 2); - if(pmt::pmt_eqv(key, itemkey)) { + itemkey = pmt_tuple_ref(*itr, 2); + if(pmt_eqv(key, itemkey)) { found_items_by_key.push_back(*itr); } } @@ -205,7 +207,7 @@ void gr_block_detail::handle_tags() { for(unsigned int i = 0; i < d_ninputs; i++) { - pmt::pmt_t tuple; + pmt_t tuple; while(d_input[i]->get_tag(d_last_tag, tuple)) { d_last_tag++; if(!sink_p()) { diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index cbb59a689..3a2b82190 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -89,19 +89,18 @@ class gr_block_detail { void _post(pmt::pmt_t msg); // Return the number of items read on input stream which_input - gr_uint64 nitems_read(unsigned int which_input); + uint64_t nitems_read(unsigned int which_input); // Return the number of items written on output stream which_output - gr_uint64 nitems_written(unsigned int which_output); + uint64_t nitems_written(unsigned int which_output); /*! - * \brief Adds a new tag to the deque of tags on a given buffer. + * \brief Adds a new tag to the given output stream. * - * Adds a new tag to deque of tags on a given buffer. This takes the input - * parameters and builds a PMT tuple from it. It then calls - * gr_buffer::add_item_tag(pmt::pmt_t t), which appends the - * tag onto its deque of tags. + * This takes the input parameters and builds a PMT tuple + * from it. It then calls gr_buffer::add_item_tag(pmt::pmt_t t), + * which appends the tag onto its deque. * * \param which_ouput an integer of which output stream to attach the tag * \param abs_offset a uint64 number of the absolute item number @@ -111,15 +110,15 @@ class gr_block_detail { * \param srcid a PMT source ID specifier */ void add_item_tag(unsigned int which_output, - gr_uint64 abs_offset, + uint64_t abs_offset, const pmt::pmt_t &key, const pmt::pmt_t &value, const pmt::pmt_t &srcid); /*! - * \brief Given a [start,end), returns a deque copy of all tags in the range. + * \brief Given a [start,end), returns a vector of all tags in the range. * - * Pass-through function to gr_buffer_reader to get a deque of tags + * Pass-through function to gr_buffer_reader to get a vector of tags * in given range. Range of counts is from start to end-1. * * Tags are tuples of: @@ -129,18 +128,17 @@ class gr_block_detail { * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest */ - std::deque<pmt::pmt_t> get_tags_in_range(unsigned int which_input, - gr_uint64 abs_start, - gr_uint64 abs_end); + std::vector<pmt::pmt_t> get_tags_in_range(unsigned int which_input, + uint64_t abs_start, + uint64_t abs_end); /*! - * \brief Given a [start,end), returns a deque copy of all tags in the range + * \brief Given a [start,end), returns a vector of all tags in the range * with a given key. * - * Calls get_tags_in_range(which_input, abs_start, abs_end) to get a deque of + * Calls get_tags_in_range(which_input, abs_start, abs_end) to get a vector of * tags from the buffers. This function then provides a secondary filter to - * the tags to extract only tags with the given 'key'. Returns a dequeu - * of these tags. + * the tags to extract only tags with the given 'key'. * * Tags are tuples of: * (item count, source id, key, value) @@ -148,12 +146,12 @@ class gr_block_detail { * \param which_input an integer of which input stream to pull from * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest - * \param key a PMT symbol key to filter only tags of this key + * \param key a PMT symbol key to select only tags of this key */ - std::deque<pmt::pmt_t> get_tags_in_range(unsigned int which_input, - gr_uint64 abs_start, - gr_uint64 abs_end, - const pmt::pmt_t &key); + std::vector<pmt::pmt_t> get_tags_in_range(unsigned int which_input, + uint64_t abs_start, + uint64_t abs_end, + const pmt::pmt_t &key); /*! * \brief Default tag handler; moves all tags downstream diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 8387a3168..862d92b81 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -263,14 +263,14 @@ gr_buffer_reader::update_read_pointer (int nitems) d_abs_read_offset += nitems; } -std::deque<pmt::pmt_t> -gr_buffer_reader::get_tags_in_range(gr_uint64 abs_start, - gr_uint64 abs_end) +std::vector<pmt::pmt_t> +gr_buffer_reader::get_tags_in_range(uint64_t abs_start, + uint64_t abs_end) { - std::deque<pmt::pmt_t> found_items; + std::vector<pmt::pmt_t> found_items; std::deque<pmt::pmt_t>::iterator itr = d_buffer->get_tags_begin(); - gr_uint64 item_time; + uint64_t item_time; while(itr != d_buffer->get_tags_end()) { item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 6dcbff0b9..5b8f21c94 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -89,17 +89,12 @@ class gr_buffer { gruel::mutex *mutex() { return &d_mutex; } - gr_uint64 nitems_written() { return d_abs_write_offset; } + uint64_t nitems_written() { return d_abs_write_offset; } /*! - * \brief Adds a new tag to the deque of tags on a given buffer. + * \brief Adds a new tag to the buffer. * - * Adds a new tag to deque of tags on a given buffer. This takes the input - * parameters and builds a PMT tuple from it. It then calls - * gr_buffer::add_item_tag(pmt::pmt_t t), which appends the - * tag onto its deque of tags. - * * \param tag a PMT tuple containing the new tag */ void add_item_tag(const pmt::pmt_t &tag); @@ -143,7 +138,7 @@ class gr_buffer { // gruel::mutex d_mutex; unsigned int d_write_index; // in items [0,d_bufsize) - gr_uint64 d_abs_write_offset; // num items written since the start + uint64_t d_abs_write_offset; // num items written since the start //deq tag_tuples bool d_done; @@ -255,7 +250,7 @@ class gr_buffer_reader { gruel::mutex *mutex() { return d_buffer->mutex(); } - gr_uint64 nitems_read() { return d_abs_read_offset; } + uint64_t nitems_read() { return d_abs_read_offset; } /*! * \brief Return the block that reads via this reader. @@ -264,9 +259,9 @@ class gr_buffer_reader { /*! - * \brief Given a [start,end), returns a deque copy of all tags in the range. + * \brief Given a [start,end), returns a vector all tags in the range. * - * Get a deque of tags in given range. Range of counts is from start to end-1. + * Get a vector of tags in given range. Range of counts is from start to end-1. * * Tags are tuples of: * (item count, source id, key, value) @@ -274,8 +269,8 @@ class gr_buffer_reader { * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest */ - std::deque<pmt::pmt_t> get_tags_in_range(gr_uint64 abs_start, - gr_uint64 abs_end); + std::vector<pmt::pmt_t> get_tags_in_range(uint64_t abs_start, + uint64_t abs_end); bool get_tag(size_t n, pmt::pmt_t &t) { @@ -293,7 +288,7 @@ class gr_buffer_reader { gr_buffer_sptr d_buffer; unsigned int d_read_index; // in items [0,d->buffer.d_bufsize) - gr_uint64 d_abs_read_offset; // num items seen since the start + uint64_t d_abs_read_offset; // num items seen since the start boost::weak_ptr<gr_block> d_link; // block that reads via this buffer reader //! constructor is private. Use gr_buffer::add_reader to create instances diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc index 93d9aa793..d360c13a5 100644 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc @@ -60,9 +60,9 @@ gr_random_annotator::work (int noutput_items, std::stringstream str; str << name() << unique_id(); - gr_uint64 abs_N = nitems_written(0); - std::deque<pmt::pmt_t> all_tags = get_tags_in_range(0, (gr_uint64)0, abs_N); - std::deque<pmt::pmt_t>::iterator itr; + uint64_t abs_N = nitems_written(0); + std::vector<pmt::pmt_t> all_tags = get_tags_in_range(0, (uint64_t)0, abs_N); + std::vector<pmt::pmt_t>::iterator itr; d_sout << std::endl << "Found " << all_tags.size() << " tags." << std::endl; d_sout.setf(std::ios::left); @@ -71,14 +71,12 @@ gr_random_annotator::work (int noutput_items, << std::setw(10) << "value" << std::endl; for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { - gr_uint64 nitem = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); - std::string srcid = pmt::pmt_symbol_to_string(pmt::pmt_tuple_ref(*itr, 1)); - std::string key = pmt::pmt_symbol_to_string(pmt::pmt_tuple_ref(*itr, 2)); - gr_uint64 value = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 3)); - - d_sout << std::setw(25) << str.str() << std::setw(25) << srcid - << std::setw(10) << nitem << std::setw(20) << key - << std::setw(10) << value << std::endl; + d_sout << std::setw(25) << str.str() + << std::setw(25) << pmt::pmt_tuple_ref(*itr, 1) + << std::setw(10) << pmt::pmt_tuple_ref(*itr, 0) + << std::setw(20) << pmt::pmt_tuple_ref(*itr, 2) + << std::setw(10) << pmt::pmt_tuple_ref(*itr, 3) + << std::endl; } // Work does nothing to the data stream; just copy all inputs to outputs diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index ab3db6653..2fedb28fd 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -52,14 +52,14 @@ qa_block_tags::t0 () //CPPUNIT_ASSERT_THROW(src->nitems_read(0), std::runtime_error); //CPPUNIT_ASSERT_THROW(src->nitems_written(0), std::runtime_error); - CPPUNIT_ASSERT_EQUAL(src->nitems_read(0), (gr_uint64)0); - CPPUNIT_ASSERT_EQUAL(src->nitems_written(0), (gr_uint64)0); + CPPUNIT_ASSERT_EQUAL(src->nitems_read(0), (uint64_t)0); + CPPUNIT_ASSERT_EQUAL(src->nitems_written(0), (uint64_t)0); tb->run(); CPPUNIT_ASSERT_THROW(src->nitems_read(0), std::invalid_argument); CPPUNIT_ASSERT(src->nitems_written(0) >= N); - CPPUNIT_ASSERT_EQUAL(snk->nitems_read(0), (gr_uint64)1000); + CPPUNIT_ASSERT_EQUAL(snk->nitems_read(0), (uint64_t)1000); CPPUNIT_ASSERT_THROW(snk->nitems_written(0), std::invalid_argument); } |