GNU Radio 3.7.1 C++ API
top_block.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2007-2009,2013 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 
00023 #ifndef INCLUDED_GR_TOP_BLOCK_H
00024 #define INCLUDED_GR_TOP_BLOCK_H
00025 
00026 #include <gnuradio/api.h>
00027 #include <gnuradio/hier_block2.h>
00028 
00029 namespace gr {
00030 
00031   class top_block_impl;
00032 
00033   GR_RUNTIME_API top_block_sptr make_top_block(const std::string &name);
00034 
00035   /*!
00036    *\brief Top-level hierarchical block representing a flowgraph
00037    * \ingroup container_blk
00038    */
00039   class GR_RUNTIME_API top_block : public hier_block2
00040   {
00041   private:
00042     friend GR_RUNTIME_API top_block_sptr
00043       make_top_block(const std::string &name);
00044 
00045     top_block_impl *d_impl;
00046 
00047   protected:
00048     top_block(const std::string &name);
00049 
00050   public:
00051     ~top_block();
00052 
00053     /*!
00054      * \brief The simple interface to running a flowgraph.
00055      *
00056      * Calls start() then wait(). Used to run a flowgraph that will
00057      * stop on its own, or when another thread will call stop().
00058      *
00059      * \param max_noutput_items the maximum number of output items
00060      * allowed for any block in the flowgraph. This passes through to
00061      * the start function; see that function for more details.
00062      */
00063     void run(int max_noutput_items=100000000);
00064 
00065     /*!
00066      * Start the contained flowgraph. Creates one or more threads to
00067      * execute the flow graph. Returns to the caller once the threads
00068      * are created. Calling start() on a top_block that is already
00069      * started IS an error.
00070      *
00071      * \param max_noutput_items the maximum number of output items
00072      * allowed for any block in the flowgraph; the noutput_items can
00073      * always be less than this, but this will cap it as a
00074      * maximum. Use this to adjust the maximum latency a flowgraph can
00075      * exhibit.
00076      */
00077     void start(int max_noutput_items=100000000);
00078 
00079     /*!
00080      * Stop the running flowgraph. Notifies each thread created by the
00081      * scheduler to shutdown, then returns to caller. Calling stop()
00082      * on a top_block that is already stopped IS NOT an error.
00083      */
00084     void stop();
00085 
00086     /*!
00087      * Wait for a flowgraph to complete. Flowgraphs complete when
00088      * either (1) all blocks indicate that they are done (typically
00089      * only when using blocks.file_source, or blocks.head, or (2)
00090      * after stop() has been called to request shutdown. Calling wait
00091      * on a top_block that is not running IS NOT an error (wait
00092      * returns w/o blocking).
00093      */
00094     void wait();
00095 
00096     /*!
00097      * Lock a flowgraph in preparation for reconfiguration. When an
00098      * equal number of calls to lock() and unlock() have occurred, the
00099      * flowgraph will be reconfigured.
00100      *
00101      * N.B. lock() and unlock() may not be called from a flowgraph
00102      * thread (E.g., block::work method) or deadlock will occur
00103      * when reconfiguration happens.
00104      */
00105     virtual void lock();
00106 
00107     /*!
00108      * Unlock a flowgraph in preparation for reconfiguration. When an
00109      * equal number of calls to lock() and unlock() have occurred, the
00110      * flowgraph will be reconfigured.
00111      *
00112      * N.B. lock() and unlock() may not be called from a flowgraph thread
00113      * (E.g., block::work method) or deadlock will occur when
00114      * reconfiguration happens.
00115      */
00116     virtual void unlock();
00117 
00118     /*!
00119      * Returns a string that lists the edge connections in the
00120      * flattened flowgraph.
00121      */
00122     std::string edge_list();
00123 
00124     /*!
00125      * Returns a string that lists the msg edge connections in the
00126      * flattened flowgraph.
00127      */
00128     std::string msg_edge_list();
00129 
00130     /*!
00131      * Displays flattened flowgraph edges and block connectivity
00132      */
00133     void dump();
00134 
00135     //! Get the number of max noutput_items in the flowgraph
00136     int max_noutput_items();
00137 
00138     //! Set the maximum number of noutput_items in the flowgraph
00139     void set_max_noutput_items(int nmax);
00140 
00141     top_block_sptr to_top_block(); // Needed for Python type coercion
00142 
00143     void setup_rpc();
00144   };
00145 
00146   inline top_block_sptr cast_to_top_block_sptr(basic_block_sptr block) {
00147     return boost::dynamic_pointer_cast<top_block, basic_block>(block);
00148   }
00149 
00150 } /* namespce gr */
00151 
00152 #endif /* INCLUDED_GR_TOP_BLOCK_H */