3 * Copyright 2006,2008 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
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)
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.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <mblock/mblock.h>
27 #include <mb_mblock_impl.h>
28 #include <mblock/runtime.h>
29 #include <mblock/exception.h>
34 static pmt_t s_sys_port = pmt_intern("%sys-port");
35 static pmt_t s_halt = pmt_intern("%halt");
37 mb_visitor::~mb_visitor()
39 // nop base case for virtual destructor.
43 mb_mblock::mb_mblock(mb_runtime *runtime,
44 const std::string &instance_name,
46 : d_impl(mb_mblock_impl_sptr(
47 new mb_mblock_impl(dynamic_cast<mb_runtime_base*>(runtime),
48 this, instance_name)))
52 mb_mblock::~mb_mblock()
58 mb_mblock::initial_transition()
60 // default implementation does nothing
64 mb_mblock::handle_message(mb_message_sptr msg)
66 // default implementation does nothing
71 mb_mblock::main_loop()
77 msg = impl()->msgq().get_highest_pri_msg();
79 // check for %halt from %sys-port
80 if (pmt_eq(msg->port_id(), s_sys_port) && pmt_eq(msg->signal(), s_halt))
86 catch (pmt_exception e){
87 std::cerr << "\nmb_mblock::main_loop: ignored pmt_exception: "
89 << "\nin mblock instance \"" << instance_name()
90 << "\" while handling message:"
91 << "\n port_id = " << msg->port_id()
92 << "\n signal = " << msg->signal()
93 << "\n data = " << msg->data()
94 << "\n metatdata = " << msg->metadata() << std::endl;
99 ////////////////////////////////////////////////////////////////////////
100 // Forward other methods to implementation class //
101 ////////////////////////////////////////////////////////////////////////
104 mb_mblock::define_port(const std::string &port_name_string,
105 const std::string &protocol_class_name,
107 mb_port::port_type_t port_type)
109 return d_impl->define_port(port_name_string, protocol_class_name,
110 conjugated, port_type);
114 mb_mblock::define_component(const std::string &component_name,
115 const std::string &class_name,
119 d_impl->define_component(component_name, class_name, user_arg);
123 mb_mblock::connect(const std::string &comp_name1, const std::string &port_name1,
124 const std::string &comp_name2, const std::string &port_name2)
126 d_impl->connect(comp_name1, port_name1,
127 comp_name2, port_name2);
132 mb_mblock::disconnect(const std::string &comp_name1, const std::string &port_name1,
133 const std::string &comp_name2, const std::string &port_name2)
135 d_impl->disconnect(comp_name1, port_name1,
136 comp_name2, port_name2);
140 mb_mblock::disconnect_component(const std::string &component_name)
142 d_impl->disconnect_component(component_name);
146 mb_mblock::disconnect_all()
148 d_impl->disconnect_all();
152 mb_mblock::nconnections() const
154 return d_impl->nconnections();
158 mb_mblock::walk_tree(mb_visitor *visitor)
160 return d_impl->walk_tree(visitor);
164 mb_mblock::instance_name() const
166 return d_impl->instance_name();
170 mb_mblock::set_instance_name(const std::string &name)
172 d_impl->set_instance_name(name);
176 mb_mblock::class_name() const
178 return d_impl->class_name();
182 mb_mblock::set_class_name(const std::string &name)
184 d_impl->set_class_name(name);
188 mb_mblock::parent() const
190 return d_impl->mblock_parent();
196 throw mbe_exit(); // adios...
200 mb_mblock::shutdown_all(pmt_t result)
202 d_impl->runtime()->request_shutdown(result);
206 mb_mblock::schedule_one_shot_timeout(const mb_time &abs_time, pmt_t user_data)
208 mb_msg_accepter_sptr accepter = impl()->make_accepter(s_sys_port);
209 return d_impl->runtime()->schedule_one_shot_timeout(abs_time, user_data,
214 mb_mblock::schedule_periodic_timeout(const mb_time &first_abs_time,
215 const mb_time &delta_time,
218 mb_msg_accepter_sptr accepter = impl()->make_accepter(s_sys_port);
219 return d_impl->runtime()->schedule_periodic_timeout(first_abs_time,
226 mb_mblock::cancel_timeout(pmt_t handle)
228 d_impl->runtime()->cancel_timeout(handle);