Class: Roby::PlanObject::InstanceHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/roby/plan_object.rb

Overview

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’.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block, copy_on_replace) ⇒ InstanceHandler

Returns a new instance of InstanceHandler.



97
98
99
100
# File 'lib/roby/plan_object.rb', line 97

def initialize(block, copy_on_replace)
    @block, @copy_on_replace =
        block, copy_on_replace
end

Instance Attribute Details

#blockObject (readonly)

The poll Proc object



58
59
60
# File 'lib/roby/plan_object.rb', line 58

def block
  @block
end

Class Method Details

.filter_options(options, defaults) ⇒ Object



93
94
95
# 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) ⇒ Object

Helper method for validate_options and filter_options

Parameters:

  • method (:validate, :filter)

    which of the filter_options or validate_options should be called.



75
76
77
78
79
80
81
82
83
84
85
86
87
# 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

.validate_options(options, defaults = Hash.new) ⇒ Object



89
90
91
# File 'lib/roby/plan_object.rb', line 89

def self.validate_options(options, defaults = Hash.new)
    handle_options(:validate, options, defaults)
end

Instance Method Details

#==(other) ⇒ Object



112
113
114
115
# File 'lib/roby/plan_object.rb', line 112

def ==(other)
    @copy_on_replace == other.copy_on_replace? &&
        @block == other.block
end

#as_optionsObject

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



104
105
106
107
108
109
110
# 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

#copy_on_replace?Object

:method:copy_on_replace?

If true, this poll handler gets copied to the new task when the task holding the handler gets replaced



63
# File 'lib/roby/plan_object.rb', line 63

attr_predicate :copy_on_replace?, true