Updated license from GPL version 2 or later to GPL version 3 or later.
[debian/gnuradio] / gnuradio-core / src / lib / runtime / gr_runtime.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2006,2007 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_RUNTIME_H
24 #define INCLUDED_GR_RUNTIME_H
25
26 #include <gr_runtime_types.h>
27
28 class gr_runtime_impl;
29
30 gr_runtime_sptr gr_make_runtime(gr_hier_block2_sptr top_block);
31
32 /*!
33  *\brief Runtime object that controls simple flow graph operation
34  *
35  * This class is instantiated with a top-level gr_hier_block2. The
36  * runtime then flattens the hierarchical block into a gr_simple_flowgraph,
37  * and allows control through start(), stop(), wait(), and run().
38  * 
39  */
40 class gr_runtime
41 {
42 private:
43   gr_runtime(gr_hier_block2_sptr top_block);
44   friend gr_runtime_sptr gr_make_runtime(gr_hier_block2_sptr top_block);
45
46   gr_runtime_impl *d_impl;
47     
48 public:
49   ~gr_runtime();
50
51   /*!
52    * Start the flow graph.  Creates an undetached scheduler thread for
53    * each flow graph partition. Returns to caller once created.
54    */
55   void start();
56   
57   /*!
58    * Stop a running flow graph.  Tells each created scheduler thread
59    * to exit, then returns to caller.
60    */
61   void stop();
62
63   /*!
64    * Wait for a stopped flow graph to complete.  Joins each completed
65    * thread.
66    */
67   void wait();
68
69   /*!
70    * Calls start(), then wait().  Used to run a flow graph that will stop
71    * on its own, or to run a flow graph indefinitely until SIGTERM is
72    * received().
73    */
74   void run();
75
76   /*!
77    * Restart a running flow graph, after topology changes have
78    * been made to its top_block (or children). Causes each created 
79    * scheduler thread to end, recalculates the flow graph, and 
80    * recreates new threads (possibly a different number from before.)
81    */
82   void restart();
83
84   /*!
85    * Lock a flow graph in preparation for reconfiguration.  When an equal
86    * number of calls to lock() and unlock() have occurred, the flow graph
87    * will be restarted automatically.
88    *
89    * N.B. lock() and unlock() cannot be called from a flow graph thread or
90    * deadlock will occur when reconfiguration happens.
91    */
92   void lock();
93
94   /*!
95    * Lock a flow graph in preparation for reconfiguration.  When an equal
96    * number of calls to lock() and unlock() have occurred, the flow graph
97    * will be restarted automatically.
98    *
99    * N.B. lock() and unlock() cannot be called from a flow graph thread or
100    * deadlock will occur when reconfiguration happens.
101    */
102   void unlock();
103 };
104
105 #endif /* INCLUDED_GR_RUNTIME_H */