Class: Orocos::RubyTasks::LocalInputPort

Inherits:
InputPort
  • Object
show all
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

OutputReader

Constant Summary collapse

OLD_DATA =
0
NEW_DATA =
1

Instance Method Summary collapse

Instance Method Details

#clearObject

Clears the channel, i.e. “forget” that this port ever got written to


91
92
93
# File 'lib/orocos/ruby_tasks/ports.rb', line 91

def clear
    do_clear
end

#do_clearObject

Never reached


373
374
375
376
377
378
# File 'ext/rorocos/ruby_task_context.cc', line 373

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) ⇒ Object


326
327
328
329
330
331
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
# File 'ext/rorocos/ruby_task_context.cc', line 326

static VALUE local_input_port_read(VALUE _local_port, VALUE type_name, VALUE rb_typelib_value, VALUE copy_old_data)
{
    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());
        switch(blocking_fct_call_with_result(boost::bind(&RTT::base::InputPortInterface::read,&local_port,ds,RTEST(copy_old_data))))
        {
            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 = blocking_fct_call_with_result(boost::bind(&RTT::base::InputPortInterface::read,&local_port,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.


32
33
34
35
36
# File 'lib/orocos/ruby_tasks/ports.rb', line 32

def raw_read(sample = nil)
    if value = read_helper(sample,true)
        value[0]
    end
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.


84
85
86
87
88
# File 'lib/orocos/ruby_tasks/ports.rb', line 84

def raw_read_new(sample = nil)
    if value = read_helper(sample, false)
        value[0] if value[1] == NEW_DATA
    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

21
22
23
24
25
# File 'lib/orocos/ruby_tasks/ports.rb', line 21

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.


70
71
72
73
74
# File 'lib/orocos/ruby_tasks/ports.rb', line 70

def read_new(sample = nil)
    if value = raw_read_new(sample)
        return Typelib.to_ruby(value)
    end
end

#read_new_raw(sample) ⇒ Object

Deprecated.

use #raw_read_new instead


44
45
46
# File 'lib/orocos/ruby_tasks/ports.rb', line 44

def read_new_raw(sample)
    raw_read_new(sample)
end

#read_raw(sample) ⇒ Object

Deprecated.

use #raw_read instead


39
40
41
# File 'lib/orocos/ruby_tasks/ports.rb', line 39

def read_raw(sample)
    raw_read(sample)
end