Class: Roby::Event
Overview
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.
Constant Summary collapse
- @@creation_places =
Hash.new
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#generator ⇒ Object
readonly
The generator which emitted this event.
-
#propagation_id ⇒ Object
readonly
Returns the value of attribute propagation_id.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
-
#after(time) ⇒ Object
Returns an event generator which will be emitted once
timeseconds after this event has been emitted. -
#initialize(generator, propagation_id, context, time = Time.now) ⇒ Event
constructor
A new instance of Event.
-
#inspect ⇒ Object
:nodoc:.
- #model ⇒ Object
- #name ⇒ Object
-
#pretty_print(pp) ⇒ Object
:nodoc:.
-
#reemit(new_id, new_context = nil) ⇒ Object
To be used in the event generators ::new methods, when we need to reemit an event while changing its.
-
#sources ⇒ Object
The events whose emission triggered this event during the propagation.
-
#sources=(sources) ⇒ Object
Sets the sources.
-
#to_s ⇒ Object
:nodoc:.
Constructor Details
#initialize(generator, propagation_id, context, time = Time.now) ⇒ Event
Returns a new instance of Event.
16 17 18 19 20 |
# File 'lib/roby/event.rb', line 16 def initialize(generator, propagation_id, context, time = Time.now) @generator, @propagation_id, @context, @time = generator, propagation_id, context.freeze, time @@creation_places[object_id] = "#{generator.class}" end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
22 23 24 |
# File 'lib/roby/event.rb', line 22 def context @context end |
#generator ⇒ Object (readonly)
The generator which emitted this event
13 14 15 |
# File 'lib/roby/event.rb', line 13 def generator @generator end |
#propagation_id ⇒ Object
Returns the value of attribute propagation_id.
22 23 24 |
# File 'lib/roby/event.rb', line 22 def propagation_id @propagation_id end |
#time ⇒ Object
Returns the value of attribute time.
22 23 24 |
# File 'lib/roby/event.rb', line 22 def time @time end |
Instance Method Details
#after(time) ⇒ Object
Returns an event generator which will be emitted once time seconds after this event has been emitted.
73 74 75 |
# File 'lib/roby/event.rb', line 73 def after(time) State.at :t => (self.time + time) end |
#inspect ⇒ Object
:nodoc:
67 68 69 |
# File 'lib/roby/event.rb', line 67 def inspect # :nodoc: "#<#{model.to_s}:0x#{address.to_s(16)} generator=#{generator} model=#{model}" end |
#model ⇒ Object
66 |
# File 'lib/roby/event.rb', line 66 def model; self.class end |
#name ⇒ Object
65 |
# File 'lib/roby/event.rb', line 65 def name; model.name end |
#pretty_print(pp) ⇒ Object
:nodoc:
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/roby/event.rb', line 81 def pretty_print(pp) # :nodoc: pp.text "[#{time.to_hms} @#{propagation_id}] #{self.class}" if context pp.breakable pp.nest(2) do pp.text " " pp.seplist(context) { |v| v.pretty_print(pp) } end end end |
#reemit(new_id, new_context = nil) ⇒ Object
To be used in the event generators ::new methods, when we need to reemit an event while changing its
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/roby/event.rb', line 53 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 |
#sources ⇒ Object
The events whose emission 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.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/roby/event.rb', line 30 def sources result = [] @sources.delete_if do |ref| begin result << ref.get false rescue Utilrb::WeakRef::RefError true end end result end |
#sources=(sources) ⇒ Object
Sets the sources. See #sources
44 45 46 47 48 49 |
# File 'lib/roby/event.rb', line 44 def sources=(sources) # :nodoc: @sources = ValueSet.new for s in sources @sources << Utilrb::WeakRef.new(s) end end |
#to_s ⇒ Object
:nodoc:
77 78 79 |
# File 'lib/roby/event.rb', line 77 def to_s # :nodoc: "[#{time.to_hms} @#{propagation_id}] #{self.class.to_s}: #{context}" end |