Class: Orocos::RubyTasks::LocalInputPort
- Defined in:
- lib/orocos/ruby_tasks/ports.rb,
ext/rorocos/ruby_task_context.cc
Overview
Input port created on a TaskContext task instantiated in this Ruby process
It is created by TaskContext#create_input_port
Direct Known Subclasses
Constant Summary
Constants inherited from Port
Port::CONNECTION_POLICY_OPTIONS, Port::DEFAULT_CONNECTION_POLICY, Port::MQ_RTT_DEFAULT_QUEUE_LENGTH
Constants included from PortBase
PortBase::D_DIFFERENT_HOSTS, PortBase::D_SAME_HOST, PortBase::D_SAME_PROCESS, PortBase::D_UNKNOWN
Instance Attribute Summary
Attributes included from PortBase
#model, #name, #orocos_type_name, #task, #type
Instance Method Summary collapse
-
#clear ⇒ Object
Clears the channel, i.e.
-
#connected? ⇒ Boolean
Whether the port seem to be connected to something.
-
#do_clear ⇒ Object
Never reached.
- #do_read(type_name, rb_typelib_value, copy_old_data, blocking_read) ⇒ Object
-
#raw_read(sample = nil) ⇒ Object
Reads a sample on this input port.
-
#raw_read_new(sample = nil) ⇒ Object
Reads a new sample on the associated output port.
-
#raw_read_with_result(sample = nil, copy_old_data = true) ⇒ Object
Attempt to read a sample and return it, along with the read state.
-
#read(sample = nil) ⇒ Object
Reads a sample on this input port.
-
#read_new(sample = nil) ⇒ Object
Reads a new sample on the associated output port.
-
#read_new_raw(sample) ⇒ Object
deprecated
Deprecated.
use #raw_read_new instead
-
#read_raw(sample) ⇒ Object
deprecated
Deprecated.
use #raw_read instead
-
#read_with_result(sample = nil, copy_old_data = true) ⇒ Object
Attempt to read a sample and return it, along with the read state.
-
#remove ⇒ Object
Remove this port from the underlying task context.
Methods inherited from InputPort
#initialize, #pretty_print, #subscribe_to_ros, #to_async, #to_proxy, #unsubscribe_from_ros, writer_class
Methods included from InputPortBase
#connect_to, #resolve_connection_from, #resolve_disconnection_from, #write, #writer
Methods inherited from Port
#create_stream, #default_ros_topic_name, #disconnect_all, #do_create_stream, #do_disconnect_all, #do_disconnect_from, #do_remove_stream, #doc, #doc?, #handle_mq_transport, prepare_policy, #pretty_print, #refine_exceptions, #remove_stream, #to_orocos_port, transient_local_port_name, transport_name, #type_name, validate_policy
Methods included from PortBase
#==, #distance_to, #ensure_type_available, #full_name, #initialize, #log_metadata, #max_marshalling_size, #max_sizes, #new_sample, #to_s
Constructor Details
This class inherits a constructor from Orocos::InputPort
Instance Method Details
#clear ⇒ Object
Clears the channel, i.e. “forget” that this port ever got written to
166 167 168 |
# File 'lib/orocos/ruby_tasks/ports.rb', line 166 def clear do_clear end |
#connected? ⇒ Boolean
Whether the port seem to be connected to something
53 54 55 56 57 |
# File 'lib/orocos/ruby_tasks/ports.rb', line 53 def connected? Orocos.allow_blocking_calls do super end end |
#do_clear ⇒ Object
Never reached
389 390 391 392 393 394 |
# File 'ext/rorocos/ruby_task_context.cc', line 389
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;
}
|
#do_read(type_name, rb_typelib_value, copy_old_data, blocking_read) ⇒ Object
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
# File 'ext/rorocos/ruby_task_context.cc', line 332
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
}
|
#raw_read(sample = nil) ⇒ Object
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.
37 38 39 40 |
# File 'lib/orocos/ruby_tasks/ports.rb', line 37 def raw_read(sample = nil) _result, value = raw_read_with_result(sample, true) value end |
#raw_read_new(sample = nil) ⇒ Object
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.
91 92 93 94 |
# 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 |
#read_with_result(sample = nil, false) ⇒ (Orocos::NEW_DATA, Typelib::Type), ... #read_with_result(sample = nil, true) ⇒ (Orocos::NEW_DATA, Typelib::Type), ...
Attempt to read a sample and return it, along with the read state
The sample is returned as a Typelib::Type object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# 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 |
#read(sample = nil) ⇒ Object
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
26 27 28 29 30 |
# 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 |
#read_new(sample = nil) ⇒ Object
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.
77 78 79 80 81 |
# 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 |
#read_new_raw(sample) ⇒ Object
use #raw_read_new instead
48 49 50 |
# File 'lib/orocos/ruby_tasks/ports.rb', line 48 def read_new_raw(sample) raw_read_new(sample) end |
#read_raw(sample) ⇒ Object
use #raw_read instead
43 44 45 |
# File 'lib/orocos/ruby_tasks/ports.rb', line 43 def read_raw(sample) raw_read(sample) end |
#read_with_result(sample = nil, false) ⇒ (Orocos::NEW_DATA, Object), ... #read_with_result(sample = nil, true) ⇒ (Orocos::NEW_DATA, Object), ...
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
114 115 116 117 118 119 120 121 |
# 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 ⇒ Object
Remove this port from the underlying task context
9 10 11 |
# File 'lib/orocos/ruby_tasks/ports.rb', line 9 def remove task.remove_port(self) end |