class Orocos::Operation

Base class for RTTMethod and Command

Attributes

arguments_spec[R]

An array describing the arguments. Each element is a [name, doc, type_name] tuple

arguments_types[R]

The typelib types for the arguments. This is an array of subclasses of Typelib::Type, with each element being the type of the corresponding element in arguments_spec. It describes the types that the Ruby side will manipulate

description[R]

The method description

inout_arguments[R]
name[R]

The method name

orocos_arguments_typenames[R]

The typelib types for the arguments. This is an array of subclasses of Typelib::Type, with each element being the type of the corresponding element in arguments_spec. It describes the types that the C++ side manipulates (i.e. declared in the Orocos component)

orocos_return_typenames[R]

The subclass of Typelib::Type that represents the type of the return value, as declared by the Orocos

return_spec[R]

The type name of the return value

return_types[R]

The subclass of Typelib::Type that will be manipulated by the Ruby code

task[R]

The task this method is part of

Public Class Methods

new(task, name, return_spec, arguments_spec) click to toggle source
# File lib/orocos/operations.rb, line 81
def initialize(task, name, return_spec, arguments_spec)
    @task, @name, @return_spec, @arguments_spec =
        task, name, return_spec, arguments_spec

    @orocos_return_typenames = return_spec.map do |type_name|
        type_name = OroGen.unqualified_cxx_type(type_name)
        Orocos.normalize_typename(type_name)
    end
    @orocos_arguments_typenames = arguments_spec.map do |_, _, type_name|
        type_name = OroGen.unqualified_cxx_type(type_name)
        Orocos.normalize_typename(type_name)
    end
    @inout_arguments = arguments_spec.each_with_index.map do |(_, _, type_name), i|
        if type_name =~ /&/ && type_name !~ /(^|[^\w])const($|[^\w])/
            i
        end
    end.compact

    # Remove a void return type
    if Orocos.registry.get(orocos_return_typenames.first).null?
        @void_return = true
        orocos_return_typenames.shift 
    else
        @void_return = false
    end

    @return_types    = typelib_types_for(orocos_return_typenames)
    @arguments_types = typelib_types_for(orocos_arguments_typenames)
end

Public Instance Methods

callop(*args) click to toggle source

Calls the method with the provided arguments, waiting for the method to finish. It returns the value returned by the remote method.

# File lib/orocos/operations.rb, line 174
def callop(*args)
    raw_result = common_call(args) do |filtered|
        return_typename, return_value = nil
        if !@void_return
            return_typename = orocos_return_typenames[0]
            return_value = result_value_for(return_types.first)
        end

        task.do_operation_call(name, return_typename, return_value,
                   orocos_arguments_typenames, filtered)

        result = []
        if return_value
            result << return_value
        end
        inout_arguments.each do |index|
            result << filtered[index]
        end
        result
    end

    result = []
    raw_result.each_with_index do |v, i|
        result << Typelib.to_ruby(v, return_types[i])
    end
    if result.empty? then nil
    elsif result.size == 1 then result.first
    else result
    end
end
new_argument(index) click to toggle source

Returns a new Typelib value for the Nth argument

# File lib/orocos/operations.rb, line 125
def new_argument(index)
    arguments_types[index].new
end
new_result() click to toggle source

Returns a Typelib value that can store the result of this operation

# File lib/orocos/operations.rb, line 153
def new_result
    return_types.map do |type|
        result_value_for(type)
    end
end
result_value_for(type) click to toggle source
# File lib/orocos/operations.rb, line 144
def result_value_for(type)
    if type.opaque?
        raise ArgumentError, "I don't know how to handle #{type.name}"
    else
        type.new
    end
end
sendop(*args) click to toggle source

Requests the operation to be started. It does not wait for it to finish, returning instead an OperationHandle object that can be used to query the operation status and return value

# File lib/orocos/operations.rb, line 162
def sendop(*args)
    common_call(args) do |filtered|
        handle = task.do_operation_send(name, orocos_arguments_typenames, filtered)
        handle.instance_variable_set :@operation, self
        handle.instance_variable_set :@orocos_return_types, @orocos_return_typenames.dup
        handle.instance_variable_set :@return_values, new_result
        handle
    end
end
typelib_types_for(types) click to toggle source

Replaces in types the opaque types by the types that should be used on the Ruby side

# File lib/orocos/operations.rb, line 113
def typelib_types_for(types)
    types.map do |t|
        begin
            Orocos.typelib_type_for(t)
        rescue Typelib::NotFound
            Orocos.load_typekit_for(t)
            Orocos.typelib_type_for(t)
        end
    end
end