diff options
author | Josh Blum | 2012-09-18 13:13:09 -0700 |
---|---|---|
committer | Josh Blum | 2012-09-18 13:13:09 -0700 |
commit | e951507b7f81d019ae0120c04554145dc0b5a257 (patch) | |
tree | b587cc9786bb692fa0c272ec661df5c37f51e387 /lib | |
parent | 85e3a7a3a450d0a778d0b730316c7d993d1f5c5f (diff) | |
download | sandhi-e951507b7f81d019ae0120c04554145dc0b5a257.tar.gz sandhi-e951507b7f81d019ae0120c04554145dc0b5a257.tar.bz2 sandhi-e951507b7f81d019ae0120c04554145dc0b5a257.zip |
added update hook for changing history/output multiple
Diffstat (limited to 'lib')
-rw-r--r-- | lib/block.cpp | 18 | ||||
-rw-r--r-- | lib/block_handlers.cpp | 38 | ||||
-rw-r--r-- | lib/element_impl.hpp | 2 | ||||
-rw-r--r-- | lib/gras_impl/messages.hpp | 5 |
4 files changed, 46 insertions, 17 deletions
diff --git a/lib/block.cpp b/lib/block.cpp index 48b18f3..63b52b2 100644 --- a/lib/block.cpp +++ b/lib/block.cpp @@ -28,12 +28,7 @@ Block::Block(void) Block::Block(const std::string &name): Element(name) { - this->set_input_history(0); - this->set_output_multiple(1); - this->set_fixed_rate(true); - this->set_relative_rate(1.0); - this->set_tag_propagation_policy(TPP_ALL_TO_ALL); - + //create internal block object tsbe::BlockConfig config; config.input_callback = boost::bind(&ElementImpl::handle_input_msg, this->get(), _1, _2, _3); config.output_callback = boost::bind(&ElementImpl::handle_output_msg, this->get(), _1, _2, _3); @@ -41,10 +36,19 @@ Block::Block(const std::string &name): config.changed_callback = boost::bind(&ElementImpl::topology_update, this->get(), _1); (*this)->block = tsbe::Block(config); + //setup some state variables + (*this)->topology_init = false; (*this)->forecast_fail = false; (*this)->block_ptr = this; (*this)->hint = 0; (*this)->block_state = ElementImpl::BLOCK_STATE_INIT; + + //call block methods to init stuff + this->set_input_history(0); + this->set_output_multiple(1); + this->set_fixed_rate(true); + this->set_relative_rate(1.0); + this->set_tag_propagation_policy(TPP_ALL_TO_ALL); } template <typename V, typename T> @@ -75,6 +79,7 @@ size_t Block::input_history(const size_t which_input) const void Block::set_input_history(const size_t history, const size_t which_input) { vector_set((*this)->input_history_items, history, which_input); + if ((*this)->topology_init) (*this)->block.post_msg(UpdateInputsMessage()); } size_t Block::output_multiple(const size_t which_output) const @@ -85,6 +90,7 @@ size_t Block::output_multiple(const size_t which_output) const void Block::set_output_multiple(const size_t multiple, const size_t which_output) { vector_set((*this)->output_multiple_items, multiple, which_output); + if ((*this)->topology_init) (*this)->block.post_msg(UpdateInputsMessage()); } void Block::consume(const size_t which_input, const size_t how_many_items) diff --git a/lib/block_handlers.cpp b/lib/block_handlers.cpp index 684b6fa..a069387 100644 --- a/lib/block_handlers.cpp +++ b/lib/block_handlers.cpp @@ -76,6 +76,13 @@ void ElementImpl::handle_block_msg( return; } + //user changed some input settings like history or reserve reqs + if (msg.type() == typeid(UpdateInputsMessage)) + { + this->input_update(task_iface); + return; + } + ASSERT(msg.type() == typeid(TopBlockMessage)); const size_t num_inputs = task_iface.get_num_inputs(); @@ -180,23 +187,32 @@ void ElementImpl::topology_update(const tsbe::TaskInterface &task_iface) this->input_tags_changed.resize(num_inputs); this->input_tags.resize(num_inputs); + //TODO: think more about this: + if (num_inputs == 0 and num_outputs == 0) + { + HERE(); + this->mark_done(task_iface); + } + + this->topology_init = true; + this->input_update(task_iface); +} + +void ElementImpl::input_update(const tsbe::TaskInterface &task_iface) +{ + const size_t num_inputs = task_iface.get_num_inputs(); + const size_t num_outputs = task_iface.get_num_outputs(); + //impose input reserve requirements based on relative rate and output multiple - this->input_multiple_items.resize(num_inputs, 1); + resize_fill_grow(this->input_multiple_items, num_inputs, 1); for (size_t i = 0; i < num_inputs; i++) { //TODO, this is a little cheap, we only look at output multiple [0] const size_t multiple = (num_outputs)?this->output_multiple_items.front():1; - input_multiple_items[i] = size_t(std::ceil(multiple/this->relative_rate)); - if (input_multiple_items[i] == 0) input_multiple_items[i] = 1; + this->input_multiple_items[i] = size_t(std::ceil(multiple/this->relative_rate)); + if (this->input_multiple_items[i] == 0) this->input_multiple_items[i] = 1; } //init the history comprehension on input queues - this->input_queues.init(this->input_history_items, input_multiple_items, this->input_items_sizes); - - //TODO: think more about this: - if (num_inputs == 0 and num_outputs == 0) - { - HERE(); - this->mark_done(task_iface); - } + this->input_queues.init(this->input_history_items, this->input_multiple_items, this->input_items_sizes); } diff --git a/lib/element_impl.hpp b/lib/element_impl.hpp index 18edfce..39895fe 100644 --- a/lib/element_impl.hpp +++ b/lib/element_impl.hpp @@ -133,6 +133,7 @@ struct ElementImpl void mark_done(const tsbe::TaskInterface &); void conclusion(const tsbe::TaskInterface &task_iface, const bool); void buffer_returner(const size_t index, SBuffer &buffer); + void input_update(const tsbe::TaskInterface &task_iface); //work helpers int work_ret; @@ -159,6 +160,7 @@ struct ElementImpl double relative_rate; bool forecast_fail; bool forecast_enable; + bool topology_init; }; } //namespace gnuradio diff --git a/lib/gras_impl/messages.hpp b/lib/gras_impl/messages.hpp index e1a3565..8c6664f 100644 --- a/lib/gras_impl/messages.hpp +++ b/lib/gras_impl/messages.hpp @@ -59,6 +59,11 @@ struct BufferHintMessage WeakToken token; }; +struct UpdateInputsMessage +{ + //empty +}; + } //namespace gnuradio #endif /*INCLUDED_LIBGRAS_IMPL_MESSAGES_HPP*/ |