class Roby::PlanObject::InstanceHandler

Generic handling object for blocks that are stored on tasks (event handlers,poll, …)

The only configurable behaviour so far is the ability to specify what to do with the block when a task is replaced by another one. This is given as a :on_replace option, which can take only two values:

drop

the handler is not copied

copy

the handler is copied

The default is dependent on the receiving's object state. For instance, abstract tasks will use a default of 'copy' while non-abstract one will use a default of 'drop'.

Attributes

block[R]

The poll Proc object

Public Class Methods

filter_options(options, defaults) click to toggle source
# File lib/roby/plan_object.rb, line 93
def self.filter_options(options, defaults)
    handle_options(:filter, options, defaults)
end
handle_options(method, options, defaults) click to toggle source

Helper method for validate_options and filter_options

@param [:validate,:filter] method which of the filter_options or

validate_options should be called.

@!macro InstanceHandlerOptions

@option options [:copy,:drop] :on_replace defines the behaviour
   when this object gets replaced in the plan. If :copy is used,
   the handler is added to the replacing task and is also kept
   in the original task. If :drop, it is not copied (but is
   kept).
# File lib/roby/plan_object.rb, line 75
def self.handle_options(method, options, defaults)
    options, other = Kernel.send("#{method}_options", options,
        on_replace: (defaults[:on_replace] || :drop))

    if ![:drop, :copy].include?(options[:on_replace])
        raise ArgumentError, "wrong value for the :on_replace option. Expecting either :drop or :copy, got #{options[:on_replace]}"
    end

    if other
        return options, other
    else return options
    end
end
new(block, copy_on_replace) click to toggle source
# File lib/roby/plan_object.rb, line 97
def initialize(block, copy_on_replace)
    @block, @copy_on_replace =
        block, copy_on_replace
end
validate_options(options, defaults = Hash.new) click to toggle source
# File lib/roby/plan_object.rb, line 89
def self.validate_options(options, defaults = Hash.new)
    handle_options(:validate, options, defaults)
end

Public Instance Methods

==(other) click to toggle source
# File lib/roby/plan_object.rb, line 112
def ==(other)
    @copy_on_replace == other.copy_on_replace? &&
        @block == other.block
end
as_options() click to toggle source

Creates an option hash from this poll handler parameters that is valid for Task#poll

# File lib/roby/plan_object.rb, line 104
def as_options
    on_replace = if copy_on_replace? then :copy
                 else :drop
                 end

    { on_replace: on_replace }
end