1 /* -*- c++ -*- */ 2 /* 3 * Copyright 2007,2008,2013 Free Software Foundation, Inc. 4 * 5 * This file is part of GNU Radio 6 * 7 * GNU Radio is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 3, or (at your option) 10 * any later version. 11 * 12 * GNU Radio is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with GNU Radio; see the file COPYING. If not, write to 19 * the Free Software Foundation, Inc., 51 Franklin Street, 20 * Boston, MA 02110-1301, USA. 21 */ 22 23 #ifndef INCLUDED_GR_TOP_BLOCK_IMPL_H 24 #define INCLUDED_GR_TOP_BLOCK_IMPL_H 25 26 #include "scheduler.h" 27 #include <gnuradio/api.h> 28 #include <gnuradio/thread/thread.h> 29 30 namespace gr { 31 32 /*! 33 *\brief Abstract implementation details of top_block 34 * \ingroup internal 35 * 36 * The actual implementation of top_block. Separate class allows 37 * decoupling of changes from dependent classes. 38 */ 39 class GR_RUNTIME_API top_block_impl 40 { 41 public: 42 top_block_impl(top_block* owner); 43 ~top_block_impl(); 44 45 // Create and start scheduler threads 46 void start(int max_noutput_items = 100000000); 47 48 // Signal scheduler threads to stop 49 void stop(); 50 51 // Wait for scheduler threads to exit 52 void wait(); 53 54 // Lock the top block to allow reconfiguration 55 void lock(); 56 57 // Unlock the top block at end of reconfiguration 58 void unlock(); 59 60 // Return a string list of edges 61 std::string edge_list(); 62 63 // Return a string list of msg edges 64 std::string msg_edge_list(); 65 66 // Dump the flowgraph to stdout 67 void dump(); 68 69 // Get the number of max noutput_items in the flowgraph 70 int max_noutput_items(); 71 72 // Set the maximum number of noutput_items in the flowgraph 73 void set_max_noutput_items(int nmax); 74 75 protected: 76 enum tb_state { IDLE, RUNNING }; 77 78 top_block* d_owner; 79 flat_flowgraph_sptr d_ffg; 80 scheduler_sptr d_scheduler; 81 82 gr::thread::mutex d_mutex; // protects d_state and d_lock_count 83 tb_state d_state; 84 int d_lock_count; 85 bool d_retry_wait; 86 boost::condition_variable d_lock_cond; 87 int d_max_noutput_items; 88 89 private: 90 void restart(); 91 void wait_for_jobs(); 92 }; 93 94 } /* namespace gr */ 95 96 #endif /* INCLUDED_GR_TOP_BLOCK_IMPL_H */ 97