class Orocos::RobyPlugin::RequirementModificationTask

Type of task that allows to modify the Orocos/Roby engine’s requirements. The modifications will be applied when the task is started, and the task will fail if the modification failed.

The task calls the block given to #initialize to modify the requirements. Example:

task = RequirementModificationTask.new do |engine|
    engine.remove Driving
end

Alternatively, if a common modification needs to be done repeatedly, one can define a task model for it

class StopDriving < Orocos::RobyPlugin::RequirementModificationTask
    implementation do |engine|
        engine.remove Driving
    end
end

See also ModalitySelectionTask

Public Class Methods

implementation(&block) click to toggle source

Defines a requirement modification block for all instances of this task model

# File lib/orocos/roby/selection_tasks.rb, line 87
def self.implementation(&block)
    if !block
        raise ArgumentError, "no block given"
    end
    check_arity(block, 1)
    define_method(:implementation, &block)
end
new(arguments = Hash.new, &block) click to toggle source
Calls superclass method
# File lib/orocos/roby/selection_tasks.rb, line 57
def initialize(arguments = Hash.new, &block)
    super(arguments) do
    end

    @implementation_method =
        if block
            check_arity(block, 1)
            block
        elsif respond_to?(:implementation)
            method(:implementation)
        else
            raise "no requirement modification block given"
        end
end

Public Instance Methods

result_task() click to toggle source

If the modification result can be identified by a single task, returns it. Otherwise, returns nil.

# File lib/orocos/roby/selection_tasks.rb, line 97
def result_task
    if @result
        if @result.respond_to?(:task)
            @result.task
        elsif @result.respond_to?(:to_task)
            @result.to_task
        end
    end
end
start!() click to toggle source

Requests the modifications to be applied

# File lib/orocos/roby/selection_tasks.rb, line 76
event :start do |context|
    if !@implementation_method
        raise ArgumentError, "no implementation set for this RequirementModificationTask"
    end

    @result = @implementation_method.call(Roby.app.orocos_engine)
    emit :start
end