diff options
Diffstat (limited to 'gnuradio-core/src/lib/runtime')
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_hier_block2.cc | 18 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_hier_block2.h | 24 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_hier_block2.i | 34 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc | 55 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h | 58 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_top_block.cc | 6 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_top_block.h | 5 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_top_block.i | 1 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_top_block_impl.h | 3 |
9 files changed, 140 insertions, 64 deletions
diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc index f531e76ad..23f274da7 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc @@ -52,6 +52,12 @@ gr_hier_block2::~gr_hier_block2() } void +gr_hier_block2::connect(gr_basic_block_sptr block) +{ + d_detail->connect(block); +} + +void gr_hier_block2::connect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port) { @@ -59,6 +65,12 @@ gr_hier_block2::connect(gr_basic_block_sptr src, int src_port, } void +gr_hier_block2::disconnect(gr_basic_block_sptr block) +{ + d_detail->disconnect(block); +} + +void gr_hier_block2::disconnect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port) { @@ -66,6 +78,12 @@ gr_hier_block2::disconnect(gr_basic_block_sptr src, int src_port, } void +gr_hier_block2::disconnect_all() +{ + d_detail->disconnect_all(); +} + +void gr_hier_block2::lock() { d_detail->lock(); diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index 7ecc0d770..6124e4d51 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -58,32 +58,18 @@ protected: public: virtual ~gr_hier_block2(); + void connect(gr_basic_block_sptr block); + void connect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port); + void disconnect(gr_basic_block_sptr block); + void disconnect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port); - /*! - * Lock a flowgraph in preparation for reconfiguration. When an equal - * number of calls to lock() and unlock() have occurred, the flowgraph - * will be restarted automatically. - * - * N.B. lock() and unlock() cannot be called from a flowgraph thread - * (E.g., gr_block::work method) or deadlock will occur when - * reconfiguration happens. - */ + void disconnect_all(); virtual void lock(); - - /*! - * Lock a flowgraph in preparation for reconfiguration. When an equal - * number of calls to lock() and unlock() have occurred, the flowgraph - * will be restarted automatically. - * - * N.B. lock() and unlock() cannot be called from a flowgraph thread - * (E.g., gr_block::work method) or deadlock will occur when - * reconfiguration happens. - */ virtual void unlock(); gr_flat_flowgraph_sptr flatten() const; diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.i b/gnuradio-core/src/lib/runtime/gr_hier_block2.i index b3882a6a8..5278eefce 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.i +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.i @@ -36,20 +36,24 @@ gr_hier_block2_sptr gr_make_hier_block2(const std::string name, class gr_hier_block2 : public gr_basic_block { private: - gr_hier_block2(const std::string name, - gr_io_signature_sptr input_signature, - gr_io_signature_sptr output_signature); - + gr_hier_block2(const std::string name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature); + public: - ~gr_hier_block2 (); - - // Add a named block to the container - void connect(gr_basic_block_sptr src, int src_port, - gr_basic_block_sptr dst, int dst_port) - throw (std::invalid_argument); - void disconnect(gr_basic_block_sptr src, int src_port, - gr_basic_block_sptr dst, int dst_port) - throw (std::invalid_argument); - void lock(); - void unlock(); + ~gr_hier_block2 (); + + void connect(gr_basic_block_sptr block) + throw (std::invalid_argument); + void connect(gr_basic_block_sptr src, int src_port, + gr_basic_block_sptr dst, int dst_port) + throw (std::invalid_argument); + void disconnect(gr_basic_block_sptr block) + throw (std::invalid_argument); + void disconnect(gr_basic_block_sptr src, int src_port, + gr_basic_block_sptr dst, int dst_port) + throw (std::invalid_argument); + void disconnect_all(); + void lock(); + void unlock(); }; 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 76d23cab0..26a28fabd 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -44,6 +44,27 @@ gr_hier_block2_detail::~gr_hier_block2_detail() d_owner = 0; // Don't use delete, we didn't allocate } +void +gr_hier_block2_detail::connect(gr_basic_block_sptr block) +{ + std::stringstream msg; + + // Check if duplicate + if (std::find(d_blocks.begin(), d_blocks.end(), block) != d_blocks.end()) { + msg << "Block " << block << " already connected."; + throw std::invalid_argument(msg.str()); + } + + // Check if has inputs or outputs + if (block->input_signature()->max_streams() != 0 || + block->output_signature()->max_streams() != 0) { + msg << "Block " << block << " must not have any input or output ports"; + throw std::invalid_argument(msg.str()); + } + + d_blocks.push_back(block); +} + void gr_hier_block2_detail::connect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port) @@ -100,6 +121,21 @@ gr_hier_block2_detail::connect(gr_basic_block_sptr src, int src_port, // TODO: connects to NC } +void +gr_hier_block2_detail::disconnect(gr_basic_block_sptr block) +{ + for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { + if (*p == block) { + d_blocks.erase(p); + return; + } + } + + std::stringstream msg; + msg << "cannot disconnect block " << block << ", not found"; + throw std::invalid_argument(msg.str()); +} + void gr_hier_block2_detail::disconnect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port) @@ -252,6 +288,15 @@ gr_hier_block2_detail::resolve_port(int port, bool is_input) return result; } +void +gr_hier_block2_detail::disconnect_all() +{ + d_fg->clear(); + d_blocks.clear(); + d_inputs.clear(); + d_outputs.clear(); +} + gr_endpoint gr_hier_block2_detail::resolve_endpoint(const gr_endpoint &endp, bool is_input) const { @@ -294,7 +339,15 @@ gr_hier_block2_detail::flatten_aux(gr_flat_flowgraph_sptr sfg) const sfg->connect(src_endp, dst_endp); } - gr_basic_block_vector_t blocks = d_fg->calc_used_blocks(); + // Construct unique list of blocks used either in edges or + // by themselves. I hate STL. + gr_basic_block_vector_t blocks, tmp = d_fg->calc_used_blocks(); + std::insert_iterator<gr_basic_block_vector_t> inserter(blocks, blocks.begin()); + std::vector<gr_basic_block_sptr>::const_iterator p; // Because flatten_aux is const + for (p = d_blocks.begin(); p != d_blocks.end(); p++) + tmp.push_back(*p); + sort(tmp.begin(), tmp.end()); + unique_copy(tmp.begin(), tmp.end(), inserter); // Recurse hierarchical children for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { 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 b692d1080..d31ae93e7 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h @@ -27,37 +27,37 @@ class gr_hier_block2_detail : boost::noncopyable { -private: - friend class gr_hier_block2; - friend class gr_runtime_impl; - - // Constructor--it's private, only friends can instantiate - gr_hier_block2_detail(gr_hier_block2 *owner); - - // Private implementation data - gr_hier_block2 *d_owner; - gr_hier_block2_detail *d_parent_detail; - gr_flowgraph_sptr d_fg; - gr_endpoint_vector_t d_inputs; - gr_endpoint_vector_t d_outputs; +public: + gr_hier_block2_detail(gr_hier_block2 *owner); + ~gr_hier_block2_detail(); - // Private implementation methods - void connect(gr_basic_block_sptr src, int src_port, - gr_basic_block_sptr dst, int dst_port); - void disconnect(gr_basic_block_sptr, int src_port, - gr_basic_block_sptr, int dst_port); - void connect_input(int my_port, int port, gr_basic_block_sptr block); - 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_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) const; - void lock(); - void unlock(); + void connect(gr_basic_block_sptr block); + void connect(gr_basic_block_sptr src, int src_port, + gr_basic_block_sptr dst, int dst_port); + void disconnect(gr_basic_block_sptr block); + void disconnect(gr_basic_block_sptr, int src_port, + gr_basic_block_sptr, int dst_port); + void disconnect_all(); + void lock(); + void unlock(); + void flatten_aux(gr_flat_flowgraph_sptr sfg) const; -public: - ~gr_hier_block2_detail(); +private: + + // Private implementation data + gr_hier_block2 *d_owner; + gr_hier_block2_detail *d_parent_detail; + gr_flowgraph_sptr d_fg; + gr_endpoint_vector_t d_inputs; + gr_endpoint_vector_t d_outputs; + gr_basic_block_vector_t d_blocks; + + void connect_input(int my_port, int port, gr_basic_block_sptr block); + 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); + gr_endpoint resolve_port(int port, bool is_input); + gr_endpoint resolve_endpoint(const gr_endpoint &endp, bool is_input) const; }; #endif /* INCLUDED_GR_HIER_BLOCK2_DETAIL_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.cc b/gnuradio-core/src/lib/runtime/gr_top_block.cc index 91248d347..10e377205 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block.cc @@ -88,3 +88,9 @@ gr_top_block::unlock() { d_impl->unlock(); } + +bool +gr_top_block::is_running() +{ + return d_impl->is_running(); +} diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.h b/gnuradio-core/src/lib/runtime/gr_top_block.h index d74903841..57c36ad3b 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block.h @@ -97,6 +97,11 @@ public: * reconfiguration happens. */ virtual void unlock(); + + /*! + * Returns true if flowgraph is running + */ + bool is_running(); }; #endif /* INCLUDED_GR_TOP_BLOCK_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.i b/gnuradio-core/src/lib/runtime/gr_top_block.i index 63ceec8b2..78c2e0b95 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.i +++ b/gnuradio-core/src/lib/runtime/gr_top_block.i @@ -46,6 +46,7 @@ public: void run(); void lock(); void unlock(); + bool is_running(); }; %{ diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h index 8052ce4fa..00cb7f979 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h @@ -53,6 +53,9 @@ public: // Unlock the top block at end of reconfiguration void unlock(); + // Return true if flowgraph is running + bool is_running() const { return d_running; } + private: bool d_running; |