#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()
- : d_impl(mb_mblock_impl_sptr(new mb_mblock_impl(this)))
+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()
{
- disconnect_all();
-
- // FIXME more?
}
void
-mb_mblock::init_fsm()
+mb_mblock::initial_transition()
{
// default implementation does nothing
}
// 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 //
////////////////////////////////////////////////////////////////////////
void
mb_mblock::define_component(const std::string &component_name,
- mb_mblock_sptr component)
+ const std::string &class_name,
+ pmt_t user_arg)
+
{
- d_impl->define_component(component_name, component);
+ d_impl->define_component(component_name, class_name, user_arg);
}
void
}
void
-mb_mblock::disconnect_component(const std::string component_name)
+mb_mblock::disconnect_component(const std::string &component_name)
{
d_impl->disconnect_component(component_name);
}
}
bool
-mb_mblock::walk_tree(mb_visitor *visitor, const std::string &path)
+mb_mblock::walk_tree(mb_visitor *visitor)
{
- return d_impl->walk_tree(visitor, path);
+ return d_impl->walk_tree(visitor);
}
std::string
}
void
-mb_mblock::set_instance_name(const std::string name)
+mb_mblock::set_instance_name(const std::string &name)
{
d_impl->set_instance_name(name);
}
}
void
-mb_mblock::set_class_name(const std::string name)
+mb_mblock::set_class_name(const std::string &name)
{
d_impl->set_class_name(name);
}
{
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);
+}
+