From 9b7a98d56ffefa71fb9d0b14cf7d56740dc890c8 Mon Sep 17 00:00:00 2001 From: eb Date: Tue, 28 Aug 2007 06:12:16 +0000 Subject: Refactored flatten into const-correct functional form. Beauty reigns. Merged -r6191:6192 from eb/fg. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@6194 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_hier_block2.cc | 8 +++++--- gnuradio-core/src/lib/runtime/gr_hier_block2.h | 2 +- gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc | 6 +++--- gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_top_block_impl.cc | 14 ++++++-------- 5 files changed, 17 insertions(+), 17 deletions(-) (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc index 890638bae..f531e76ad 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc @@ -77,8 +77,10 @@ gr_hier_block2::unlock() d_detail->unlock(); } -void -gr_hier_block2::flatten(gr_flat_flowgraph_sptr ffg) +gr_flat_flowgraph_sptr +gr_hier_block2::flatten() const { - d_detail->flatten(ffg); + gr_flat_flowgraph_sptr new_ffg = gr_make_flat_flowgraph(); + d_detail->flatten_aux(new_ffg); + return new_ffg; } diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index 75223d149..ba25b4b87 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -65,7 +65,7 @@ public: virtual void lock(); virtual void unlock(); - void flatten(gr_flat_flowgraph_sptr ffg); + gr_flat_flowgraph_sptr flatten() const; }; #endif /* INCLUDED_GR_HIER_BLOCK2_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index 15c898c77..e1b11205a 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -204,7 +204,7 @@ gr_hier_block2_detail::resolve_port(int port, bool is_input) } gr_endpoint -gr_hier_block2_detail::resolve_endpoint(const gr_endpoint &endp, bool is_input) +gr_hier_block2_detail::resolve_endpoint(const gr_endpoint &endp, bool is_input) const { // Check if endpoint is a leaf node if (boost::dynamic_pointer_cast(endp.block())) @@ -225,7 +225,7 @@ gr_hier_block2_detail::resolve_endpoint(const gr_endpoint &endp, bool is_input) } void -gr_hier_block2_detail::flatten(gr_flat_flowgraph_sptr sfg) +gr_hier_block2_detail::flatten_aux(gr_flat_flowgraph_sptr sfg) const { if (GR_HIER_BLOCK2_DETAIL_DEBUG) std::cout << "flattening " << d_owner->name() << std::endl; @@ -248,7 +248,7 @@ gr_hier_block2_detail::flatten(gr_flat_flowgraph_sptr sfg) for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { gr_hier_block2_sptr hier_block2(boost::dynamic_pointer_cast(*p)); if (hier_block2) - hier_block2->d_detail->flatten(sfg); + hier_block2->d_detail->flatten_aux(sfg); } } diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h index ace22ea9a..b692d1080 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h @@ -50,9 +50,9 @@ private: void connect_output(int my_port, int port, gr_basic_block_sptr block); void disconnect_input(int my_port, int port, gr_basic_block_sptr block); void disconnect_output(int my_port, int port, gr_basic_block_sptr block); - void flatten(gr_flat_flowgraph_sptr sfg); + void flatten_aux(gr_flat_flowgraph_sptr sfg) const; gr_endpoint resolve_port(int port, bool is_input); - gr_endpoint resolve_endpoint(const gr_endpoint &endp, bool is_input); + gr_endpoint resolve_endpoint(const gr_endpoint &endp, bool is_input) const; void lock(); void unlock(); diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc index 679654077..f25ab2b3e 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc @@ -63,7 +63,7 @@ runtime_sigint_handler(int signum) gr_top_block_impl::gr_top_block_impl(gr_top_block *owner) : d_running(false), - d_ffg(gr_make_flat_flowgraph()), + d_ffg(), d_owner(owner), d_lock_count(0) { @@ -86,8 +86,7 @@ gr_top_block_impl::start() throw std::runtime_error("already running"); // Create new flat flow graph by flattening hierarchy - d_ffg->clear(); - d_owner->flatten(d_ffg); + d_ffg = d_owner->flatten(); // Validate new simple flow graph and wire it up d_ffg->validate(); @@ -196,11 +195,10 @@ gr_top_block_impl::restart() if (GR_TOP_BLOCK_IMPL_DEBUG) std::cout << "restart: threads stopped" << std::endl; - // Create new simple flow graph - gr_flat_flowgraph_sptr new_ffg = gr_make_flat_flowgraph(); - d_owner->flatten(new_ffg); - new_ffg->validate(); - new_ffg->merge_connections(d_ffg); + // Create new simple flow graph + gr_flat_flowgraph_sptr new_ffg = d_owner->flatten(); + new_ffg->validate(); // check consistency, sanity, etc + new_ffg->merge_connections(d_ffg); // reuse buffers, etc if (GR_TOP_BLOCK_IMPL_DEBUG) std::cout << "restart: replacing old flow graph with new" << std::endl; -- cgit