summaryrefslogtreecommitdiff
path: root/gnuradio-runtime/lib
diff options
context:
space:
mode:
authorDavid Winter <david.winter@analog.com>2021-09-28 13:42:54 +0200
committermormj <34754695+mormj@users.noreply.github.com>2021-10-21 10:59:16 -0400
commitdb01027fd99c882cf8b3a7dad854606499778e3b (patch)
tree2b2acc3584dc36668ef3fb2493598e7abf7abd3c /gnuradio-runtime/lib
parent61709059f2e40a04ada73785812f19a5fc89cb8a (diff)
global: Replace stdio logging with logger
This commit replaces many uses of std::c{out,err} and printf with the appropriate GR_LOG_* directives. Signed-off-by: David Winter <david.winter@analog.com>
Diffstat (limited to 'gnuradio-runtime/lib')
-rw-r--r--gnuradio-runtime/lib/block.cc11
-rw-r--r--gnuradio-runtime/lib/flat_flowgraph.cc22
-rw-r--r--gnuradio-runtime/lib/flat_flowgraph.h3
-rw-r--r--gnuradio-runtime/lib/flowgraph.cc19
-rw-r--r--gnuradio-runtime/lib/hier_block2_detail.cc255
-rw-r--r--gnuradio-runtime/lib/hier_block2_detail.h4
-rw-r--r--gnuradio-runtime/lib/logger.cc2
7 files changed, 151 insertions, 165 deletions
diff --git a/gnuradio-runtime/lib/block.cc b/gnuradio-runtime/lib/block.cc
index e9f1a635bb..cddf5a5baa 100644
--- a/gnuradio-runtime/lib/block.cc
+++ b/gnuradio-runtime/lib/block.cc
@@ -16,7 +16,9 @@
#include <gnuradio/block_detail.h>
#include <gnuradio/block_registry.h>
#include <gnuradio/buffer.h>
+#include <gnuradio/logger.h>
#include <gnuradio/prefs.h>
+#include <boost/format.hpp>
#include <iostream>
#include <stdexcept>
@@ -357,8 +359,9 @@ long block::min_output_buffer(size_t i)
void block::set_min_output_buffer(long min_output_buffer)
{
- std::cout << "set_min_output_buffer on block " << unique_id() << " to "
- << min_output_buffer << std::endl;
+ GR_LOG_INFO(d_logger,
+ boost::format("set_min_output_buffer on block %s to %d") % unique_id() %
+ min_output_buffer);
for (int i = 0; i < output_signature()->max_streams(); i++) {
set_min_output_buffer(i, min_output_buffer);
}
@@ -594,13 +597,13 @@ void block::reset_perf_counters()
void block::system_handler(pmt::pmt_t msg)
{
- // std::cout << "system_handler " << msg << "\n";
+ // GR_LOG_INFO(d_logger, boost::format("system handler %s") % msg);
pmt::pmt_t op = pmt::car(msg);
if (pmt::eqv(op, d_pmt_done)) {
d_finished = pmt::to_long(pmt::cdr(msg));
global_block_registry.notify_blk(d_symbol_name);
} else {
- std::cout << "WARNING: bad message op on system port!\n";
+ GR_LOG_WARN(d_logger, "bad message op on system port!");
pmt::print(msg);
}
}
diff --git a/gnuradio-runtime/lib/flat_flowgraph.cc b/gnuradio-runtime/lib/flat_flowgraph.cc
index 150b74fd6e..0df75553e0 100644
--- a/gnuradio-runtime/lib/flat_flowgraph.cc
+++ b/gnuradio-runtime/lib/flat_flowgraph.cc
@@ -35,10 +35,7 @@ flat_flowgraph_sptr make_flat_flowgraph()
return flat_flowgraph_sptr(new flat_flowgraph());
}
-flat_flowgraph::flat_flowgraph()
-{
- configure_default_loggers(d_logger, d_debug_logger, "flat_flowgraph");
-}
+flat_flowgraph::flat_flowgraph() {}
flat_flowgraph::~flat_flowgraph() {}
@@ -130,8 +127,8 @@ buffer_sptr flat_flowgraph::allocate_buffer(basic_block_sptr block, int port)
// limit buffer size if indicated
if (grblock->max_output_buffer(port) > 0) {
- // std::cout << "constraining output items to " << block->max_output_buffer(port)
- // << "\n";
+ // GR_LOG_INFO(d_debug_logger, boost::format("constraining output items to %d")
+ // % block->max_output_buffer(port));
nitems = std::min((long)nitems, (long)grblock->max_output_buffer(port));
nitems -= nitems % grblock->output_multiple();
if (nitems < 1)
@@ -371,24 +368,25 @@ std::string flat_flowgraph::msg_edge_list()
void flat_flowgraph::dump()
{
for (edge_viter_t e = d_edges.begin(); e != d_edges.end(); e++)
- std::cout << " edge: " << (*e) << std::endl;
+ GR_LOG_INFO(d_logger, boost::format(" edge: %s") % *e);
for (basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) {
- std::cout << " block: " << (*p) << std::endl;
+ GR_LOG_INFO(d_logger, boost::format(" block: %s") % *p);
block_detail_sptr detail = cast_to_block_sptr(*p)->detail();
- std::cout << " detail @" << detail << ":" << std::endl;
+ GR_LOG_INFO(d_logger, boost::format(" detail @%s:") % detail);
int ni = detail->ninputs();
int no = detail->noutputs();
for (int i = 0; i < no; i++) {
buffer_sptr buffer = detail->output(i);
- std::cout << " output " << i << ": " << buffer << std::endl;
+ GR_LOG_INFO(d_logger, boost::format(" output %d: %s") % i % buffer);
}
for (int i = 0; i < ni; i++) {
buffer_reader_sptr reader = detail->input(i);
- std::cout << " reader " << i << ": " << reader
- << " reading from buffer=" << reader->buffer() << std::endl;
+ GR_LOG_INFO(d_logger,
+ boost::format(" reader %d: %s reading from buffer=%s") % i %
+ reader % reader->buffer());
}
}
}
diff --git a/gnuradio-runtime/lib/flat_flowgraph.h b/gnuradio-runtime/lib/flat_flowgraph.h
index 83f5d1b78a..deb0fe2c6a 100644
--- a/gnuradio-runtime/lib/flat_flowgraph.h
+++ b/gnuradio-runtime/lib/flat_flowgraph.h
@@ -90,9 +90,6 @@ private:
* start and restarts.
*/
void setup_buffer_alignment(block_sptr block);
-
- gr::logger_ptr d_logger;
- gr::logger_ptr d_debug_logger;
};
} /* namespace gr */
diff --git a/gnuradio-runtime/lib/flowgraph.cc b/gnuradio-runtime/lib/flowgraph.cc
index 4e60e16010..8c9f398d2f 100644
--- a/gnuradio-runtime/lib/flowgraph.cc
+++ b/gnuradio-runtime/lib/flowgraph.cc
@@ -22,13 +22,14 @@
namespace gr {
-constexpr bool FLOWGRAPH_DEBUG = false;
-
edge::~edge() {}
flowgraph_sptr make_flowgraph() { return flowgraph_sptr(new flowgraph()); }
-flowgraph::flowgraph() {}
+flowgraph::flowgraph()
+{
+ configure_default_loggers(d_logger, d_debug_logger, "flowgraph");
+}
flowgraph::~flowgraph() {}
@@ -76,8 +77,7 @@ void flowgraph::validate()
std::vector<int> used_ports;
int ninputs, noutputs;
- if (FLOWGRAPH_DEBUG)
- std::cout << "Validating block: " << (*p) << std::endl;
+ GR_LOG_DEBUG(d_debug_logger, boost::format("Validating block: %s") % *p);
used_ports = calc_used_ports(*p, true); // inputs
ninputs = used_ports.size();
@@ -125,17 +125,16 @@ void flowgraph::check_valid_port(gr::io_signature::sptr sig, int port)
void flowgraph::check_valid_port(const msg_endpoint& e)
{
- if (FLOWGRAPH_DEBUG)
- std::cout << "check_valid_port( " << e.block() << ", " << e.port() << ")\n";
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("check_valid_port(%s, %s)") % e.block() % e.port());
if (!e.block()->has_msg_port(e.port())) {
const gr::basic_block::msg_queue_map_t& msg_map = e.block()->get_msg_map();
- std::cout << "Could not find port: " << e.port() << " in:" << std::endl;
+ GR_LOG_WARN(d_logger, boost::format("Could not find port %s in:") % e.port());
for (gr::basic_block::msg_queue_map_t::const_iterator it = msg_map.begin();
it != msg_map.end();
++it)
- std::cout << it->first << std::endl;
- std::cout << std::endl;
+ GR_LOG_WARN(d_logger, boost::format(" %s") % it->first);
throw std::invalid_argument("invalid msg port in connect() or disconnect()");
}
}
diff --git a/gnuradio-runtime/lib/hier_block2_detail.cc b/gnuradio-runtime/lib/hier_block2_detail.cc
index d63195d36d..282ec79332 100644
--- a/gnuradio-runtime/lib/hier_block2_detail.cc
+++ b/gnuradio-runtime/lib/hier_block2_detail.cc
@@ -24,8 +24,6 @@
namespace gr {
-constexpr bool HIER_BLOCK2_DETAIL_DEBUG = false;
-
hier_block2_detail::hier_block2_detail(hier_block2* owner)
: d_owner(owner), d_parent_detail(0), d_fg(make_flowgraph())
{
@@ -48,6 +46,8 @@ hier_block2_detail::hier_block2_detail(hier_block2* owner)
d_max_output_buffer = std::vector<size_t>(std::max(max_outputs, 1), 0);
d_min_output_buffer = std::vector<size_t>(std::max(max_outputs, 1), 0);
+
+ configure_default_loggers(d_logger, d_debug_logger, "hier_block2_detail");
}
hier_block2_detail::~hier_block2_detail()
@@ -75,9 +75,9 @@ void hier_block2_detail::connect(basic_block_sptr block)
hier_block2_sptr hblock(cast_to_hier_block2_sptr(block));
if (hblock && hblock.get() != d_owner) {
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "connect: block is hierarchical, setting parent to " << this
- << std::endl;
+ GR_LOG_DEBUG(
+ d_debug_logger,
+ boost::format("connect: block is hierarchical, setting parent to %s") % this);
hblock->d_detail->d_parent_detail = this;
}
@@ -91,9 +91,9 @@ void hier_block2_detail::connect(basic_block_sptr src,
{
std::stringstream msg;
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "connecting: " << endpoint(src, src_port) << " -> "
- << endpoint(dst, dst_port) << std::endl;
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("connecting: %s -> %s") % endpoint(src, src_port) %
+ endpoint(dst, dst_port));
if (src.get() == dst.get())
throw std::invalid_argument(
@@ -103,16 +103,16 @@ void hier_block2_detail::connect(basic_block_sptr src,
hier_block2_sptr dst_block(cast_to_hier_block2_sptr(dst));
if (src_block && src.get() != d_owner) {
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "connect: src is hierarchical, setting parent to " << this
- << std::endl;
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("connect: src is hierarchical, setting parent to %s") %
+ this);
src_block->d_detail->d_parent_detail = this;
}
if (dst_block && dst.get() != d_owner) {
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "connect: dst is hierarchical, setting parent to " << this
- << std::endl;
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("connect: dst is hierarchical, setting parent to %s") %
+ this);
dst_block->d_detail->d_parent_detail = this;
}
@@ -149,8 +149,7 @@ void hier_block2_detail::msg_connect(basic_block_sptr src,
basic_block_sptr dst,
pmt::pmt_t dstport)
{
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "connecting message port..." << std::endl;
+ GR_LOG_DEBUG(d_debug_logger, "connecting message port...");
// add block uniquely to list to internal blocks
if (std::find(d_blocks.begin(), d_blocks.end(), dst) == d_blocks.end()) {
@@ -174,23 +173,25 @@ void hier_block2_detail::msg_connect(basic_block_sptr src,
hier_block2_sptr dst_block(cast_to_hier_block2_sptr(dst));
if (src_block && src.get() != d_owner) {
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "msg_connect: src is hierarchical, setting parent to " << this
- << std::endl;
+ GR_LOG_DEBUG(
+ d_debug_logger,
+ boost::format("msg_connect: src is hierarchical, setting parent to %s") %
+ this);
src_block->d_detail->d_parent_detail = this;
}
if (dst_block && dst.get() != d_owner) {
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "msg_connect: dst is hierarchical, setting parent to " << this
- << std::endl;
+ GR_LOG_DEBUG(
+ d_debug_logger,
+ boost::format("msg_connect: dst is hierarchical, setting parent to %s") %
+ this);
dst_block->d_detail->d_parent_detail = this;
}
// add edge for this message connection
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << boost::format("msg_connect( (%s, %s, %d), (%s, %s, %d) )\n") % src %
- srcport % hier_out % dst % dstport % hier_in;
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("msg_connect( (%s, %s, %d), (%s, %s, %d) )") % src %
+ srcport % hier_out % dst % dstport % hier_in);
d_fg->connect(msg_endpoint(src, srcport, hier_out),
msg_endpoint(dst, dstport, hier_in));
}
@@ -200,8 +201,7 @@ void hier_block2_detail::msg_disconnect(basic_block_sptr src,
basic_block_sptr dst,
pmt::pmt_t dstport)
{
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "disconnecting message port..." << std::endl;
+ GR_LOG_DEBUG(d_debug_logger, "disconnecting message port...");
// remove edge for this message connection
bool hier_in = false, hier_out = false;
@@ -257,9 +257,8 @@ void hier_block2_detail::disconnect(basic_block_sptr block)
hier_block2_sptr hblock(cast_to_hier_block2_sptr(block));
if (block && block.get() != d_owner) {
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "disconnect: block is hierarchical, clearing parent"
- << std::endl;
+ GR_LOG_DEBUG(d_debug_logger,
+ "disconnect: block is hierarchical, clearing parent");
hblock->d_detail->d_parent_detail = 0;
}
@@ -274,8 +273,8 @@ void hier_block2_detail::disconnect(basic_block_sptr block)
if ((*p).src().block() == block || (*p).dst().block() == block) {
edges.push_back(*p);
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "disconnect: block found in edge " << (*p) << std::endl;
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("disconnect: block found in edge %s") % *p);
}
}
@@ -296,9 +295,9 @@ void hier_block2_detail::disconnect(basic_block_sptr src,
basic_block_sptr dst,
int dst_port)
{
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "disconnecting: " << endpoint(src, src_port) << " -> "
- << endpoint(dst, dst_port) << std::endl;
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("disconnecting: %s -> %s") % endpoint(src, src_port) %
+ endpoint(dst, dst_port));
if (src.get() == dst.get())
throw std::invalid_argument(
@@ -308,14 +307,12 @@ void hier_block2_detail::disconnect(basic_block_sptr src,
hier_block2_sptr dst_block(cast_to_hier_block2_sptr(dst));
if (src_block && src.get() != d_owner) {
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "disconnect: src is hierarchical, clearing parent" << std::endl;
+ GR_LOG_DEBUG(d_debug_logger, "disconnect: src is hierarchical, clearing parent");
src_block->d_detail->d_parent_detail = 0;
}
if (dst_block && dst.get() != d_owner) {
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "disconnect: dst is hierarchical, clearing parent" << std::endl;
+ GR_LOG_DEBUG(d_debug_logger, "disconnect: dst is hierarchical, clearing parent");
dst_block->d_detail->d_parent_detail = 0;
}
@@ -448,10 +445,9 @@ endpoint_vector_t hier_block2_detail::resolve_port(int port, bool is_input)
{
std::stringstream msg;
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "Resolving port " << port << " as an "
- << (is_input ? "input" : "output") << " of " << d_owner->name()
- << std::endl;
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("Resolving port %s as an %s of %s") % port %
+ (is_input ? "input" : "output") % d_owner->name());
endpoint_vector_t result;
@@ -519,9 +515,8 @@ endpoint_vector_t hier_block2_detail::resolve_endpoint(const endpoint& endp,
// Check if endpoint is a leaf node
if (cast_to_block_sptr(endp.block())) {
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "Block " << endp.block() << " is a leaf node, returning."
- << std::endl;
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("Block %s is a leaf node, returning.") % endp.block());
result.push_back(endp);
return result;
}
@@ -529,9 +524,9 @@ endpoint_vector_t hier_block2_detail::resolve_endpoint(const endpoint& endp,
// Check if endpoint is a hierarchical block
hier_block2_sptr hier_block2(cast_to_hier_block2_sptr(endp.block()));
if (hier_block2) {
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "Resolving endpoint " << endp << " as an "
- << (is_input ? "input" : "output") << ", recursing" << std::endl;
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("Resolving endpoint %s as an %s, recursing") % endp %
+ (is_input ? "input" : "output"));
return hier_block2->d_detail->resolve_port(endp.port(), is_input);
}
@@ -542,9 +537,10 @@ endpoint_vector_t hier_block2_detail::resolve_endpoint(const endpoint& endp,
void hier_block2_detail::flatten_aux(flat_flowgraph_sptr sfg) const
{
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << " ** Flattening " << d_owner->name()
- << " parent: " << d_parent_detail << std::endl;
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format(" ** Flattening %s parent: %s") % d_owner->name() %
+ d_parent_detail);
+ ;
bool is_top_block = (d_parent_detail == NULL);
// Add my edges to the flow graph, resolving references to actual endpoints
@@ -563,15 +559,13 @@ void hier_block2_detail::flatten_aux(flat_flowgraph_sptr sfg) const
bool set_all_max_buff = d_owner->all_max_output_buffer_p();
// Get the min and max buffer length
if (set_all_min_buff) {
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "Getting (" << (d_owner->alias()).c_str() << ") min buffer"
- << std::endl;
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("Getting (%s) min buffer") % d_owner->alias());
min_buff = d_owner->min_output_buffer();
}
if (set_all_max_buff) {
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "Getting (" << (d_owner->alias()).c_str() << ") max buffer"
- << std::endl;
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("Getting (%s) max buffer") % d_owner->alias());
max_buff = d_owner->max_output_buffer();
}
@@ -587,19 +581,18 @@ void hier_block2_detail::flatten_aux(flat_flowgraph_sptr sfg) const
block_sptr bb = std::dynamic_pointer_cast<block>(b);
if (bb != 0) {
if (bb->min_output_buffer(0) != min_buff) {
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "Block (" << (bb->alias()).c_str()
- << ") min_buff (" << min_buff << ")" << std::endl;
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("Block (%s) min_buff (%d)") %
+ bb->alias() % min_buff);
bb->set_min_output_buffer(min_buff);
}
} else {
hier_block2_sptr hh = std::dynamic_pointer_cast<hier_block2>(b);
if (hh != 0) {
if (hh->min_output_buffer(0) != min_buff) {
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "HBlock (" << (hh->alias()).c_str()
- << ") min_buff (" << min_buff << ")"
- << std::endl;
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("HBlock (%s) min_buff (%d)") %
+ hh->alias() % min_buff);
hh->set_min_output_buffer(min_buff);
}
}
@@ -612,19 +605,18 @@ void hier_block2_detail::flatten_aux(flat_flowgraph_sptr sfg) const
block_sptr bb = std::dynamic_pointer_cast<block>(b);
if (bb != 0) {
if (bb->max_output_buffer(0) != max_buff) {
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "Block (" << (bb->alias()).c_str()
- << ") max_buff (" << max_buff << ")" << std::endl;
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("Block (%s) max_buff (%d)") %
+ bb->alias() % max_buff);
bb->set_max_output_buffer(max_buff);
}
} else {
hier_block2_sptr hh = std::dynamic_pointer_cast<hier_block2>(b);
if (hh != 0) {
if (hh->max_output_buffer(0) != max_buff) {
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "HBlock (" << (hh->alias()).c_str()
- << ") max_buff (" << max_buff << ")"
- << std::endl;
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("HBlock (%s) max_buff (%d)") %
+ hh->alias() % max_buff);
hh->set_max_output_buffer(max_buff);
}
}
@@ -639,19 +631,18 @@ void hier_block2_detail::flatten_aux(flat_flowgraph_sptr sfg) const
block_sptr bb = std::dynamic_pointer_cast<block>(b);
if (bb != 0) {
if (bb->min_output_buffer(0) != min_buff) {
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "Block (" << (bb->alias()).c_str()
- << ") min_buff (" << min_buff << ")" << std::endl;
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("Block (%s) min_buff (%d)") %
+ bb->alias() % min_buff);
bb->set_min_output_buffer(min_buff);
}
} else {
hier_block2_sptr hh = std::dynamic_pointer_cast<hier_block2>(b);
if (hh != 0) {
if (hh->min_output_buffer(0) != min_buff) {
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "HBlock (" << (hh->alias()).c_str()
- << ") min_buff (" << min_buff << ")"
- << std::endl;
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("HBlock (%s) min_buff (%d)") %
+ hh->alias() % min_buff);
hh->set_min_output_buffer(min_buff);
}
}
@@ -664,19 +655,21 @@ void hier_block2_detail::flatten_aux(flat_flowgraph_sptr sfg) const
block_sptr bb = std::dynamic_pointer_cast<block>(b);
if (bb != 0) {
if (bb->max_output_buffer(0) != max_buff) {
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "Block (" << (bb->alias()).c_str()
- << ") max_buff (" << max_buff << ")" << std::endl;
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("Block (%s) max_buff (%d)") %
+ bb->alias() % max_buff);
bb->set_max_output_buffer(max_buff);
}
} else {
hier_block2_sptr hh = std::dynamic_pointer_cast<hier_block2>(b);
if (hh != 0) {
if (hh->max_output_buffer(0) != max_buff) {
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "HBlock (" << (hh->alias()).c_str()
- << ") max_buff (" << max_buff << ")"
- << std::endl;
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("HBlock (%s) max_buff (%d)") %
+ hh->alias() % max_buff);
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("HBlock (%s) max_buff (%d)") %
+ hh->alias() % max_buff);
hh->set_max_output_buffer(max_buff);
}
}
@@ -685,12 +678,10 @@ void hier_block2_detail::flatten_aux(flat_flowgraph_sptr sfg) const
}
}
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "Flattening stream connections: " << std::endl;
+ GR_LOG_DEBUG(d_debug_logger, "Flattening stream connections: ");
for (p = edges.begin(); p != edges.end(); p++) {
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "Flattening edge " << (*p) << std::endl;
+ GR_LOG_DEBUG(d_debug_logger, boost::format("Flattening edge %s") % *p);
endpoint_vector_t src_endps = resolve_endpoint(p->src(), false);
endpoint_vector_t dst_endps = resolve_endpoint(p->dst(), true);
@@ -698,43 +689,40 @@ void hier_block2_detail::flatten_aux(flat_flowgraph_sptr sfg) const
endpoint_viter_t s, d;
for (s = src_endps.begin(); s != src_endps.end(); s++) {
for (d = dst_endps.begin(); d != dst_endps.end(); d++) {
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << (*s) << "->" << (*d) << std::endl;
+ GR_LOG_DEBUG(d_debug_logger, boost::format(" %s -> %s") % *s % *d);
sfg->connect(*s, *d);
}
}
}
// loop through flattening hierarchical connections
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "Flattening msg connections: " << std::endl;
+ GR_LOG_DEBUG(d_debug_logger, "Flattening msg connections: ");
std::vector<std::pair<msg_endpoint, bool>> resolved_endpoints;
for (q = msg_edges.begin(); q != msg_edges.end(); q++) {
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << boost::format(
- " flattening edge ( %s, %s, %d) -> ( %s, %s, %d)\n") %
- q->src().block() % q->src().port() % q->src().is_hier() %
- q->dst().block() % q->dst().port() % q->dst().is_hier();
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format(" flattening edge ( %s, %s, %d) -> ( %s, %s, %d)") %
+ q->src().block() % q->src().port() % q->src().is_hier() %
+ q->dst().block() % q->dst().port() % q->dst().is_hier());
if (q->src().is_hier() && q->src().block().get() == d_owner) {
// connection into this block ..
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "hier incoming port: " << q->src() << std::endl;
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("hier incoming port: %s") % q->src());
sfg->replace_endpoint(q->src(), q->dst(), false);
resolved_endpoints.push_back(std::pair<msg_endpoint, bool>(q->src(), false));
} else if (q->dst().is_hier() && q->dst().block().get() == d_owner) {
// connection out of this block
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "hier outgoing port: " << q->dst() << std::endl;
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("hier outgoing port: %s") % q->dst());
sfg->replace_endpoint(q->dst(), q->src(), true);
resolved_endpoints.push_back(std::pair<msg_endpoint, bool>(q->dst(), true));
} else {
// internal connection only
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "internal msg connection: " << q->src() << "-->" << q->dst()
- << std::endl;
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("internal msg connection: %s --> %s") % q->src() %
+ q->dst());
sfg->connect(q->src(), q->dst());
}
}
@@ -743,9 +731,9 @@ void hier_block2_detail::flatten_aux(flat_flowgraph_sptr sfg) const
resolved_endpoints.begin();
it != resolved_endpoints.end();
it++) {
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "sfg->clear_endpoint(" << (*it).first << ", " << (*it).second
- << ") " << std::endl;
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("sfg->clear_endpoint(%s, %s)") % it->first %
+ it->second);
sfg->clear_endpoint((*it).first, (*it).second);
}
@@ -799,19 +787,18 @@ void hier_block2_detail::flatten_aux(flat_flowgraph_sptr sfg) const
block_sptr bb = std::dynamic_pointer_cast<block>(blk);
if (bb != 0) {
int bb_src_port = d_outputs[i].port();
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "Block (" << (bb->alias()).c_str() << ") Port ("
- << bb_src_port << ") min_buff (" << min_buff << ")"
- << std::endl;
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("Block (%s) Port (%d) min_buff (d)") %
+ bb->alias() % bb_src_port % min_buff);
bb->set_min_output_buffer(bb_src_port, min_buff);
} else {
hier_block2_sptr hh = std::dynamic_pointer_cast<hier_block2>(blk);
if (hh != 0) {
int hh_src_port = d_outputs[i].port();
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "HBlock (" << (hh->alias()).c_str() << ") Port ("
- << hh_src_port << ") min_buff (" << min_buff << ")"
- << std::endl;
+ GR_LOG_DEBUG(
+ d_debug_logger,
+ boost::format("HBlock (%s) Port (%d) min_buff (%d)") %
+ hh->alias() % hh_src_port % min_buff);
hh->set_min_output_buffer(hh_src_port, min_buff);
}
}
@@ -823,19 +810,18 @@ void hier_block2_detail::flatten_aux(flat_flowgraph_sptr sfg) const
block_sptr bb = std::dynamic_pointer_cast<block>(blk);
if (bb != 0) {
int bb_src_port = d_outputs[i].port();
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "Block (" << (bb->alias()).c_str() << ") Port ("
- << bb_src_port << ") max_buff (" << max_buff << ")"
- << std::endl;
+ GR_LOG_DEBUG(d_debug_logger,
+ boost::format("Block (%s) Port (%d) max_buff (%d)") %
+ bb->alias() % bb_src_port % max_buff);
bb->set_max_output_buffer(bb_src_port, max_buff);
} else {
hier_block2_sptr hh = std::dynamic_pointer_cast<hier_block2>(blk);
if (hh != 0) {
int hh_src_port = d_outputs[i].port();
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "HBlock (" << (hh->alias()).c_str() << ") Port ("
- << hh_src_port << ") max_buff (" << max_buff << ")"
- << std::endl;
+ GR_LOG_DEBUG(
+ d_debug_logger,
+ boost::format("HBlock (%s) Port (%d) max_buff (%d)") %
+ hh->alias() % hh_src_port % max_buff);
hh->set_max_output_buffer(hh_src_port, max_buff);
}
}
@@ -852,9 +838,10 @@ void hier_block2_detail::flatten_aux(flat_flowgraph_sptr sfg) const
for (basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) {
hier_block2_sptr hier_block2(cast_to_hier_block2_sptr(*p));
if (hier_block2 && (hier_block2.get() != d_owner)) {
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "flatten_aux: recursing into hierarchical block "
- << hier_block2->alias() << std::endl;
+ GR_LOG_DEBUG(
+ d_debug_logger,
+ boost::format("flatten_aux: recursing into hierarchical block %s") %
+ hier_block2->alias());
hier_block2->d_detail->flatten_aux(sfg);
}
}
@@ -867,9 +854,9 @@ void hier_block2_detail::flatten_aux(flat_flowgraph_sptr sfg) const
}
// print all primitive connections at exit
- if (HIER_BLOCK2_DETAIL_DEBUG && is_top_block) {
- std::cout << "flatten_aux finished in top_block" << std::endl;
- sfg->dump();
+ if (is_top_block) {
+ GR_LOG_DEBUG(d_debug_logger, "flatten_aux finished in top_block");
+ // sfg->dump();
}
// if ctrlport is enabled, call setup RPC for all blocks in the flowgraph
@@ -885,8 +872,7 @@ void hier_block2_detail::flatten_aux(flat_flowgraph_sptr sfg) const
void hier_block2_detail::lock()
{
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "lock: entered in " << this << std::endl;
+ GR_LOG_DEBUG(d_debug_logger, boost::format("lock: entered in %s") % this);
if (d_parent_detail)
d_parent_detail->lock();
@@ -896,8 +882,7 @@ void hier_block2_detail::lock()
void hier_block2_detail::unlock()
{
- if (HIER_BLOCK2_DETAIL_DEBUG)
- std::cout << "unlock: entered in " << this << std::endl;
+ GR_LOG_DEBUG(d_debug_logger, boost::format("unlock: entered in %s") % this);
if (d_parent_detail)
d_parent_detail->unlock();
diff --git a/gnuradio-runtime/lib/hier_block2_detail.h b/gnuradio-runtime/lib/hier_block2_detail.h
index 35da1f922d..15a45e0091 100644
--- a/gnuradio-runtime/lib/hier_block2_detail.h
+++ b/gnuradio-runtime/lib/hier_block2_detail.h
@@ -13,6 +13,7 @@
#include <gnuradio/api.h>
#include <gnuradio/hier_block2.h>
+#include <gnuradio/logger.h>
#include <flat_flowgraph.h>
#include <boost/core/noncopyable.hpp>
@@ -65,6 +66,9 @@ private:
endpoint_vector_t d_outputs; // Single internal endpoint per external output
basic_block_vector_t d_blocks;
+ gr::logger_ptr d_logger;
+ gr::logger_ptr d_debug_logger;
+
void refresh_io_signature();
void connect_input(int my_port, int port, basic_block_sptr block);
void connect_output(int my_port, int port, basic_block_sptr block);
diff --git a/gnuradio-runtime/lib/logger.cc b/gnuradio-runtime/lib/logger.cc
index 3e9b313de7..4721571119 100644
--- a/gnuradio-runtime/lib/logger.cc
+++ b/gnuradio-runtime/lib/logger.cc
@@ -83,7 +83,7 @@ void logger_config::watch_file(std::string filename, unsigned int watch_period)
boost::this_thread::sleep(
boost::posix_time::time_duration(0, 0, watch_period, 0));
} catch (const boost::thread_interrupted&) {
- std::cout << "GNURadio leaving logger config file watch." << std::endl;
+ std::cerr << "GNURadio leaving logger config file watch." << std::endl;
break;
}
}