Updated license from GPL version 2 or later to GPL version 3 or later.
[debian/gnuradio] / gnuradio-core / src / lib / runtime / gr_runtime.i
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2004,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 class gr_runtime;
24 typedef boost::shared_ptr<gr_runtime> gr_runtime_sptr;
25 %template(gr_runtime_sptr) boost::shared_ptr<gr_runtime>;
26
27 gr_runtime_sptr gr_make_runtime(gr_hier_block2_sptr top_block);
28
29 class gr_runtime
30 {
31 protected:
32     gr_runtime(gr_hier_block2_sptr top_block);
33
34 public:
35     void run() throw (std::runtime_error);
36     void start() throw (std::runtime_error);
37     void stop() throw (std::runtime_error);
38     void wait() throw (std::runtime_error);
39     void restart() throw (std::runtime_error);
40 };
41
42 %{
43 class ensure_py_gil_state2 {
44     PyGILState_STATE    d_gstate;
45 public:
46   ensure_py_gil_state2()  { d_gstate = PyGILState_Ensure(); }
47   ~ensure_py_gil_state2() { PyGILState_Release(d_gstate); }
48 };
49 %}
50
51 %inline %{
52 void runtime_run_unlocked(gr_runtime_sptr r) throw (std::runtime_error) 
53 {
54     ensure_py_gil_state2 _lock;
55     r->run();
56 }
57
58 void runtime_start_unlocked(gr_runtime_sptr r) throw (std::runtime_error) 
59 {
60     ensure_py_gil_state2 _lock;
61     r->start();
62 }
63
64 void runtime_stop_unlocked(gr_runtime_sptr r) throw (std::runtime_error) 
65 {
66     ensure_py_gil_state2 _lock;
67     r->stop();
68 }
69
70 void runtime_wait_unlocked(gr_runtime_sptr r) throw (std::runtime_error) 
71 {
72     ensure_py_gil_state2 _lock;
73     r->wait();
74 }
75
76 void runtime_restart_unlocked(gr_runtime_sptr r) throw (std::runtime_error) 
77 {
78     ensure_py_gil_state2 _lock;
79     r->restart();
80 }
81
82 %}