Class: Orocos::RubyTasks::LocalOutputPort

Inherits:
OutputPort
  • Object
show all
Defined in:
lib/orocos/ruby_tasks/ports.rb,
ext/rorocos/ruby_task_context.cc

Direct Known Subclasses

InputWriter

Instance Method Summary collapse

Instance Method Details

#do_write(type_name, rb_typelib_value) ⇒ Object


380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
# File 'ext/rorocos/ruby_task_context.cc', line 380

static VALUE local_output_port_write(VALUE _local_port, VALUE type_name, VALUE rb_typelib_value)
{
    RTT::base::OutputPortInterface& local_port = get_wrapped<RTT::base::OutputPortInterface>(_local_port);
    Typelib::Value value = typelib_get(rb_typelib_value);

    orogen_transports::TypelibMarshallerBase* transport = 0;
    RTT::types::TypeInfo* ti = get_type_info(StringValuePtr(type_name));
    if (ti && ti->hasProtocol(orogen_transports::TYPELIB_MARSHALLER_ID))
    {
        transport =
            dynamic_cast<orogen_transports::TypelibMarshallerBase*>(ti->getProtocol(orogen_transports::TYPELIB_MARSHALLER_ID));
    }

    if (!transport)
    {
        RTT::base::DataSourceBase::shared_ptr ds =
            ti->buildReference(value.getData());

        blocking_fct_call(boost::bind(&RTT::base::OutputPortInterface::write,&local_port,ds));
    }
    else
    {
        orogen_transports::TypelibMarshallerBase::Handle* handle =
            transport->createHandle();

        transport->setTypelibSample(handle, static_cast<uint8_t*>(value.getData()));
        RTT::base::DataSourceBase::shared_ptr ds =
            transport->getDataSource(handle);
        blocking_fct_call(boost::bind(&RTT::base::OutputPortInterface::write,&local_port,ds));
        transport->deleteHandle(handle);
    }
    bool result = blocking_fct_call_with_result(boost::bind(&RTT::base::OutputPortInterface::connected,&local_port));
    return result ? Qtrue : Qfalse;
}

#write(data) ⇒ Object

Write a sample on this output port

If the data type is a struct, the sample can be provided either as a Typelib instance object or as a hash.

In the first case, one can do:

value = port.new_sample # Get a new sample from the port
value.field = 10
value.other_field = "a_string"
input_writer.write(value)

In the second case,

input_writer.write(:field => 10, :other_field => "a_string")

137
138
139
140
# File 'lib/orocos/ruby_tasks/ports.rb', line 137

def write(data)
    data = Typelib.from_ruby(data, type)
    do_write(orocos_type_name, data)
end