GNU Radio 3.5.3.2 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 (void){} //allows pure virtual interface sub-classes
00059   gr_hier_block2(const std::string &name,
00060                  gr_io_signature_sptr input_signature,
00061                  gr_io_signature_sptr output_signature);
00062   
00063 public:
00064   virtual ~gr_hier_block2();
00065   
00066   /*!
00067    * \brief typedef for object returned from self().
00068    *
00069    * This type is only guaranteed to be passable to connect and disconnect.
00070    * No other assumptions should be made about it.
00071    */
00072   typedef gr_basic_block_sptr   opaque_self;
00073 
00074   /*!
00075    * \brief Return an object, representing the current block, which can be passed to connect.
00076    *
00077    * The returned object may only be used as an argument to connect or disconnect.
00078    * Any other use of self() results in unspecified (erroneous) behavior.
00079    */
00080   opaque_self self();
00081 
00082   /*!
00083    * \brief Add a stand-alone (possibly hierarchical) block to internal graph
00084    *
00085    * This adds a gr-block or hierarchical block to the internal graph
00086    * without wiring it to anything else.
00087    */
00088   void connect(gr_basic_block_sptr block);
00089 
00090   /*!
00091    * \brief Add gr-blocks or hierarchical blocks to internal graph and wire together
00092    *
00093    * This adds (if not done earlier by another connect) a pair of gr-blocks or 
00094    * hierarchical blocks to the internal flowgraph, and wires the specified output 
00095    * port to the specified input port.
00096    */
00097   void connect(gr_basic_block_sptr src, int src_port, 
00098                gr_basic_block_sptr dst, int dst_port);
00099 
00100   /*!
00101    * \brief Remove a gr-block or hierarchical block from the internal flowgraph.
00102    *
00103    * This removes a gr-block or hierarchical block from the internal flowgraph,
00104    * disconnecting it from other blocks as needed.
00105    *
00106    */
00107   void disconnect(gr_basic_block_sptr block);
00108 
00109   /*!
00110    * \brief Disconnect a pair of gr-blocks or hierarchical blocks in internal
00111    *        flowgraph.
00112    *
00113    * This disconnects the specified input port from the specified output port
00114    * of a pair of gr-blocks or hierarchical blocks.
00115    */
00116   void disconnect(gr_basic_block_sptr src, int src_port,
00117                   gr_basic_block_sptr dst, int dst_port);
00118 
00119   /*!
00120    * \brief Disconnect all connections in the internal flowgraph.
00121    *
00122    * This call removes all output port to input port connections in the internal
00123    * flowgraph.
00124    */
00125   void disconnect_all();
00126 
00127   /*!
00128    * Lock a flowgraph in preparation for reconfiguration.  When an equal
00129    * number of calls to lock() and unlock() have occurred, the flowgraph
00130    * will be reconfigured.
00131    *
00132    * N.B. lock() and unlock() may not be called from a flowgraph thread
00133    * (E.g., gr_block::work method) or deadlock will occur when
00134    * reconfiguration happens.
00135    */
00136   virtual void lock();
00137 
00138   /*!
00139    * Unlock a flowgraph in preparation for reconfiguration.  When an equal
00140    * number of calls to lock() and unlock() have occurred, the flowgraph
00141    * will be reconfigured.
00142    *
00143    * N.B. lock() and unlock() may not be called from a flowgraph thread
00144    * (E.g., gr_block::work method) or deadlock will occur when
00145    * reconfiguration happens.
00146    */
00147   virtual void unlock();
00148 
00149   // This is a public method for ease of code organization, but should be
00150   // ignored by the user.
00151   gr_flat_flowgraph_sptr flatten() const;
00152 
00153   gr_hier_block2_sptr to_hier_block2(); // Needed for Python/Guile type coercion
00154 };
00155 
00156 inline gr_hier_block2_sptr cast_to_hier_block2_sptr(gr_basic_block_sptr block) {
00157   return boost::dynamic_pointer_cast<gr_hier_block2, gr_basic_block>(block);
00158 }
00159 
00160 #endif /* INCLUDED_GR_HIER_BLOCK2_H */