GNU Radio 3.5.1 C++ API
gr_block_executor.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2004,2008 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_BLOCK_EXECUTOR_H
00024 #define INCLUDED_GR_BLOCK_EXECUTOR_H
00025 
00026 #include <gr_core_api.h>
00027 #include <gr_runtime_types.h>
00028 #include <fstream>
00029 #include <gr_tags.h>
00030 
00031 //class gr_block_executor;
00032 //typedef boost::shared_ptr<gr_block_executor>  gr_block_executor_sptr;
00033 
00034 
00035 /*!
00036  * \brief Manage the execution of a single block.
00037  * \ingroup internal
00038  */
00039 
00040 class GR_CORE_API gr_block_executor {
00041 protected:
00042   gr_block_sptr                 d_block;        // The block we're trying to run
00043   std::ofstream                *d_log;
00044 
00045   // These are allocated here so we don't have to on each iteration
00046 
00047   gr_vector_int                 d_ninput_items_required;
00048   gr_vector_int                 d_ninput_items;
00049   gr_vector_const_void_star     d_input_items;
00050   std::vector<bool>             d_input_done;
00051   gr_vector_void_star           d_output_items;
00052   std::vector<uint64_t>         d_start_nitems_read; //stores where tag counts are before work
00053   std::vector<gr_tag_t>       d_returned_tags;
00054   int                           d_max_noutput_items;
00055 
00056  public:
00057   gr_block_executor(gr_block_sptr block, int max_noutput_items=100000);
00058   ~gr_block_executor ();
00059 
00060   enum state {
00061     READY,            // We made progress; everything's cool.
00062     READY_NO_OUTPUT,  // We consumed some input, but produced no output.
00063     BLKD_IN,          // no progress; we're blocked waiting for input data.
00064     BLKD_OUT,         // no progress; we're blocked waiting for output buffer space.
00065     DONE,             // we're done; don't call me again.
00066   };
00067 
00068   /*
00069    * \brief Run one iteration.
00070    */
00071   state run_one_iteration();
00072 };
00073 
00074 #endif /* INCLUDED_GR_BLOCK_EXECUTOR_H */