From 0a988ab506d3489e13222e9c7ddff889c6371ee6 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 31 Aug 2012 23:46:37 -0700 Subject: added comments and some cleanup code --- lib/CMakeLists.txt | 2 +- lib/block_handlers.cpp | 9 ++++-- lib/block_ports.cpp | 70 ---------------------------------------- lib/element.cpp | 6 ++++ lib/element_impl.hpp | 21 +++--------- lib/hier_block.cpp | 5 +++ lib/port_handlers.cpp | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/top_block.cpp | 7 ++++ 8 files changed, 118 insertions(+), 89 deletions(-) delete mode 100644 lib/block_ports.cpp create mode 100644 lib/port_handlers.cpp diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 6ec28c1..09fc704 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -14,7 +14,7 @@ list(APPEND gnuradio_core_sources ${CMAKE_CURRENT_SOURCE_DIR}/block_task.cpp ${CMAKE_CURRENT_SOURCE_DIR}/block_allocator.cpp ${CMAKE_CURRENT_SOURCE_DIR}/block_handlers.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/block_ports.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/port_handlers.cpp ${CMAKE_CURRENT_SOURCE_DIR}/hier_block.cpp ${CMAKE_CURRENT_SOURCE_DIR}/top_block.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gr_block.cpp diff --git a/lib/block_handlers.cpp b/lib/block_handlers.cpp index 8bf137d..fcaa359 100644 --- a/lib/block_handlers.cpp +++ b/lib/block_handlers.cpp @@ -19,10 +19,14 @@ using namespace gnuradio; -void ElementImpl::handle_block_msg(const tsbe::TaskInterface &task_iface, const tsbe::Wax &msg) -{ +void ElementImpl::handle_block_msg( + const tsbe::TaskInterface &task_iface, + const tsbe::Wax &msg +){ std::cout << "handle_block_msg in " << name << std::endl; + //a buffer has returned from the downstream + //(all interested consumers have finished with it) if (msg.type() == typeid(BufferReturnMessage)) { const BufferReturnMessage &message = msg.cast(); @@ -33,6 +37,7 @@ void ElementImpl::handle_block_msg(const tsbe::TaskInterface &task_iface, const return; } + //self kick, call the handle task method if (msg.type() == typeid(SelfKickMessage)) { this->handle_task(task_iface); diff --git a/lib/block_ports.cpp b/lib/block_ports.cpp deleted file mode 100644 index a0d9276..0000000 --- a/lib/block_ports.cpp +++ /dev/null @@ -1,70 +0,0 @@ -// -// 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 io_sig program. If not, see . - -#include "element_impl.hpp" - -using namespace gnuradio; - -void ElementImpl::handle_input_msg(const tsbe::TaskInterface &handle, const size_t index, const tsbe::Wax &msg) -{ - std::cout << "handle_input_msg in " << name << std::endl; - - if (msg.type() == typeid(tsbe::Buffer)) - { - if (this->block_state == BLOCK_STATE_DONE) return; - this->input_queues.push(index, msg.cast()); - this->handle_task(handle); - return; - } - if (msg.type() == typeid(Tag)) - { - this->input_tags[index].push_back(msg.cast()); - this->input_tags_changed[index] = true; - return; - } - if (msg.type() == typeid(Token)) - { - this->token_pool.insert(msg.cast()); - return; - } - if (msg.type() == typeid(CheckTokensMessage)) - { - if (this->input_queues.empty(index) and this->input_tokens[index].unique()) - { - this->mark_done(handle); - } - return; - } -} - -void ElementImpl::handle_output_msg(const tsbe::TaskInterface &handle, const size_t index, const tsbe::Wax &msg) -{ - std::cout << "handle_output_msg in " << name << std::endl; - - if (msg.type() == typeid(Token)) - { - this->token_pool.insert(msg.cast()); - return; - } - if (msg.type() == typeid(CheckTokensMessage)) - { - if (this->output_tokens[index].unique()) - { - this->mark_done(handle); - } - return; - } -} diff --git a/lib/element.cpp b/lib/element.cpp index e0269e7..addc04d 100644 --- a/lib/element.cpp +++ b/lib/element.cpp @@ -40,6 +40,12 @@ Element::Element(const std::string &name) this->set_output_signature(sig); } +ElementImpl::~ElementImpl(void) +{ + if (this->executor) this->top_block_cleanup(); + if (this->topology) this->hier_block_cleanup(); +} + long Element::unique_id(void) const { return (*this)->unique_id; diff --git a/lib/element_impl.hpp b/lib/element_impl.hpp index 4742993..333bfae 100644 --- a/lib/element_impl.hpp +++ b/lib/element_impl.hpp @@ -34,23 +34,11 @@ namespace gnuradio struct ElementImpl { - ElementImpl(void) - { - //NOP - } - ~ElementImpl(void) - { - if (this->executor) - { - TopBlockMessage event; - event.what = TopBlockMessage::INERT; - this->executor.post_msg(event); - } - children.clear(); - } - - std::vector > children; + //deconstructor stuff + ~ElementImpl(void); + void top_block_cleanup(void); + void hier_block_cleanup(void); //stuff for when its a block std::string name; @@ -109,6 +97,7 @@ struct ElementImpl tsbe::Block block; tsbe::Topology topology; tsbe::Executor executor; + std::vector > children; const tsbe::Element &get_elem(void) const { if (block) return block; diff --git a/lib/hier_block.cpp b/lib/hier_block.cpp index 47be7d0..3603612 100644 --- a/lib/hier_block.cpp +++ b/lib/hier_block.cpp @@ -32,6 +32,11 @@ HierBlock::HierBlock(const std::string &name): (*this)->topology = tsbe::Topology(config); } +void ElementImpl::hier_block_cleanup(void) +{ + this->children.clear(); +} + void HierBlock::connect(const Element &elem) { (*this)->topology.add_topology(elem->topology); diff --git a/lib/port_handlers.cpp b/lib/port_handlers.cpp new file mode 100644 index 0000000..2461b7d --- /dev/null +++ b/lib/port_handlers.cpp @@ -0,0 +1,87 @@ +// +// 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 io_sig program. If not, see . + +#include "element_impl.hpp" + +using namespace gnuradio; + +void ElementImpl::handle_input_msg( + const tsbe::TaskInterface &handle, + const size_t index, + const tsbe::Wax &msg +){ + std::cout << "handle_input_msg in " << name << std::endl; + + //handle incoming stream buffer, push into the queue + if (msg.type() == typeid(tsbe::Buffer)) + { + if (this->block_state == BLOCK_STATE_DONE) return; + this->input_queues.push(index, msg.cast()); + this->handle_task(handle); + return; + } + + //handle incoming stream tag, push into the tag storage + if (msg.type() == typeid(Tag)) + { + this->input_tags[index].push_back(msg.cast()); + this->input_tags_changed[index] = true; + return; + } + + //store the token of the upstream producer + if (msg.type() == typeid(Token)) + { + this->token_pool.insert(msg.cast()); + return; + } + + //an upstream block declared itself done, recheck the token + if (msg.type() == typeid(CheckTokensMessage)) + { + if (this->input_queues.empty(index) and this->input_tokens[index].unique()) + { + this->mark_done(handle); + } + return; + } +} + +void ElementImpl::handle_output_msg( + const tsbe::TaskInterface &handle, + const size_t index, + const tsbe::Wax &msg +){ + std::cout << "handle_output_msg in " << name << std::endl; + + //store the token of the downstream consumer + if (msg.type() == typeid(Token)) + { + this->token_pool.insert(msg.cast()); + return; + } + + + //a downstream block has declared itself done, recheck the token + if (msg.type() == typeid(CheckTokensMessage)) + { + if (this->output_tokens[index].unique()) + { + this->mark_done(handle); + } + return; + } +} diff --git a/lib/top_block.cpp b/lib/top_block.cpp index cf450b5..e0751b5 100644 --- a/lib/top_block.cpp +++ b/lib/top_block.cpp @@ -37,6 +37,13 @@ TopBlock::TopBlock(const std::string &name): std::cout << "===================================================" << std::endl; } +void ElementImpl::top_block_cleanup(void) +{ + TopBlockMessage event; + event.what = TopBlockMessage::INERT; + this->executor.post_msg(event); +} + void TopBlock::update(void) { this->start(); //ok to re-start, means update -- cgit