1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
/* -*- c++ -*- */
/*
* Copyright 2006 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* GNU Radio is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* GNU Radio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <mb_mblock.h>
#include <mb_mblock_impl.h>
#include <mb_runtime.h>
#include <mb_exception.h>
#include <iostream>
static pmt_t s_sys_port = pmt_intern("%sys-port");
static pmt_t s_halt = pmt_intern("%halt");
mb_visitor::~mb_visitor()
{
// nop base case for virtual destructor.
}
mb_mblock::mb_mblock(mb_runtime *runtime,
const std::string &instance_name,
pmt_t user_arg)
: d_impl(mb_mblock_impl_sptr(
new mb_mblock_impl(dynamic_cast<mb_runtime_base*>(runtime),
this, instance_name)))
{
}
mb_mblock::~mb_mblock()
{
}
void
mb_mblock::initial_transition()
{
// default implementation does nothing
}
void
mb_mblock::handle_message(mb_message_sptr msg)
{
// default implementation does nothing
}
void
mb_mblock::main_loop()
{
while (1){
mb_message_sptr msg;
try {
while (1){
msg = impl()->msgq().get_highest_pri_msg();
// check for %halt from %sys-port
if (pmt_eq(msg->port_id(), s_sys_port) && pmt_eq(msg->signal(), s_halt))
exit();
handle_message(msg);
}
}
catch (pmt_exception e){
std::cerr << "\nmb_mblock::main_loop: ignored pmt_exception: "
<< e.what()
<< "\nin mblock instance \"" << instance_name()
<< "\" while handling message:"
<< "\n port_id = " << msg->port_id()
<< "\n signal = " << msg->signal()
<< "\n data = " << msg->data()
<< "\n metatdata = " << msg->metadata() << std::endl;
}
}
}
////////////////////////////////////////////////////////////////////////
// Forward other methods to implementation class //
////////////////////////////////////////////////////////////////////////
mb_port_sptr
mb_mblock::define_port(const std::string &port_name_string,
const std::string &protocol_class_name,
bool conjugated,
mb_port::port_type_t port_type)
{
return d_impl->define_port(port_name_string, protocol_class_name,
conjugated, port_type);
}
void
mb_mblock::define_component(const std::string &component_name,
const std::string &class_name,
pmt_t user_arg)
{
d_impl->define_component(component_name, class_name, user_arg);
}
void
mb_mblock::connect(const std::string &comp_name1, const std::string &port_name1,
const std::string &comp_name2, const std::string &port_name2)
{
d_impl->connect(comp_name1, port_name1,
comp_name2, port_name2);
}
void
mb_mblock::disconnect(const std::string &comp_name1, const std::string &port_name1,
const std::string &comp_name2, const std::string &port_name2)
{
d_impl->disconnect(comp_name1, port_name1,
comp_name2, port_name2);
}
void
mb_mblock::disconnect_component(const std::string &component_name)
{
d_impl->disconnect_component(component_name);
}
void
mb_mblock::disconnect_all()
{
d_impl->disconnect_all();
}
int
mb_mblock::nconnections() const
{
return d_impl->nconnections();
}
bool
mb_mblock::walk_tree(mb_visitor *visitor)
{
return d_impl->walk_tree(visitor);
}
std::string
mb_mblock::instance_name() const
{
return d_impl->instance_name();
}
void
mb_mblock::set_instance_name(const std::string &name)
{
d_impl->set_instance_name(name);
}
std::string
mb_mblock::class_name() const
{
return d_impl->class_name();
}
void
mb_mblock::set_class_name(const std::string &name)
{
d_impl->set_class_name(name);
}
mb_mblock *
mb_mblock::parent() const
{
return d_impl->mblock_parent();
}
void
mb_mblock::exit()
{
throw mbe_exit(); // adios...
}
void
mb_mblock::shutdown_all(pmt_t result)
{
d_impl->runtime()->request_shutdown(result);
}
pmt_t
mb_mblock::schedule_one_shot_timeout(const mb_time &abs_time, pmt_t user_data)
{
mb_msg_accepter_sptr accepter = impl()->make_accepter(s_sys_port);
return d_impl->runtime()->schedule_one_shot_timeout(abs_time, user_data,
accepter);
}
pmt_t
mb_mblock::schedule_periodic_timeout(const mb_time &first_abs_time,
const mb_time &delta_time,
pmt_t user_data)
{
mb_msg_accepter_sptr accepter = impl()->make_accepter(s_sys_port);
return d_impl->runtime()->schedule_periodic_timeout(first_abs_time,
delta_time,
user_data,
accepter);
}
void
mb_mblock::cancel_timeout(pmt_t handle)
{
d_impl->runtime()->cancel_timeout(handle);
}
|