Class: Roby::OrGenerator

Inherits:
EventGenerator show all
Defined in:
lib/roby/or_generator.rb

Overview

Fires when the first of its source events fires.

For instance,

a = task1.start_event
b = task2.start_event
(a | b) # will emit as soon as one of task1 and task2 are started

Or events will emit only once, unless #reset is called:

a = task1.intermediate_event
b = task2.intermediate_event
or_ev = (a | b)

a.intermediate_event! # or_ev emits here
b.intermediate_event! # or_ev does *not* emit
a.intermediate_event! # or_ev does *not* emit
b.intermediate_event! # or_ev does *not* emit

or_ev.reset
b.intermediate_event! # or_ev emits here
a.intermediate_event! # or_ev does *not* emit
b.intermediate_event! # or_ev does *not* emit

The OrGenerator tracks its sources via the signalling relations, so

or_ev << c.intermediate_event

is equivalent to

c.intermediate_event.add_signal or_ev

Instance Attribute Summary

Attributes inherited from EventGenerator

#command, #event_model, #history, #unreachability_reason, #unreachable_handlers

Attributes inherited from PlanObject

#addition_time, #executable, #execution_engine, #finalization_handlers, #finalization_time, #model, #plan, #promise_executor, #removed_at

Attributes included from Transaction::Proxying::Cache

#transaction_forwarder_module, #transaction_proxy_module

Attributes included from Relations::DirectedRelationSupport

#relation_graphs

Attributes inherited from DistributedObject

#local_owner_id, #owners

Instance Method Summary collapse

Methods inherited from EventGenerator

#&, #achieve_asynchronously, #achieve_with, #add_child_object, #call, #call_handlers, #call_unreachable_handlers, #call_without_propagation, #called, #calling, #cancel, #check_call_validity, #check_call_validity_after_calling, #check_emission_validity, #clear_pending, #controlable?, #create_transaction_proxy, #default_command, #delay, #each_precondition, #emit, #emit_failed, #emit_without_propagation, #emitting, #filter, #finalized!, #fire, #fired, #forward, #forward_once, #forward_to, #forward_to_once, #forwarded_to?, #garbage!, #happened?, #if_unreachable, #initialize_copy, #initialize_replacement, #last, #mark_unreachable!, match, #match, #model, #name, #new, #on, #once, #pending, #plan=, #precondition, #pretty_print, #realize_with, #related_events, #related_tasks, #replace_by, #signal, #signals, #signals_once, #to_event, #to_execution_exception, #to_execution_exception_matcher, #unreachable!, #unreachable_without_propagation, #until, #when_unreachable, #|

Methods included from DRoby::Identifiable

#droby_id, #initialize_copy

Methods included from DRoby::V5::DRobyConstant::Dump

#droby_dump, #droby_marshallable?

Methods included from DRoby::V5::EventGeneratorDumper

#droby_dump

Methods included from GUI::RelationsCanvasEventGenerator

#display, #display_create, #display_name, #display_time_end, #display_time_start, priorities, style, styles

Methods included from GUI::RelationsCanvasPlanObject

#display, #display_create, #display_events, #display_name, #display_parent

Methods inherited from PlanObject

#add_child_object, #apply_relation_changes, #as_plan, #can_finalize?, #commit_transaction, #concrete_model, #connection_space, #each_finalization_handler, #each_in_neighbour_merged, #each_out_neighbour_merged, #each_plan_child, #engine, #executable?, #finalized!, #finalized?, #forget_peer, #fullfills?, #garbage!, #garbage?, #initialize_copy, #initialize_replacement, #merged_relations, #promise, #read_write?, #real_object, #remotely_useful?, #replace_by, #replace_subplan_by, #root_object, #root_object?, #subscribed?, #transaction_proxy?, #transaction_stack, #update_on?, #updated_by?, #when_finalized

Methods included from Models::PlanObject

#child_plan_object, #finalization_handler, #match, #when_finalized

Methods included from GUI::GraphvizPlanObject

#apply_layout, #dot_label, #to_dot

Methods included from Relations::DirectedRelationSupport

#[], #[]=, #add_child_object, #add_parent_object, #child_object?, #child_objects, #clear_vertex, #each_child_object, #each_in_neighbour, #each_out_neighbour, #each_parent_object, #each_relation, #each_relation_graph, #each_relation_sorted, #each_root_relation_graph, #enum_child_objects, #enum_parent_objects, #enum_relations, #leaf?, #parent_object?, #parent_objects, #related_object?, #related_objects, #relation_graph_for, #relations, #remove_child_object, #remove_children, #remove_parent_object, #remove_parents, #remove_relations, #root?, #sorted_relations

Methods inherited from DistributedObject

#add_owner, #clear_owners, #initialize_copy, #owned_by?, #remove_owner

Constructor Details

#initializeOrGenerator

Creates a new OrGenerator without any sources.



38
39
40
41
42
43
# File 'lib/roby/or_generator.rb', line 38

def initialize
    super do |context|
        emit_if_first(context)
    end
    @active = true
end

Instance Method Details

#<<(generator) ⇒ Object

Adds generator to the sources of this event



87
88
89
90
# File 'lib/roby/or_generator.rb', line 87

def <<(generator)
    generator.add_signal self
    self
end

#added_signal_parent(parent, info) ⇒ Object

Tracks the event’s parents in the signalling relation



70
71
72
73
74
75
76
77
# File 'lib/roby/or_generator.rb', line 70

def added_signal_parent(parent, info) # :nodoc:
    super
    parent.if_unreachable(cancel_at_emission: true) do |reason, event|
        if !emitted? && each_parent_object(EventStructure::Signal).all?(&:unreachable?)
            unreachable!(reason || parent)
        end
    end
end

#emit_if_first(context) ⇒ Object

Helper method called to emit the event when it is required



62
63
64
65
66
67
# File 'lib/roby/or_generator.rb', line 62

def emit_if_first(context) # :nodoc:
    return unless @active

    @active = false
    emit(context)
end

#empty?Boolean

True if there is no source events

Returns:

  • (Boolean)


46
47
48
# File 'lib/roby/or_generator.rb', line 46

def empty?
    parent_objects(EventStructure::Signal).empty?
end

#removed_signal_parent(parent) ⇒ Object



79
80
81
82
83
84
# File 'lib/roby/or_generator.rb', line 79

def removed_signal_parent(parent)
    super
    if !emitted? && each_parent_object(EventStructure::Signal).all?(&:unreachable?)
        unreachable!
    end
end

#resetObject

Or generators will emit only once, unless this method is called. See the documentation of OrGenerator for an example.



52
53
54
55
56
57
58
59
# File 'lib/roby/or_generator.rb', line 52

def reset
    @active = true
    each_parent_object(EventStructure::Signal) do |source|
        if source.respond_to?(:reset)
            source.reset
        end
    end
end