summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/CMakeLists.txt1
-rw-r--r--lib/block.cpp54
-rw-r--r--lib/gr_block.cpp56
-rw-r--r--lib/tag_handlers.hpp2
-rw-r--r--lib/tags.cpp36
5 files changed, 98 insertions, 51 deletions
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<Tag> &tags,
- const size_t which_input,
- uint64_t abs_start,
- uint64_t abs_end
-){
- const std::vector<Tag> &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<Tag> &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<Tag> &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<int> &)
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 <gr_block.h>
+#include <boost/foreach.hpp>
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<gr_tag_t> &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<Tag> &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 <http://www.gnu.org/licenses/>.
+
+#include <gnuradio/tags.hpp>
+
+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;
+}