Class: Roby::AndGenerator

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

Overview

Event generator which fires when all its source events have fired See EventGenerator#& for a more complete description

Constant Summary

Constants included from Log::EventGeneratorHooks

Log::EventGeneratorHooks::HOOKS

Constants included from Log::BasicObjectHooks

Log::BasicObjectHooks::HOOKS

Instance Attribute Summary

Attributes inherited from EventGenerator

#command, #executable, #pending, #unreachable_handlers

Attributes inherited from PlanObject

#executable, #plan, #removed_at

Attributes inherited from BasicObject

#distribute

Instance Method Summary collapse

Methods inherited from EventGenerator

#&, #_dump, _load, #achieve_with, #add_child_object, #call, #call_handlers, #call_without_propagation, #called, #calling, #cancel, #controlable?, #default_command, #delay, #droby_dump, #each_precondition, #emit, #emit_failed, #emit_on, #emit_without_propagation, #emitting, event_gathering, #executable?, #filter, #fired, #forward, #forward_once, #forwarding, gather_events, #if_unreachable, #initialize_copy, #last, #model, #name, #new, #on, #once, #pending?, #postpone, #postponed, #precondition, #pretty_print, #realize_with, #related_events, #related_tasks, remove_event_gathering, #signal, #signal_once, #signalling, #to_event, #unreachable!, #until, #when_unreachable, #|

Methods included from Distributed::DRobyModel::Dump

#droby_dump

Methods included from Distributed::EventNotifications

#fired, #forwarding, #signalling

Methods included from Propagation::EventPrecedenceChanged

#added_child_object, #removed_child_object

Methods included from Log::EventGeneratorHooks

#added_child_object, #called, #calling, #emitting, #fired, #forwarding, #postponed, #removed_child_object, #signalling

Methods inherited from PlanObject

#add_child_object, #apply_relation_changes, child_plan_object, #each_plan_child, #executable?, #finalized?, #forget_peer, #read_write?, #remotely_useful?, #removing_child_object, #replace_by, #replace_subplan_by, #root_object, #root_object?, #subscribed?, #update_on?, #updated_by?

Methods included from Distributed::RelationModificationHooks

#added_child_object, #removed_child_object

Methods included from Transactions::PlanObjectUpdates

#adding_child_object, #removing_child_object

Methods included from DirectedRelationSupport

#add_child_object, #add_parent_object, #check_is_relation, #related_objects, #relations, #remove_child_object, #remove_children, #remove_parent_object, #remove_parents, #remove_relations

Methods inherited from BasicObject

#add_sibling_for, #distribute?, distribute?, #finalized?, #forget_peer, #has_sibling_on?, #initialize_copy, local_only, #read_write?, #remotely_useful?, #remove_sibling_for, #self_owned?, #sibling_of, #sibling_on, #subscribe, #subscribed?, #update_on?, #updated?, #updated_by?, #updated_peers

Methods included from Log::BasicObjectHooks

#added_owner, #removed_owner

Constructor Details

#initializeAndGenerator

Returns a new instance of AndGenerator.



779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
# File 'lib/roby/event.rb', line 779

def initialize
    super do |context|
	emit_if_achieved(context)
    end

    # This hash is a event_generator => event mapping of the last
    # events of each event generator. We compare the event stored in
    # this hash with the last events of each source to know if the
    # source fired since it has been added to this AndGenerator
    @events = Hash.new

    # This flag is true unless we are not waiting for the emission
    # anymore.
    @active = true
end

Instance Method Details

#<<(generator) ⇒ Object

Add a new source to this generator



846
847
848
849
# File 'lib/roby/event.rb', line 846

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

#added_parent_object(parent, relations, info) ⇒ Object

Adds a new source to events when a source event is added



819
820
821
822
823
824
825
826
827
828
829
830
831
# File 'lib/roby/event.rb', line 819

def added_parent_object(parent, relations, info) # :nodoc:
    super if defined? super
    return unless relations.include?(EventStructure::Signal)
    @events[parent] = parent.last

    # If the parent is unreachable, check that it has neither been
    # removed, nor it has been emitted
    parent.if_unreachable(true) do |reason|
	if @events[parent] == parent.last
	    unreachable!(reason || parent)
	end
    end
end

#emit_if_achieved(context) ⇒ Object

:nodoc:



807
808
809
810
811
812
813
814
# File 'lib/roby/event.rb', line 807

def emit_if_achieved(context) # :nodoc:
    return unless @active
    each_parent_object(EventStructure::Signal) do |source|
	return if @events[source] == source.last
    end
    @active = false
    emit(nil)
end

#empty?Boolean

Returns:

  • (Boolean)


816
# File 'lib/roby/event.rb', line 816

def empty?; events.empty? end

#eventsObject

The set of source events



841
# File 'lib/roby/event.rb', line 841

def events;  parent_objects(EventStructure::Signal) end

#removed_parent_object(parent, relations) ⇒ Object

Removes a source from events when the source is removed



834
835
836
837
838
# File 'lib/roby/event.rb', line 834

def removed_parent_object(parent, relations) # :nodoc:
    super if defined? super
    return unless relations.include?(EventStructure::Signal)
    @events.delete(parent)
end

#resetObject

Resets the waiting. If the event has already been emitted, it re-arms it.



797
798
799
800
801
802
803
804
805
# File 'lib/roby/event.rb', line 797

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

#waitingObject

The set of events which we are waiting for



843
# File 'lib/roby/event.rb', line 843

def waiting; parent_objects(EventStructure::Signal).find_all { |ev| @events[ev] == ev.last } end