aab8ea5ab1edfafe4a7ae726909ffd2963955f82
[debian/gnuradio] / gnuradio-core / src / lib / runtime / gr_runtime.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2006 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 2, 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 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include <gr_runtime.h>
28 #include <gr_runtime_impl.h>
29 #include <gr_local_sighandler.h>
30 #include <iostream>
31
32 static gr_runtime *s_runtime = 0;
33
34 gr_runtime_sptr 
35 gr_make_runtime(gr_hier_block2_sptr top_block)
36 {
37     return gr_runtime_sptr(new gr_runtime(top_block));
38 }
39
40 gr_runtime::gr_runtime(gr_hier_block2_sptr top_block)
41 {
42     d_impl = new gr_runtime_impl(top_block);
43     s_runtime = this;
44 }
45   
46 gr_runtime::~gr_runtime()
47 {
48     s_runtime = 0; // we don't own this
49     delete d_impl;
50 }
51
52 // FIXME: This prevents using more than one gr_runtime instance
53 static void 
54 runtime_sigint_handler(int signum)
55 {
56
57     if (s_runtime)
58         s_runtime->stop();
59 }
60
61 void 
62 gr_runtime::start()
63 {
64     gr_local_sighandler sigint(SIGINT, runtime_sigint_handler);
65
66     d_impl->start();
67 }
68
69 void 
70 gr_runtime::stop()
71 {
72     d_impl->stop();
73 }
74
75 void 
76 gr_runtime::wait()
77 {
78     gr_local_sighandler sigint(SIGINT, runtime_sigint_handler);
79
80     d_impl->wait();
81 }
82
83 void 
84 gr_runtime::run()
85 {
86     gr_local_sighandler sigint(SIGINT, runtime_sigint_handler);
87
88     d_impl->start();
89     d_impl->wait();
90 }