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

context[RW]
generator[R]

The generator which emitted this event

propagation_id[RW]
time[RW]

Public Class Methods

new(generator, propagation_id, context, time = Time.now) click to toggle source
# 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

add_sources(new_sources) click to toggle source
# 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
after(time) click to toggle source

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
all_sources() click to toggle source

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
model() click to toggle source
# File lib/roby/event.rb, line 98
def model; self.class end
name() click to toggle source
# File lib/roby/event.rb, line 97
def name; model.name end
plan() click to toggle source
# File lib/roby/event.rb, line 15
def plan
    generator.plan
end
protect_all_sources() click to toggle source

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
protect_sources() click to toggle source

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
reemit(new_id, new_context = nil) click to toggle source

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
root_sources() click to toggle source
# 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
sources() click to toggle source

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
to_execution_exception() click to toggle source
# File lib/roby/event.rb, line 127
def to_execution_exception
    generator.to_execution_exception
end
to_execution_exception_matcher() click to toggle source
# File lib/roby/event.rb, line 131
def to_execution_exception_matcher
    generator.to_execution_exception_matcher
end