class Orocos::RubyTasks::TaskContext::LocalTaskContext

Internal handler used to represent the local RTT::TaskContext object

It is created from Ruby as it handles the RTT::TaskContext pointer

Attributes

name[R]
String

the task name

remote_task[R]
Orocos::TaskContext

the remote task

Public Class Methods

new(p1) click to toggle source
static VALUE local_task_context_new(VALUE klass, VALUE _name)
{
    std::string name = StringValuePtr(_name);
    LocalTaskContext* ruby_task = new LocalTaskContext(name);
    RTT::corba::CorbaDispatcher::Instance(ruby_task->ports(), ORO_SCHED_OTHER, RTT::os::LowestPriority);

    RTT::corba::TaskContextServer::Create(ruby_task);

    VALUE rlocal_task = Data_Wrap_Struct(cLocalTaskContext, 0, delete_local_task_context, new RLocalTaskContext(ruby_task));
    rb_obj_call_init(rlocal_task, 1, &_name);
    return rlocal_task;
}
new(name) click to toggle source
# File lib/orocos/ruby_tasks/task_context.rb, line 17
def initialize(name)
    @name = name
end

Public Instance Methods

do_create_attribute(klass, port_name, orocos_type_name) click to toggle source
static VALUE local_task_context_create_attribute(VALUE _task, VALUE _klass, VALUE _attribute_name, VALUE _type_name)
{
    std::string attribute_name = StringValuePtr(_attribute_name);
    std::string type_name = StringValuePtr(_type_name);
    RTT::types::TypeInfo* ti = get_type_info(type_name);
    if (!ti)
        rb_raise(rb_eArgError, "type %s is not registered on the RTT type system", type_name.c_str());

    RTT::types::ValueFactoryPtr factory = ti->getValueFactory();
    if (!factory)
        rb_raise(rb_eArgError, "it seems that the typekit for %s does not include the necessary factory", type_name.c_str());

    RTT::base::AttributeBase* attribute = factory->buildAttribute(attribute_name);
    VALUE ruby_attribute = Data_Wrap_Struct(_klass, 0, delete_rtt_ruby_attribute, attribute);
    local_task_context(_task).addAttribute(*attribute);

    VALUE args[4] = { rb_iv_get(_task, "@remote_task"), _attribute_name, _type_name };
    rb_obj_call_init(ruby_attribute, 3, args);
    return ruby_attribute;
}
do_create_port(klass, port_name, orocos_type_name) click to toggle source
static VALUE local_task_context_create_port(VALUE _task, VALUE _is_output, VALUE _klass, VALUE _port_name, VALUE _type_name)
{
    std::string port_name = StringValuePtr(_port_name);
    std::string type_name = StringValuePtr(_type_name);
    RTT::types::TypeInfo* ti = get_type_info(type_name);
    if (!ti)
        rb_raise(rb_eArgError, "type %s is not registered on the RTT type system", type_name.c_str());
    RTT::types::ConnFactoryPtr factory = ti->getPortFactory();
    if (!factory)
        rb_raise(rb_eArgError, "it seems that the typekit for %s does not include the necessary factory", type_name.c_str());

    RTT::base::PortInterface* port;
    VALUE ruby_port;
    if (RTEST(_is_output))
        port = factory->outputPort(port_name);
    else
        port = factory->inputPort(port_name);

    ruby_port = Data_Wrap_Struct(_klass, 0, delete_rtt_ruby_port, port);
    local_task_context(_task).ports()->addPort(*port);

    VALUE args[4] = { rb_iv_get(_task, "@remote_task"), _port_name, _type_name, Qnil };
    rb_obj_call_init(ruby_port, 4, args);
    return ruby_port;
}
do_create_property(klass, port_name, orocos_type_name) click to toggle source
static VALUE local_task_context_create_property(VALUE _task, VALUE _klass, VALUE _property_name, VALUE _type_name)
{
    std::string property_name = StringValuePtr(_property_name);
    std::string type_name = StringValuePtr(_type_name);
    RTT::types::TypeInfo* ti = get_type_info(type_name);
    if (!ti)
        rb_raise(rb_eArgError, "type %s is not registered on the RTT type system", type_name.c_str());

    RTT::types::ValueFactoryPtr factory = ti->getValueFactory();
    if (!factory)
        rb_raise(rb_eArgError, "it seems that the typekit for %s does not include the necessary factory", type_name.c_str());

    RTT::base::PropertyBase* property = factory->buildProperty(property_name, "");
    VALUE ruby_property = Data_Wrap_Struct(_klass, 0, delete_rtt_ruby_property, property);
    local_task_context(_task).addProperty(*property);

    VALUE args[4] = { rb_iv_get(_task, "@remote_task"), _property_name, _type_name };
    rb_obj_call_init(ruby_property, 3, args);
    return ruby_property;
}
do_remove_port(p1) click to toggle source
static VALUE local_task_context_remove_port(VALUE obj, VALUE _port_name)
{
    std::string port_name = StringValuePtr(_port_name);
    LocalTaskContext& task(local_task_context(obj));
    RTT::DataFlowInterface& di(*task.ports());
    RTT::base::PortInterface* port = di.getPort(port_name);
    if (!port)
        rb_raise(rb_eArgError, "task %s has no port named %s", task.getName().c_str(), port_name.c_str());

    // Workaround a bug in RTT. The port's data flow interface is not reset
    port->setInterface(0);
    di.removePort(port_name);
    return Qnil;
}
exception() click to toggle source
static VALUE local_task_context_exception(VALUE _task)
{
    local_task_context(_task).exception();
    return Qnil;
}
ior() click to toggle source
static VALUE local_task_context_ior(VALUE _task)
{
    LocalTaskContext& task = local_task_context(_task);
    std::string ior = RTT::corba::TaskContextServer::getIOR(&task);
    return rb_str_new(ior.c_str(), ior.length());
}
model_name=(name) click to toggle source
static VALUE local_task_context_set_model_name(VALUE _task, VALUE name)
{
    local_task_context(_task).setModelName(StringValuePtr(name));
    return Qnil;
}