Class: Roby::TaskEvent
- Extended by:
- Models::TaskEvent
- Defined in:
- lib/roby/task_event.rb
Overview
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
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
The event model, usually its class.
-
#task ⇒ Object
readonly
The task which fired this event.
Attributes included from Models::TaskEvent
Attributes inherited from Event
#context, #generator, #propagation_id, #time
Instance Method Summary collapse
-
#all_task_sources ⇒ Object
Recursively browses in the event sources, returning only those that come from this event’s task.
-
#controlable? ⇒ Boolean
If the event is controlable.
-
#failure? ⇒ Boolean
If this event is terminal.
-
#initialize(task, generator, propagation_id, context, time = Time.now) ⇒ TaskEvent
constructor
A new instance of TaskEvent.
- #pretty_print(pp, with_context = true) ⇒ Object
-
#root_task_sources ⇒ Object
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.
-
#success? ⇒ Boolean
If this event is terminal.
-
#symbol ⇒ Object
The event symbol.
-
#task_sources ⇒ Object
Returns the events that are the cause of this event, limiting itself to the task’s events.
-
#terminal? ⇒ Boolean
If this event is terminal.
- #to_s ⇒ Object
Methods included from Models::TaskEvent
generalized_match, match, setup_submodel
Methods inherited from Event
#add_sources, #after, #all_sources, #inspect, #name, #plan, #protect_all_sources, #protect_sources, #reemit, #root_sources, #sources, #sources=, #to_execution_exception, #to_execution_exception_matcher
Methods included from DRoby::V5::EventDumper
Constructor Details
#initialize(task, generator, propagation_id, context, time = Time.now) ⇒ TaskEvent
Returns a new instance of TaskEvent.
29 30 31 32 33 34 |
# 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 |
Instance Attribute Details
#model ⇒ Object (readonly)
The event model, usually its class
27 28 29 |
# File 'lib/roby/task_event.rb', line 27 def model @model end |
#task ⇒ Object (readonly)
The task which fired this event
25 26 27 |
# File 'lib/roby/task_event.rb', line 25 def task @task end |
Instance Method Details
#all_task_sources ⇒ Object
Recursively browses in the event sources, returning only those that come from this event’s task
71 72 73 74 75 76 77 78 |
# 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? ⇒ Boolean
If the event is controlable
117 |
# File 'lib/roby/task_event.rb', line 117 def controlable?; model.controlable? end |
#failure? ⇒ Boolean
If this event is terminal
121 |
# File 'lib/roby/task_event.rb', line 121 def failure?; @terminal_flag == :failure end |
#pretty_print(pp, with_context = true) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# 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 ⇒ Object
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.
83 84 85 86 87 88 |
# 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? ⇒ Boolean
If this event is terminal
119 |
# File 'lib/roby/task_event.rb', line 119 def success?; @terminal_flag == :success end |
#symbol ⇒ Object
The event symbol
125 |
# File 'lib/roby/task_event.rb', line 125 def symbol; model.symbol end |
#task_sources ⇒ Object
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.
58 59 60 61 62 63 64 65 66 67 |
# 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? ⇒ Boolean
If this event is terminal
123 |
# File 'lib/roby/task_event.rb', line 123 def terminal?; @terminal_flag end |
#to_s ⇒ Object
90 91 92 93 94 95 96 |
# 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 |