summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
m---------gnuradio0
-rw-r--r--include/gras/block.hpp39
-rw-r--r--include/gras/tags.hpp10
-rw-r--r--lib/block.cpp33
-rw-r--r--lib/tag_handlers.hpp2
-rw-r--r--python/gras/GRAS_Block.i2
-rw-r--r--tests/demo_blocks.py7
7 files changed, 54 insertions, 39 deletions
diff --git a/gnuradio b/gnuradio
-Subproject 86c97917faa366bcbd4b69bf847c877d576a62e
+Subproject 62fe77518c3466d646cd63ffb6450c6e06c633b
diff --git a/include/gras/block.hpp b/include/gras/block.hpp
index 6765973..a45ddd3 100644
--- a/include/gras/block.hpp
+++ b/include/gras/block.hpp
@@ -8,7 +8,6 @@
#include <gras/tags.hpp>
#include <vector>
#include <string>
-#include <boost/range.hpp> //iterator range
namespace gras
{
@@ -143,45 +142,53 @@ struct GRAS_API Block : Element
******************************************************************/
//! Get the configuration rules of an input port
- InputPortConfig input_config(const size_t which_input = 0) const;
+ InputPortConfig input_config(const size_t which_input) const;
//! Set the configuration rules for an input port
- void set_input_config(const InputPortConfig &config, const size_t which_input = 0);
+ void set_input_config(const size_t which_input, const InputPortConfig &config);
//! Get the configuration rules of an output port
- OutputPortConfig output_config(const size_t which_output = 0) const;
+ OutputPortConfig output_config(const size_t which_output) const;
//! Set the configuration rules for an output port
- void set_output_config(const OutputPortConfig &config, const size_t which_output = 0);
+ void set_output_config(const size_t which_output, const OutputPortConfig &config);
/*******************************************************************
* Deal with data production and consumption
******************************************************************/
//! Call during work to consume items
- void consume(const size_t which_input, const size_t how_many_items);
+ void consume(const size_t num_items, const size_t which_input);
//! Call during work to produce items
- void produce(const size_t which_output, const size_t how_many_items);
+ void produce(const size_t num_items, const size_t which_output);
+
+ //! Get absolute count of all items consumed on the given input port
+ item_index_t num_items_consumed(const size_t which_input);
+
+ //! Get absolute count of all items produced on the given output port
+ item_index_t num_items_produced(const size_t which_output);
/*******************************************************************
* Deal with tag handling and tag configuration
******************************************************************/
- item_index_t nitems_read(const size_t which_input);
-
- item_index_t nitems_written(const size_t which_output);
-
//! Send a tag to the downstream on the given output port
void post_output_tag(const size_t which_output, const Tag &tag);
- //! Iterator return type get_input_tags - stl and boost compliant
- typedef boost::iterator_range<std::vector<Tag>::const_iterator> TagIter;
-
//! Get an iterator of item tags for the given input
- TagIter get_input_tags(const size_t which_input = 0);
+ TagIter get_input_tags(const size_t which_input);
- //! Overload me to implement tag propagation logic
+ /*!
+ * Overload me to implement tag propagation logic:
+ *
+ * Propagate tags will be given an iterator for all input tags
+ * whose offset counts is less than the number of items consumed.
+ * It is the job of the propagate_tags overload to
+ * propagate tags to the downstream and interpolate the offset.
+ * By default, the propagate_tags implementation is a NOP.
+ * Also, the user may simple propagate tags from within work.
+ */
virtual void propagate_tags(const size_t which_input, const TagIter &iter);
/*******************************************************************
diff --git a/include/gras/tags.hpp b/include/gras/tags.hpp
index 5702c1c..8b703fe 100644
--- a/include/gras/tags.hpp
+++ b/include/gras/tags.hpp
@@ -35,4 +35,14 @@ GRAS_API bool operator<(const Tag &lhs, const Tag &rhs);
} //namespace gras
+#include <boost/range.hpp> //iterator range
+#include <vector>
+
+namespace gras
+{
+ //! Iterator return type stl and boost compliant
+ typedef boost::iterator_range<std::vector<Tag>::const_iterator> TagIter;
+
+} //namespace gras
+
#endif /*INCLUDED_GRAS_TAGS_HPP*/
diff --git a/lib/block.cpp b/lib/block.cpp
index 78881ea..cc22508 100644
--- a/lib/block.cpp
+++ b/lib/block.cpp
@@ -37,8 +37,8 @@ Block::Block(const std::string &name):
(*this)->block->block_state = BlockActor::BLOCK_STATE_INIT;
//call block methods to init stuff
- this->set_input_config(InputPortConfig());
- this->set_output_config(OutputPortConfig());
+ this->set_input_config(0, InputPortConfig());
+ this->set_output_config(0, OutputPortConfig());
this->set_interruptible_work(false);
this->set_buffer_affinity(-1);
}
@@ -68,7 +68,7 @@ InputPortConfig Block::input_config(const size_t which_input) const
return vector_get((*this)->block->input_configs, which_input);
}
-void Block::set_input_config(const InputPortConfig &config, const size_t which_input)
+void Block::set_input_config(const size_t which_input, const InputPortConfig &config)
{
vector_set((*this)->block->input_configs, config, which_input);
if ((*this)->block->topology_init)
@@ -80,45 +80,42 @@ OutputPortConfig Block::output_config(const size_t which_output) const
return vector_get((*this)->block->output_configs, which_output);
}
-void Block::set_output_config(const OutputPortConfig &config, const size_t which_output)
+void Block::set_output_config(const size_t which_output, const OutputPortConfig &config)
{
vector_set((*this)->block->output_configs, config, which_output);
if ((*this)->block->topology_init)
(*this)->block->Push(UpdateInputsMessage(), Theron::Address());
}
-void Block::consume(const size_t which_input, const size_t how_many_items)
+void Block::consume(const size_t which_input, const size_t num_items)
{
- (*this)->block->consume(which_input, how_many_items);
+ (*this)->block->consume(which_input, num_items);
}
-void Block::produce(const size_t which_output, const size_t how_many_items)
+void Block::produce(const size_t which_output, const size_t num_items)
{
- (*this)->block->produce(which_output, how_many_items);
+ (*this)->block->produce(which_output, num_items);
}
-item_index_t Block::nitems_read(const size_t which_input)
+item_index_t Block::num_items_consumed(const size_t which_input)
{
return (*this)->block->items_consumed[which_input];
}
-item_index_t Block::nitems_written(const size_t which_output)
+item_index_t Block::num_items_produced(const size_t which_output)
{
return (*this)->block->items_produced[which_output];
}
-void Block::post_output_tag(
- const size_t which_output,
- const Tag &tag
-){
+void Block::post_output_tag(const size_t which_output, const Tag &tag)
+{
(*this)->block->post_downstream(which_output, InputTagMessage(tag));
}
-Block::TagIter Block::get_input_tags(
- const size_t which_input
-){
+TagIter Block::get_input_tags(const size_t which_input)
+{
const std::vector<Tag> &input_tags = (*this)->block->input_tags[which_input];
- return boost::make_iterator_range(input_tags.begin(), input_tags.end());
+ return TagIter(input_tags.begin(), input_tags.end());
}
void Block::propagate_tags(const size_t, const TagIter &)
diff --git a/lib/tag_handlers.hpp b/lib/tag_handlers.hpp
index 6f0bdf5..4e018b6 100644
--- a/lib/tag_handlers.hpp
+++ b/lib/tag_handlers.hpp
@@ -35,7 +35,7 @@ GRAS_FORCE_INLINE void BlockActor::trim_tags(const size_t i)
if (last == 0) return;
//call the overloaded propagate_tags to do the dirty work
- this->block_ptr->propagate_tags(i, boost::make_iterator_range(tags_i.begin(), tags_i.begin()+last));
+ this->block_ptr->propagate_tags(i, TagIter(tags_i.begin(), tags_i.begin()+last));
//now its safe to perform the erasure
tags_i.erase(tags_i.begin(), tags_i.begin()+last);
diff --git a/python/gras/GRAS_Block.i b/python/gras/GRAS_Block.i
index f7db3d2..3ee8691 100644
--- a/python/gras/GRAS_Block.i
+++ b/python/gras/GRAS_Block.i
@@ -175,7 +175,7 @@ struct BlockPython : Block
std::vector<Tag> get_input_tags(const size_t which_input)
{
- Block::TagIter it = Block::get_input_tags(which_input);
+ const TagIter it = Block::get_input_tags(which_input);
std::vector<Tag> tags(it.begin(), it.end());
return tags;
}
diff --git a/tests/demo_blocks.py b/tests/demo_blocks.py
index 9a7a02f..2b2d8dd 100644
--- a/tests/demo_blocks.py
+++ b/tests/demo_blocks.py
@@ -67,8 +67,9 @@ class TagSource(gras.Block):
self._values = values
def work(self, ins, outs):
- offset = self.nitems_written(0)
- self.post_output_tag(0, gras.Tag(offset, 'key', self._values[0]))
+ offset = self.num_items_produced(0)
+ tag = gras.Tag(offset, 'key', self._values[0])
+ self.post_output_tag(0, tag)
self.produce(0, len(outs[0]))
self._values = self._values[1:]
if not self._values:
@@ -86,7 +87,7 @@ class TagSink(gras.Block):
return tuple(self._values)
def work(self, ins, outs):
- max_read = self.nitems_read(0) + len(ins[0])
+ max_read = self.num_items_consumed(0) + len(ins[0])
for tag in self.get_input_tags(0):
if tag.offset < max_read:
self._values.append(tag.value)