GNU Radio 3.5.1 C++ API
gr_hier_block2.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2006,2007,2008,2009 Free Software Foundation, Inc.
00004  * 
00005  * This file is part of GNU Radio
00006  * 
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  * 
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 #ifndef INCLUDED_GR_HIER_BLOCK2_H
00023 #define INCLUDED_GR_HIER_BLOCK2_H
00024 
00025 #include <gr_core_api.h>
00026 #include <gr_basic_block.h>
00027 
00028 /*!
00029  * \brief public constructor for gr_hier_block2
00030 
00031  */
00032 GR_CORE_API gr_hier_block2_sptr gr_make_hier_block2(const std::string &name,
00033                                         gr_io_signature_sptr input_signature,
00034                                         gr_io_signature_sptr output_signature);
00035 
00036 class gr_hier_block2_detail;
00037 
00038 /*!
00039  * \brief Hierarchical container class for gr_block's and gr_hier_block2's
00040  * \ingroup container_blk
00041  * \ingroup base_blk
00042  *
00043  */
00044 class GR_CORE_API gr_hier_block2 : public gr_basic_block
00045 {
00046 private:
00047   friend class gr_hier_block2_detail;
00048   friend GR_CORE_API gr_hier_block2_sptr gr_make_hier_block2(const std::string &name,
00049                                                  gr_io_signature_sptr input_signature,
00050                                                  gr_io_signature_sptr output_signature);
00051   
00052   /*!
00053    * \brief Private implementation details of gr_hier_block2
00054    */
00055   gr_hier_block2_detail *d_detail;
00056     
00057 protected: 
00058   gr_hier_block2(const std::string &name,
00059                  gr_io_signature_sptr input_signature,
00060                  gr_io_signature_sptr output_signature);
00061   
00062 public:
00063   virtual ~gr_hier_block2();
00064   
00065   /*!
00066    * \brief typedef for object returned from self().
00067    *
00068    * This type is only guaranteed to be passable to connect and disconnect.
00069    * No other assumptions should be made about it.
00070    */
00071   typedef gr_basic_block_sptr   opaque_self;
00072 
00073   /*!
00074    * \brief Return an object, representing the current block, which can be passed to connect.
00075    *
00076    * The returned object may only be used as an argument to connect or disconnect.
00077    * Any other use of self() results in unspecified (erroneous) behavior.
00078    */
00079   opaque_self self();
00080 
00081   /*!
00082    * \brief Add a stand-alone (possibly hierarchical) block to internal graph
00083    *
00084    * This adds a gr-block or hierarchical block to the internal graph
00085    * without wiring it to anything else.
00086    */
00087   void connect(gr_basic_block_sptr block);
00088 
00089   /*!
00090    * \brief Add gr-blocks or hierarchical blocks to internal graph and wire together
00091    *
00092    * This adds (if not done earlier by another connect) a pair of gr-blocks or 
00093    * hierarchical blocks to the internal flowgraph, and wires the specified output 
00094    * port to the specified input port.
00095    */
00096   void connect(gr_basic_block_sptr src, int src_port, 
00097                gr_basic_block_sptr dst, int dst_port);
00098 
00099   /*!
00100    * \brief Remove a gr-block or hierarchical block from the internal flowgraph.
00101    *
00102    * This removes a gr-block or hierarchical block from the internal flowgraph,
00103    * disconnecting it from other blocks as needed.
00104    *
00105    */
00106   void disconnect(gr_basic_block_sptr block);
00107 
00108   /*!
00109    * \brief Disconnect a pair of gr-blocks or hierarchical blocks in internal
00110    *        flowgraph.
00111    *
00112    * This disconnects the specified input port from the specified output port
00113    * of a pair of gr-blocks or hierarchical blocks.
00114    */
00115   void disconnect(gr_basic_block_sptr src, int src_port,
00116                   gr_basic_block_sptr dst, int dst_port);
00117 
00118   /*!
00119    * \brief Disconnect all connections in the internal flowgraph.
00120    *
00121    * This call removes all output port to input port connections in the internal
00122    * flowgraph.
00123    */
00124   void disconnect_all();
00125 
00126   /*!
00127    * Lock a flowgraph in preparation for reconfiguration.  When an equal
00128    * number of calls to lock() and unlock() have occurred, the flowgraph
00129    * will be reconfigured.
00130    *
00131    * N.B. lock() and unlock() may not be called from a flowgraph thread
00132    * (E.g., gr_block::work method) or deadlock will occur when
00133    * reconfiguration happens.
00134    */
00135   virtual void lock();
00136 
00137   /*!
00138    * Unlock a flowgraph in preparation for reconfiguration.  When an equal
00139    * number of calls to lock() and unlock() have occurred, the flowgraph
00140    * will be reconfigured.
00141    *
00142    * N.B. lock() and unlock() may not be called from a flowgraph thread
00143    * (E.g., gr_block::work method) or deadlock will occur when
00144    * reconfiguration happens.
00145    */
00146   virtual void unlock();
00147 
00148   // This is a public method for ease of code organization, but should be
00149   // ignored by the user.
00150   gr_flat_flowgraph_sptr flatten() const;
00151 
00152   gr_hier_block2_sptr to_hier_block2(); // Needed for Python/Guile type coercion
00153 };
00154 
00155 inline gr_hier_block2_sptr cast_to_hier_block2_sptr(gr_basic_block_sptr block) {
00156   return boost::dynamic_pointer_cast<gr_hier_block2, gr_basic_block>(block);
00157 }
00158 
00159 #endif /* INCLUDED_GR_HIER_BLOCK2_H */