class Roby::TaskEventGenerator
Specialization of EventGenerator
to represent task events
It gives access to the task-specific information (associated task, event name, …)
Attributes
The event plan. It is the same as task.plan and is actually updated by task.plan=. It is redefined here for performance reasons.
The event symbol (its name as a Symbol object)
The task we are part of
Public Class Methods
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
Roby::EventGenerator#called
# File lib/roby/task_event_generator.rb, line 74 def called(context) super if terminal? && pending? task.finishing = true end end
Roby::EventGenerator#check_call_validity_after_calling
# File lib/roby/task_event_generator.rb, line 252 def check_call_validity_after_calling if error = super refine_call_exception(error) end end
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
# 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
# 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
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
# File lib/roby/task_event_generator.rb, line 318 def default_on_replace if task.abstract? then :copy else :drop end end
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
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
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
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
@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
# File lib/roby/task_event_generator.rb, line 333 def match Queries::TaskEventGeneratorMatcher.new(task, symbol) end
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
Changes the underlying model
# File lib/roby/task_event_generator.rb, line 12 def override_model(model) @event_model = model end
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
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
# File lib/roby/task_event_generator.rb, line 176 def removed_forwarding(child) super invalidate_task_terminal_flag_if_needed(child) end
Invalidates the task's terminal flag when the Forwarding and/or the Signal relation gets modified.
# File lib/roby/task_event_generator.rb, line 171 def removed_signal(child) super invalidate_task_terminal_flag_if_needed(child) end
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
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