class Roby::TaskEventGenerator

Specialization of EventGenerator to represent task events

It gives access to the task-specific information (associated task, event name, …)

Attributes

plan[R]

The event plan. It is the same as task.plan and is actually updated by task.plan=. It is redefined here for performance reasons.

symbol[R]

The event symbol (its name as a Symbol object)

task[R]

The task we are part of

Public Class Methods

new(task, model) click to toggle source
Calls superclass method Roby::EventGenerator::new
# File lib/roby/task_event_generator.rb, line 16
def initialize(task, model)
    super(model.respond_to?(:call), plan: task.plan)
    @task, @event_model = task, model
    @symbol = model.symbol
end

Public Instance Methods

called(context) click to toggle source
Calls superclass method Roby::EventGenerator#called
# File lib/roby/task_event_generator.rb, line 74
def called(context)
    super
    if terminal? && pending?
        task.finishing = true
    end
end
check_call_validity_after_calling() click to toggle source
# File lib/roby/task_event_generator.rb, line 252
def check_call_validity_after_calling
    if error = super
        refine_call_exception(error)
    end
end
clear_pending() click to toggle source
Calls superclass method Roby::EventGenerator#clear_pending
# File lib/roby/task_event_generator.rb, line 63
def clear_pending
    if @pending && symbol == :start
        if !emitted? && !task.failed_to_start?
            plan.task_index.set_state(task, :pending?) if plan && !plan.template?
            task.pending = true
            task.starting = false
        end
    end
    super
end
command=(block) click to toggle source
# File lib/roby/task_event_generator.rb, line 28
def command=(block)
    event_model.singleton_class.class_eval do
        define_method(:call, &block)
    end
end
create_transaction_proxy(transaction) click to toggle source
# File lib/roby/task_event_generator.rb, line 328
def create_transaction_proxy(transaction)
    # Ensure that the task is proxied already
    transaction.wrap_task(task).event(symbol)
end
default_command(context) click to toggle source

The default command if the event is created with controlable: true. It emits the event on the task.

# File lib/roby/task_event_generator.rb, line 24
def default_command(context)
    event_model.call(task, context)
end
default_on_replace() click to toggle source
# File lib/roby/task_event_generator.rb, line 318
def default_on_replace
    if task.abstract? then :copy
    else :drop
    end
end
emit_failed(error = nil, message = nil) click to toggle source
Calls superclass method Roby::EventGenerator#emit_failed
# File lib/roby/task_event_generator.rb, line 215
def emit_failed(error = nil, message = nil)
    exception = super
    if symbol == :start
        if !task.failed_to_start?
            task.failed_to_start!(exception)
        end
    end
end
failure?() click to toggle source

True if this event is either forwarded to or signals the task's :failed event

# File lib/roby/task_event_generator.rb, line 143
def failure?; terminal_flag == :failure end
fire(event) click to toggle source
Calls superclass method Roby::EventGenerator#fire
# File lib/roby/task_event_generator.rb, line 81
def fire(event)
    super
    if symbol == :start
        task.do_poll(plan)
    elsif symbol == :stop
        task.each_event do |ev|
            ev.unreachable!(task.terminal_event)
        end
    end
end
handle_with(repairing_task, remove_when_done: true) click to toggle source

Mark this event as being handled by the task task

# File lib/roby/task_structure/error_handling.rb, line 4
def handle_with(repairing_task, remove_when_done: true)
    if repairing_task.respond_to?(:as_plan)
        repairing_task = repairing_task.as_plan
    end

    if !task.child_object?(repairing_task, ErrorHandling)
        task.add_error_handler repairing_task, Set.new
    end

    if remove_when_done
        repairing_task.stop_event.on do |event|
            repairing_task = event.task
            if task.plan && task.child_object?(repairing_task, ErrorHandling)
                task.remove_error_handler(repairing_task)
            end
        end
    end

    task[repairing_task, ErrorHandling] << Roby::Queries::ExecutionExceptionMatcher.new.with_origin(task.model.find_event(symbol))
    repairing_task
end
invalidate_task_terminal_flag_if_needed(child) click to toggle source

@api private

Helper for the signal and forward relation hooks that invalidates the events terminal flags when the event structure is changed

# File lib/roby/task_event_generator.rb, line 149
def invalidate_task_terminal_flag_if_needed(child)
    if child.respond_to?(:task) && child.task == task
        task.invalidate_terminal_flag
    end
end
match() click to toggle source
# File lib/roby/task_event_generator.rb, line 333
def match
    Queries::TaskEventGeneratorMatcher.new(task, symbol)
end
on(on_replace: default_on_replace, once: false, &block) click to toggle source
Calls superclass method Roby::EventGenerator#on
# File lib/roby/task_event_generator.rb, line 324
def on(on_replace: default_on_replace, once: false, &block)
    super(on_replace: on_replace, once: once, &block)
end
override_model(model) click to toggle source

Changes the underlying model

# File lib/roby/task_event_generator.rb, line 12
def override_model(model)
    @event_model = model
end
pending(sources) click to toggle source
Calls superclass method Roby::EventGenerator#pending
# File lib/roby/task_event_generator.rb, line 53
def pending(sources)
    super
    if symbol == :start
        task.freeze_delayed_arguments
        plan.task_index.set_state(task, :starting?) if plan && !plan.template?
        task.pending  = false
        task.starting = true
    end
end
plan=(plan) click to toggle source

The event plan. It is the same as task.plan and is actually updated by task.plan=. It is redefined here for performance reasons.

# File lib/roby/task_event_generator.rb, line 43
def plan=(plan)
    @plan = plan
    @relation_graphs =
        if plan then plan.event_relation_graphs
        end
    @execution_engine =
        if plan && plan.executable? then plan.execution_engine
        end
end
removed_forwarding(child) click to toggle source
Calls superclass method
# File lib/roby/task_event_generator.rb, line 176
def removed_forwarding(child)
    super
    invalidate_task_terminal_flag_if_needed(child)
end
removed_signal(child) click to toggle source

Invalidates the task's terminal flag when the Forwarding and/or the Signal relation gets modified.

Calls superclass method
# File lib/roby/task_event_generator.rb, line 171
def removed_signal(child)
    super
    invalidate_task_terminal_flag_if_needed(child)
end
success?() click to toggle source

True if this event is either forwarded to or signals the task's :success event

# File lib/roby/task_event_generator.rb, line 141
def success?; terminal_flag == :success end
terminal?() click to toggle source

True if this event is either forwarded to or signals the task's :stop event

# File lib/roby/task_event_generator.rb, line 139
def terminal?; !!terminal_flag end