From 2a1966462484cf1cb25ea7802cc0d9a8e80096c9 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 21 Oct 2012 15:53:11 -0700 Subject: getting API read for PMCs Moved tags API stuff into gr block, specifically the get tags filters. The block class now has a simplified interface for dealing with input and output tags. Dummy typedefs for PMCs Tag class now uses PMCs --- lib/CMakeLists.txt | 1 + lib/block.cpp | 54 ++++---------------------------------------------- lib/gr_block.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/tag_handlers.hpp | 2 +- lib/tags.cpp | 36 +++++++++++++++++++++++++++++++++ 5 files changed, 98 insertions(+), 51 deletions(-) create mode 100644 lib/tags.cpp (limited to 'lib') diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 6081bb6..cfc957f 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -43,6 +43,7 @@ list(APPEND gnuradio_core_sources ${CMAKE_CURRENT_SOURCE_DIR}/debug.cpp ${CMAKE_CURRENT_SOURCE_DIR}/element.cpp ${CMAKE_CURRENT_SOURCE_DIR}/sbuffer.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/tags.cpp ${CMAKE_CURRENT_SOURCE_DIR}/block.cpp ${CMAKE_CURRENT_SOURCE_DIR}/block_actor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/block_task.cpp diff --git a/lib/block.cpp b/lib/block.cpp index 6b27ab2..95d27fa 100644 --- a/lib/block.cpp +++ b/lib/block.cpp @@ -176,64 +176,18 @@ void Block::set_tag_propagation_policy(Block::tag_propagation_policy_t p) (*this)->block->tag_prop_policy = p; } -void Block::add_item_tag( +void Block::post_output_tag( const size_t which_output, const Tag &tag ){ (*this)->block->post_downstream(which_output, InputTagMessage(tag)); } -void Block::add_item_tag( - const size_t which_output, - uint64_t abs_offset, - const pmt::pmt_t &key, - const pmt::pmt_t &value, - const pmt::pmt_t &srcid -){ - Tag t; - t.offset = abs_offset; - t.key = key; - t.value = value; - t.srcid = srcid; - this->add_item_tag(which_output, t); -} - -void Block::get_tags_in_range( - std::vector &tags, - const size_t which_input, - uint64_t abs_start, - uint64_t abs_end -){ - const std::vector &input_tags = (*this)->block->input_tags[which_input]; - tags.clear(); - for (size_t i = 0; i < input_tags.size(); i++) - { - if (input_tags[i].offset >= abs_start and input_tags[i].offset <= abs_end) - { - tags.push_back(input_tags[i]); - } - } -} - -void Block::get_tags_in_range( - std::vector &tags, - const size_t which_input, - uint64_t abs_start, - uint64_t abs_end, - const pmt::pmt_t &key +Block::TagIter Block::get_input_tags( + const size_t which_input ){ const std::vector &input_tags = (*this)->block->input_tags[which_input]; - tags.clear(); - for (size_t i = 0; i < input_tags.size(); i++) - { - if ( - input_tags[i].offset >= abs_start and - input_tags[i].offset <= abs_end and - pmt::pmt_equal(input_tags[i].key, key) - ){ - tags.push_back(input_tags[i]); - } - } + return boost::make_iterator_range(input_tags.begin(), input_tags.end()); } void Block::forecast(int, std::vector &) diff --git a/lib/gr_block.cpp b/lib/gr_block.cpp index b4e7c04..32d9a0c 100644 --- a/lib/gr_block.cpp +++ b/lib/gr_block.cpp @@ -16,6 +16,7 @@ #include "element_impl.hpp" #include +#include gr_block::gr_block(void) { @@ -147,3 +148,58 @@ bool gr_block::is_set_max_noutput_items(void) const { return this->max_noutput_items() != 0; } + +//TODO Tag2gr_tag and gr_tag2Tag need PMC to/from PMT logic +static gr_tag_t Tag2gr_tag(const gnuradio::Tag &tag) +{ + gr_tag_t t; + t.offset = tag.offset; + t.key = tag.key; + t.value = tag.value; + t.srcid = tag.srcid; + return t; +} + +static gnuradio::Tag gr_tag2Tag(const gr_tag_t &tag) +{ + return gnuradio::Tag(tag.offset, tag.key, tag.value, tag.srcid); +} + +void gr_block::add_item_tag( + const size_t which_output, const gr_tag_t &tag +){ + this->post_output_tag(which_output, gr_tag2Tag(tag)); +} + +void gr_block::add_item_tag( + const size_t which_output, + uint64_t abs_offset, + const pmt::pmt_t &key, + const pmt::pmt_t &value, + const pmt::pmt_t &srcid +){ + gr_tag_t t; + t.offset = abs_offset; + t.key = key; + t.value = value; + t.srcid = srcid; + this->add_item_tag(which_output, t); +} + +void gr_block::get_tags_in_range( + std::vector &tags, + const size_t which_input, + uint64_t abs_start, + uint64_t abs_end, + const pmt::pmt_t &key +){ + tags.clear(); + BOOST_FOREACH(const gnuradio::Tag &tag, this->get_input_tags(which_input)) + { + if (tag.offset >= abs_start and tag.offset <= abs_end) + { + gr_tag_t t = Tag2gr_tag(tag); + if (key or pmt::pmt_equal(t.key, key)) tags.push_back(t); + } + } +} diff --git a/lib/tag_handlers.hpp b/lib/tag_handlers.hpp index 9e20bc0..4e630fb 100644 --- a/lib/tag_handlers.hpp +++ b/lib/tag_handlers.hpp @@ -27,7 +27,7 @@ GRAS_FORCE_INLINE void BlockActor::sort_tags(const size_t i) { if (not this->input_tags_changed[i]) return; std::vector &tags_i = this->input_tags[i]; - std::sort(tags_i.begin(), tags_i.end(), Tag::offset_compare); + std::sort(tags_i.begin(), tags_i.end()); this->input_tags_changed[i] = false; } diff --git a/lib/tags.cpp b/lib/tags.cpp new file mode 100644 index 0000000..ec563d0 --- /dev/null +++ b/lib/tags.cpp @@ -0,0 +1,36 @@ +// +// Copyright 2012 Josh Blum +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . + +#include + +using namespace gnuradio; + +Tag::Tag(void): + offset(0) +{ + //NOP +} + +Tag::Tag(const uint64_t &offset, const PMCC &key, const PMCC &value, const PMCC &srcid): + offset(offset), key(key), value(value), srcid(srcid) +{ + //NOP +} + +bool gnuradio::operator<(const Tag &lhs, const Tag &rhs) +{ + return lhs.offset < rhs.offset; +} -- cgit