Module: Roby::Transaction::EventGeneratorProxy

Defined in:
lib/roby/transaction/event_generator_proxy.rb

Instance Method Summary collapse

Instance Method Details

#commit_transactionObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/roby/transaction/event_generator_proxy.rb', line 45

def commit_transaction
    super

    handlers.each { |h| __getobj__.on(h.as_options, &h.block) }
    unreachable_handlers.each do |cancel, h|
        on_replace = if h.copy_on_replace? then :copy
                     else :drop
                     end
        __getobj__.if_unreachable(
            cancel_at_emission: cancel,
            on_replace: on_replace,
            &h.block)
    end
end

#initialize_replacement(event) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/roby/transaction/event_generator_proxy.rb', line 15

def initialize_replacement(event)
    # Apply recursively all event handlers of this (proxied) event to
    # the new event
    #
    # We have to look at all levels as, in transactions, the "handlers"
    # set only contains new event handlers
    real_object = self
    while real_object.transaction_proxy?
        real_object = real_object.__getobj__

        real_object.handlers.each do |h|
            if h.copy_on_replace?
                event ||= yield
                event.on(h.as_options, &h.block)
            end
        end
        real_object.unreachable_handlers.each do |cancel, h|
            if h.copy_on_replace?
                event ||= yield
                event.if_unreachable(cancel_at_emission: cancel, on_replace: :copy, &h.block)
            end
        end
    end

    if event
        super(event)
    else super(nil, &Proc.new)
    end
end

#setup_proxy(object, plan) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/roby/transaction/event_generator_proxy.rb', line 6

def setup_proxy(object, plan)
    super(object, plan)
    @handlers.clear
    @unreachable_handlers.clear
    if object.controlable?
        @command = method(:emit)
    end
end