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>
33 static pmt_t s_sys_port = pmt_intern("%sys-port");
34 static pmt_t s_halt = pmt_intern("%halt");
36 mb_visitor::~mb_visitor()
38 // nop base case for virtual destructor.
42 mb_mblock::mb_mblock(mb_runtime *runtime,
43 const std::string &instance_name,
45 : d_impl(mb_mblock_impl_sptr(
46 new mb_mblock_impl(dynamic_cast<mb_runtime_base*>(runtime),
47 this, instance_name)))
51 mb_mblock::~mb_mblock()
57 mb_mblock::initial_transition()
59 // default implementation does nothing
63 mb_mblock::handle_message(mb_message_sptr msg)
65 // default implementation does nothing
70 mb_mblock::main_loop()
76 msg = impl()->msgq().get_highest_pri_msg();
78 // check for %halt from %sys-port
79 if (pmt_eq(msg->port_id(), s_sys_port) && pmt_eq(msg->signal(), s_halt))
85 catch (pmt_exception e){
86 std::cerr << "\nmb_mblock::main_loop: ignored pmt_exception: "
88 << "\nin mblock instance \"" << instance_name()
89 << "\" while handling message:"
90 << "\n port_id = " << msg->port_id()
91 << "\n signal = " << msg->signal()
92 << "\n data = " << msg->data()
93 << "\n metatdata = " << msg->metadata() << std::endl;
98 ////////////////////////////////////////////////////////////////////////
99 // Forward other methods to implementation class //
100 ////////////////////////////////////////////////////////////////////////
103 mb_mblock::define_port(const std::string &port_name_string,
104 const std::string &protocol_class_name,
106 mb_port::port_type_t port_type)
108 return d_impl->define_port(port_name_string, protocol_class_name,
109 conjugated, port_type);
113 mb_mblock::define_component(const std::string &component_name,
114 const std::string &class_name,
118 d_impl->define_component(component_name, class_name, user_arg);
122 mb_mblock::connect(const std::string &comp_name1, const std::string &port_name1,
123 const std::string &comp_name2, const std::string &port_name2)
125 d_impl->connect(comp_name1, port_name1,
126 comp_name2, port_name2);
131 mb_mblock::disconnect(const std::string &comp_name1, const std::string &port_name1,
132 const std::string &comp_name2, const std::string &port_name2)
134 d_impl->disconnect(comp_name1, port_name1,
135 comp_name2, port_name2);
139 mb_mblock::disconnect_component(const std::string &component_name)
141 d_impl->disconnect_component(component_name);
145 mb_mblock::disconnect_all()
147 d_impl->disconnect_all();
151 mb_mblock::nconnections() const
153 return d_impl->nconnections();
157 mb_mblock::walk_tree(mb_visitor *visitor)
159 return d_impl->walk_tree(visitor);
163 mb_mblock::instance_name() const
165 return d_impl->instance_name();
169 mb_mblock::set_instance_name(const std::string &name)
171 d_impl->set_instance_name(name);
175 mb_mblock::class_name() const
177 return d_impl->class_name();
181 mb_mblock::set_class_name(const std::string &name)
183 d_impl->set_class_name(name);
187 mb_mblock::parent() const
189 return d_impl->mblock_parent();
195 throw mbe_exit(); // adios...
199 mb_mblock::shutdown_all(pmt_t result)
201 d_impl->runtime()->request_shutdown(result);
205 mb_mblock::schedule_one_shot_timeout(const mb_time &abs_time, pmt_t user_data)
207 mb_msg_accepter_sptr accepter = impl()->make_accepter(s_sys_port);
208 return d_impl->runtime()->schedule_one_shot_timeout(abs_time, user_data,
213 mb_mblock::schedule_periodic_timeout(const mb_time &first_abs_time,
214 const mb_time &delta_time,
217 mb_msg_accepter_sptr accepter = impl()->make_accepter(s_sys_port);
218 return d_impl->runtime()->schedule_periodic_timeout(first_abs_time,
225 mb_mblock::cancel_timeout(pmt_t handle)
227 d_impl->runtime()->cancel_timeout(handle);