class Roby::Event
Event
objects are the objects representing a particular emission in the event propagation process. They represent the common propagation information (time, generator, sources, …) and provide some common functionalities related to propagation as well.
Attributes
The generator which emitted this event
Public Class Methods
# File lib/roby/event.rb, line 10 def initialize(generator, propagation_id, context, time = Time.now) @generator, @propagation_id, @context, @time = generator, propagation_id, context.freeze, time @sources = Set.new end
Public Instance Methods
# File lib/roby/event.rb, line 70 def add_sources(new_sources) for new_s in new_sources @sources << WeakRef.new(new_s) end end
Returns an event generator which will be emitted once time
seconds after this event has been emitted.
# File lib/roby/event.rb, line 105 def after(time) State.at t: (self.time + time) end
Recursively computes the source event that led to the emission of self
# File lib/roby/event.rb, line 42 def all_sources result = Set.new sources.each do |ev| result << ev result.merge(ev.all_sources) end result end
# File lib/roby/event.rb, line 98 def model; self.class end
# File lib/roby/event.rb, line 97 def name; model.name end
# File lib/roby/event.rb, line 15 def plan generator.plan end
Call to recursively protect this event's sources from Ruby's garbage collection. Call this if you want to store the propagation history for this event
# File lib/roby/event.rb, line 60 def protect_all_sources @protected_all_sources = all_sources end
Call to protect this event's source from Ruby's garbage collection. Call this if you want to store the propagation history for this event
# File lib/roby/event.rb, line 53 def protect_sources @protected_sources = sources end
To be used in the event generators ::new
methods, when we need to reemit an event while changing its
# File lib/roby/event.rb, line 85 def reemit(new_id, new_context = nil) if propagation_id != new_id || (new_context && new_context != context) new_event = self.dup new_event.propagation_id = new_id new_event.context = new_context new_event.time = Time.now new_event else self end end
# File lib/roby/event.rb, line 76 def root_sources all = all_sources all.find_all do |event| all.none? { |ev| ev.generator.child_object?(event.generator, Roby::EventStructure::Forwarding) } end end
The events whose emission directly triggered this event during the propagation. The events in this set are subject to Ruby's own garbage collection, which means that if a source event is garbage collected (i.e. if all references to the associated task/event generator are removed), it will be removed from this set as well.
# File lib/roby/event.rb, line 27 def sources result = Set.new @sources.delete_if do |ref| begin result << ref.__getobj__ false rescue WeakRef::RefError true end end result end
# File lib/roby/event.rb, line 127 def to_execution_exception generator.to_execution_exception end
# File lib/roby/event.rb, line 131 def to_execution_exception_matcher generator.to_execution_exception_matcher end