summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/gnuradio/block.hpp31
-rw-r--r--include/gnuradio/gr_block.h20
-rw-r--r--include/gnuradio/gr_tags.h23
-rw-r--r--include/gnuradio/tags.hpp35
-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
9 files changed, 167 insertions, 91 deletions
diff --git a/include/gnuradio/block.hpp b/include/gnuradio/block.hpp
index 23274b1..bcce34a 100644
--- a/include/gnuradio/block.hpp
+++ b/include/gnuradio/block.hpp
@@ -22,6 +22,7 @@
#include <gnuradio/tags.hpp>
#include <vector>
#include <string>
+#include <boost/range.hpp> //iterator range
namespace gnuradio
{
@@ -214,32 +215,14 @@ struct GRAS_API Block : Element
void set_tag_propagation_policy(tag_propagation_policy_t p);
- void add_item_tag(
- const size_t which_output, const Tag &tag
- );
-
- void 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=pmt::PMT_F
- );
+ //! Send a tag to the downstream on the given output port
+ void post_output_tag(const size_t which_output, const Tag &tag);
- void get_tags_in_range(
- std::vector<Tag> &tags,
- const size_t which_input,
- uint64_t abs_start,
- uint64_t abs_end
- );
+ //! Iterator return type get_input_tags - stl and boost compliant
+ typedef boost::iterator_range<std::vector<Tag>::const_iterator> TagIter;
- void 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
- );
+ //! Get an iterator of item tags for the given input
+ TagIter get_input_tags(const size_t which_input = 0);
/*******************************************************************
* Work related routines from basic block
diff --git a/include/gnuradio/gr_block.h b/include/gnuradio/gr_block.h
index 7328dd1..8e0c40e 100644
--- a/include/gnuradio/gr_block.h
+++ b/include/gnuradio/gr_block.h
@@ -80,6 +80,26 @@ struct GRAS_API gr_block : gnuradio::Block
gr_vector_void_star &output_items
);
+ void add_item_tag(
+ const size_t which_output, const gr_tag_t &tag
+ );
+
+ void 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=pmt::PMT_F
+ );
+
+ void 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 = pmt::pmt_t()
+ );
+
unsigned history(void) const;
void set_history(unsigned history);
diff --git a/include/gnuradio/gr_tags.h b/include/gnuradio/gr_tags.h
index e4c9508..cb268da 100644
--- a/include/gnuradio/gr_tags.h
+++ b/include/gnuradio/gr_tags.h
@@ -19,6 +19,27 @@
#include <gnuradio/tags.hpp>
-typedef gnuradio::Tag gr_tag_t;
+struct GRAS_API gr_tag_t
+{
+
+ //! the item \p tag occurred at (as a uint64_t)
+ uint64_t offset;
+
+ //! the key of \p tag (as a PMT symbol)
+ pmt::pmt_t key;
+
+ //! the value of \p tag (as a PMT)
+ pmt::pmt_t value;
+
+ //! the source ID of \p tag (as a PMT)
+ pmt::pmt_t srcid;
+
+ //! Comparison function to test which tag, \p x or \p y, came first in time
+ static inline bool offset_compare(
+ const gr_tag_t &x, const gr_tag_t &y
+ ){
+ return x.offset < y.offset;
+ }
+};
#endif /*INCLUDED_GR_TAGS_H*/
diff --git a/include/gnuradio/tags.hpp b/include/gnuradio/tags.hpp
index d8414d8..c8eafba 100644
--- a/include/gnuradio/tags.hpp
+++ b/include/gnuradio/tags.hpp
@@ -18,34 +18,39 @@
#define INCLUDED_GNURADIO_TAGS_HPP
#include <gnuradio/gras.hpp>
+#include <boost/operators.hpp>
+
+//TODO -- this is a stub for the PMC libray
#include <gruel/pmt.h>
+typedef pmt::pmt_t PMC;
+typedef pmt::pmt_t PMCC;
namespace gnuradio
{
-struct GRAS_API Tag
+struct GRAS_API Tag : boost::less_than_comparable<Tag>
{
+ //! Make an empty tag with null members
+ Tag(void);
- //! the item \p tag occurred at (as a uint64_t)
- uint64_t offset;
+ //! Make a tag from parameters to initialize the members
+ Tag(const uint64_t &offset, const PMCC &key, const PMCC &value, const PMCC &srcid = PMCC());
- //! the key of \p tag (as a PMT symbol)
- pmt::pmt_t key;
+ //! the absolute item count associated with this tag
+ uint64_t offset;
- //! the value of \p tag (as a PMT)
- pmt::pmt_t value;
+ //! A symbolic name identifying the type of tag
+ PMCC key;
- //! the source ID of \p tag (as a PMT)
- pmt::pmt_t srcid;
+ //! The value of this tag -> the sample metadata
+ PMCC value;
- //! Comparison function to test which tag, \p x or \p y, came first in time
- static inline bool offset_compare(
- const Tag &x, const Tag &y
- ){
- return x.offset < y.offset;
- }
+ //! The optional source ID -> something unique
+ PMCC srcid;
};
+GRAS_API bool operator<(const Tag &lhs, const Tag &rhs);
+
} //namespace gnuradio
#endif /*INCLUDED_GNURADIO_TAGS_HPP*/
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;
+}