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.



101
102
103
104
# File 'lib/roby/plan_object.rb', line 101

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

Instance Attribute Details

#blockObject (readonly)

The poll Proc object



60
61
62
# File 'lib/roby/plan_object.rb', line 60

def block
  @block
end

Class Method Details

.filter_options(options, defaults) ⇒ Object



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

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.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/roby/plan_object.rb', line 78

def self.handle_options(method, options, defaults)
    options, other = Kernel.send("#{method}_options", options,
                                 on_replace: defaults[:on_replace] || :drop)

    unless %i[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
        [options, other]
    else
        options
    end
end

.validate_options(options, defaults = {}) ⇒ Object



93
94
95
# File 'lib/roby/plan_object.rb', line 93

def self.validate_options(options, defaults = {})
    handle_options(:validate, options, defaults)
end

Instance Method Details

#==(other) ⇒ Object



117
118
119
120
# File 'lib/roby/plan_object.rb', line 117

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



108
109
110
111
112
113
114
115
# File 'lib/roby/plan_object.rb', line 108

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



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

attr_predicate :copy_on_replace?, true