class Roby::TaskEvent

Base class for events emitted by tasks.

When one creates a new event on a task, Roby creates a corresponding subclass of TaskEvent. The emitted event objects are then instances of that class.

For instance, there is a Roby::Task::StopEvent class which is used to represent the emitted :stop events of Roby::Task. However, if one overloads the stop command with

class TModel < Roby::Task
  event :stop, controlable: true
end

Then TModel::StopEvent will be a subclass of StopEvent.

These models are meant to be extended when the emission carry information, i.e. to provide a robust access to the information contained in Event#context

Attributes

model[R]

The event model, usually its class

task[R]

The task which fired this event

Public Class Methods

new(task, generator, propagation_id, context, time = Time.now) click to toggle source
Calls superclass method Roby::Event::new
# File lib/roby/task_event.rb, line 29
def initialize(task, generator, propagation_id, context, time = Time.now)
    @task = task
    @terminal_flag = generator.terminal_flag
    @model = self.class
    super(generator, propagation_id, context, time)
end

Public Instance Methods

all_task_sources() click to toggle source

Recursively browses in the event sources, returning only those that come from this event's task

# File lib/roby/task_event.rb, line 71
def all_task_sources
    result = Set.new
    for ev in task_sources
        result << ev
        result.merge(ev.all_task_sources)
    end
    result
end
controlable?() click to toggle source

If the event is controlable

# File lib/roby/task_event.rb, line 117
def controlable?; model.controlable? end
failure?() click to toggle source

If this event is terminal

# File lib/roby/task_event.rb, line 121
def failure?; @terminal_flag == :failure end
pretty_print(pp, with_context = true) click to toggle source
# File lib/roby/task_event.rb, line 98
def pretty_print(pp, with_context = true)
    pp.text "event '#{symbol}' emitted at [#{Roby.format_time(time)} @#{propagation_id}] from "
    pp.nest(2) do
        pp.breakable
        task.pretty_print(pp)
    end

    if with_context && context
        pp.breakable
        pp.nest(2) do
            pp.text "  "
            pp.seplist(context) do |v|
                v.pretty_print(pp)
            end
        end
    end
end
root_task_sources() click to toggle source

Recursively browses in the event sources, returning those (1) that come from this event's task and (2) have no parent from within the Forwarding relation in the task sources.

# File lib/roby/task_event.rb, line 83
def root_task_sources
    all = all_task_sources
    all.find_all do |event|
        all.none? { |ev| ev.generator.child_object?(event.generator, Roby::EventStructure::Forwarding) }
    end
end
success?() click to toggle source

If this event is terminal

# File lib/roby/task_event.rb, line 119
def success?; @terminal_flag == :success end
symbol() click to toggle source

The event symbol

# File lib/roby/task_event.rb, line 125
def symbol; model.symbol end
task_sources() click to toggle source

Returns the events that are the cause of this event, limiting itself to the task's events. The return value is a Set of TaskEvent instances.

For instance, for an interruptible task:

task.start!
task.stop!

Then task.stop_event.last.task_sources will return a Set instance which contains the failed event. I.e. in this particular situation, it behaves in the same way than Event#event_sources

However, with

event.add_signal task.failed_event
task.start!
event.call

Event#event_sources will return both event.last and task.failed_event.last while TaskEvent will only return task.failed_event.last.

# File lib/roby/task_event.rb, line 58
def task_sources
    result = Set.new
    for ev in sources
        gen = ev.generator
        if gen.respond_to?(:task) && gen.task == task
            result << ev
        end
    end
    result
end
terminal?() click to toggle source

If this event is terminal

# File lib/roby/task_event.rb, line 123
def terminal?; @terminal_flag end
to_s() click to toggle source
# File lib/roby/task_event.rb, line 90
def to_s
    result = "[#{Roby.format_time(time)} @#{propagation_id}] #{task}/#{symbol}"
    if context
        result += ": #{context}"
    end
    result
end