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, context: true, context_task: nil) ⇒ 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.
31 32 33 34 35 36 |
# File 'lib/roby/task_event.rb', line 31 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
29 30 31 |
# File 'lib/roby/task_event.rb', line 29 def model @model end |
#task ⇒ Object (readonly)
The task which fired this event
27 28 29 |
# File 'lib/roby/task_event.rb', line 27 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
73 74 75 76 77 78 79 80 |
# File 'lib/roby/task_event.rb', line 73 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
122 123 124 |
# File 'lib/roby/task_event.rb', line 122 def controlable? model.controlable? end |
#failure? ⇒ Boolean
If this event is terminal
132 133 134 |
# File 'lib/roby/task_event.rb', line 132 def failure? @terminal_flag == :failure end |
#pretty_print(pp, context: true, context_task: nil) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/roby/task_event.rb', line 100 def pretty_print(pp, context: true, context_task: nil) pp.text "event '#{symbol}' emitted at [#{Roby.format_time(time)} @#{propagation_id}]" if !context_task || context_task != task pp.text " from" pp.nest(2) do pp.breakable task.pretty_print(pp) end end if context && !self.context.empty? pp.breakable pp.nest(2) do pp.text " " pp.seplist(self.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.
85 86 87 88 89 90 |
# File 'lib/roby/task_event.rb', line 85 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
127 128 129 |
# File 'lib/roby/task_event.rb', line 127 def success? @terminal_flag == :success end |
#symbol ⇒ Object
The event symbol
142 143 144 |
# File 'lib/roby/task_event.rb', line 142 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.
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/roby/task_event.rb', line 60 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
137 138 139 |
# File 'lib/roby/task_event.rb', line 137 def terminal? @terminal_flag end |
#to_s ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/roby/task_event.rb', line 92 def to_s result = "[#{Roby.format_time(time)} @#{propagation_id}] #{task}/#{symbol}" if context result += ": #{context}" end result end |