class Orocos::RubyTasks::LocalInputPort
Input port created on a {TaskContext} task instantiated in this Ruby process
It is created by {TaskContext#create_input_port}
Public Instance Methods
Clears the channel, i.e. “forget” that this port ever got written to
# File lib/orocos/ruby_tasks/ports.rb, line 166 def clear do_clear end
Whether the port seem to be connected to something
# File lib/orocos/ruby_tasks/ports.rb, line 53 def connected? Orocos.allow_blocking_calls do super end end
static VALUE local_input_port_clear(VALUE _local_port)
{
RTT::base::InputPortInterface& local_port = get_wrapped<RTT::base::InputPortInterface>(_local_port);
local_port.clear();
return Qnil;
}
static VALUE local_input_port_read(VALUE _local_port, VALUE type_name, VALUE rb_typelib_value, VALUE copy_old_data, VALUE blocking_read)
{
RTT::base::InputPortInterface& local_port = get_wrapped<RTT::base::InputPortInterface>(_local_port);
Typelib::Value value = typelib_get(rb_typelib_value);
RTT::types::TypeInfo* ti = get_type_info(StringValuePtr(type_name));
orogen_transports::TypelibMarshallerBase* typelib_transport =
get_typelib_transport(ti, false);
if (!typelib_transport || typelib_transport->isPlainTypelibType())
{
RTT::base::DataSourceBase::shared_ptr ds =
ti->buildReference(value.getData());
RTT::FlowStatus did_read;
if (RTEST(blocking_read))
did_read = blocking_fct_call_with_result(boost::bind(&RTT::base::InputPortInterface::read,&local_port,ds,RTEST(copy_old_data)));
else
did_read = local_port.read(ds, RTEST(copy_old_data));
switch(did_read)
{
case RTT::NoData: return Qfalse;
case RTT::OldData: return INT2FIX(0);
case RTT::NewData: return INT2FIX(1);
}
}
else
{
orogen_transports::TypelibMarshallerBase::Handle* handle =
typelib_transport->createHandle();
// Set the typelib sample using the value passed from ruby to avoid
// unnecessary convertions. Don't touch the orocos sample though.
typelib_transport->setTypelibSample(handle, value, false);
RTT::base::DataSourceBase::shared_ptr ds =
typelib_transport->getDataSource(handle);
RTT::FlowStatus did_read;
if (RTEST(blocking_read))
did_read = blocking_fct_call_with_result(boost::bind(&RTT::base::InputPortInterface::read,&local_port,ds,RTEST(copy_old_data)));
else
did_read = local_port.read(ds, RTEST(copy_old_data));
if (did_read == RTT::NewData || (did_read == RTT::OldData && RTEST(copy_old_data)))
{
typelib_transport->refreshTypelibSample(handle);
Typelib::copy(value, Typelib::Value(typelib_transport->getTypelibSample(handle), value.getType()));
}
typelib_transport->deleteHandle(handle);
switch(did_read)
{
case RTT::NoData: return Qfalse;
case RTT::OldData: return INT2FIX(0);
case RTT::NewData: return INT2FIX(1);
}
}
return Qnil; // Never reached
}
Reads a sample on this input port
Unlike read, it will always return a typelib type even for simple types.
Raises CORBA::ComError if the communication is broken.
# File lib/orocos/ruby_tasks/ports.rb, line 37 def raw_read(sample = nil) _result, value = raw_read_with_result(sample, true) value end
Reads a new sample on the associated output port.
Unlike raw_read, it will return a non-nil value only if it it different from the last time read or read_new has been called
Unlike read_new, it will always return a typelib type even for simple types.
Raises CORBA::ComError if the communication is broken.
# File lib/orocos/ruby_tasks/ports.rb, line 91 def raw_read_new(sample = nil) _result, value = raw_read_with_result(sample, false) value end
Attempt to read a sample and return it, along with the read state
The sample is returned as a Typelib::Type object
@overload #read_with_result(sample = nil, false)
@return [(Orocos::NEW_DATA, Typelib::Type)] the read sample if there was a never-read sample @return [Orocos::OLD_DATA] if there is a sample on the port, but it was already read @return [false] if there were no samples on the port
@overload #read_with_result(sample = nil, true)
@return [(Orocos::NEW_DATA, Typelib::Type)] the read sample if there was a never-read sample @return [(Orocos::OLD_DATA, Typelib::Type)] the read sample if there was a sample that was already read @return [false] if there were no samples on the port
# File lib/orocos/ruby_tasks/ports.rb, line 140 def raw_read_with_result(sample = nil, copy_old_data = true) if sample if !sample.kind_of?(type) if sample.class != type raise ArgumentError, "wrong sample type #{sample.class}, expected #{type}" end end value = sample else value = type.new end result = value.allocating_operation do do_read(orocos_type_name, value, copy_old_data, blocking_read?) end if result == NEW_DATA || (result == OLD_DATA && copy_old_data) if sample sample.invalidate_changes_from_converted_types end return result, value else return result end end
Reads a sample on this input port
For simple types, the returned value is the Ruby representation of the C value. For instance, C++ strings are represented as String objects, integers as Integer, …
For structures and vectors, the returned value is a representation of that type that Ruby can understand. Field access is transparent:
struct = reader.read struct.a_field # returns either a simple value or another structure struct.an_array.each do |element| end
# File lib/orocos/ruby_tasks/ports.rb, line 26 def read(sample = nil) if value = raw_read(sample) return Typelib.to_ruby(value) end end
Reads a new sample on the associated output port.
Unlike read, it will return a non-nil value only if it it different from the last time read or read_new has been called
For simple types, the returned value is the Ruby representation of the C value. For instance, C++ strings are represented as String objects, integers as Integer, …
For structures and vectors, the returned value is a representation of that type that Ruby can understand. Field access is transparent:
struct = reader.read struct.a_field # returns either a simple value or another structure struct.an_array.each do |element| end
Raises CORBA::ComError if the communication is broken.
# File lib/orocos/ruby_tasks/ports.rb, line 77 def read_new(sample = nil) if value = raw_read_new(sample) return Typelib.to_ruby(value) end end
@deprecated use {raw_read_new} instead
# File lib/orocos/ruby_tasks/ports.rb, line 48 def read_new_raw(sample) raw_read_new(sample) end
@deprecated use {raw_read} instead
# File lib/orocos/ruby_tasks/ports.rb, line 43 def read_raw(sample) raw_read(sample) end
Attempt to read a sample and return it, along with the read state
The returned sample is converted to its Ruby equivalent if a conversion has been registered
@overload #read_with_result(sample = nil, false)
@return [(Orocos::NEW_DATA, Object)] the read sample if there was a never-read sample @return [Orocos::OLD_DATA] if there is a sample on the port, but it was already read @return [false] if there were no samples on the port
@overload #read_with_result(sample = nil, true)
@return [(Orocos::NEW_DATA, Object)] the read sample if there was a never-read sample @return [(Orocos::OLD_DATA, Object)] the read sample if there was a sample that was already read @return [false] if there were no samples on the port
# File lib/orocos/ruby_tasks/ports.rb, line 114 def read_with_result(sample = nil, copy_old_data = true) result, value = raw_read_with_result(sample, copy_old_data) if value return result, Typelib.to_ruby(value) else return result end end
Remove this port from the underlying task context
# File lib/orocos/ruby_tasks/ports.rb, line 9 def remove task.remove_port(self) end