Module: Roby::Transaction::TaskProxy

Includes:
GUI::GraphvizTask, GUI::RelationsCanvasTaskProxy
Defined in:
lib/roby/transaction/task_proxy.rb

Overview

Transaction proxy for Roby::Task

Constant Summary collapse

STATE_PREDICATES =
%i[pending? running? finished? success? failed?].freeze

Instance Attribute Summary

Attributes included from GUI::RelationsCanvasTaskProxy

#real_object

Attributes included from GUI::RelationsCanvasTask

#displayed_state, #last_event

Instance Method Summary collapse

Methods included from GUI::GraphvizTask

#apply_layout, #dot_label, #to_dot_events

Methods included from GUI::GraphvizPlanObject

#apply_layout, #dot_label, #to_dot

Methods included from GUI::RelationsCanvasTaskProxy

#display, #display_create, #display_name, #display_parent, #flags

Methods included from GUI::RelationsCanvasTask

#display, #display_create, #display_name, #display_time_end, #display_time_start, #layout_events, to_svg, #update_graphics

Methods included from GUI::RelationsCanvasPlanObject

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

Instance Method Details

#commit_transactionObject

Perform the operations needed for the commit to be successful. In practice, it updates the task arguments as needed.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/roby/transaction/task_proxy.rb', line 78

def commit_transaction
    super

    # Update the task arguments. The original
    # Roby::Task#commit_transaction has already translated the proxy
    # objects into real objects
    arguments.each do |key, value|
        __getobj__.arguments.update!(key, value)
    end

    execute_handlers.each do |h|
        __getobj__.execute(h.as_options, &h.block)
    end
    poll_handlers.each do |h|
        __getobj__.poll(h.as_options, &h.block)
    end

    __getobj__.abstract = self.abstract?
    if @fullfilled_model
        __getobj__.fullfilled_model = @fullfilled_model.dup
    end
    __getobj__.do_not_reuse unless @reusable
end

#event(name) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/roby/transaction/task_proxy.rb', line 67

def event(name)
    if ev = find_event(name)
        ev
    else
        ev = __getobj__.event(name)
        bound_events[ev.symbol] = plan.create_and_register_proxy_event(ev)
    end
end

#has_event?(name) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/roby/transaction/task_proxy.rb', line 63

def has_event?(name)
    super || __getobj__.has_event?(name)
end

#initialize_replacement(task) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/roby/transaction/task_proxy.rb', line 102

def initialize_replacement(task)
    super

    seen_events = bound_events.keys.to_set

    # Apply recursively all event handlers of this (proxied) task to
    # the new task
    #
    # 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.execute_handlers.each do |h|
            if h.copy_on_replace?
                task.execute(h.as_options, &h.block)
            end
        end
        real_object.poll_handlers.each do |h|
            if h.copy_on_replace?
                task.poll(h.as_options, &h.block)
            end
        end

        # Do the same for all events that are not present at this level
        # of the transaction
        real_object.each_event do |event|
            unless seen_events.include?(event.symbol)
                event.initialize_replacement(nil) { task.event(event.symbol) }
                seen_events << event.symbol
            end
        end
    end
end

#setup_proxy(object, transaction) ⇒ Object

Create a new proxy representing object in transaction



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/roby/transaction/task_proxy.rb', line 20

def setup_proxy(object, transaction)
    super(object, transaction)

    @poll_handlers.clear
    @execute_handlers.clear

    @arguments = Roby::TaskArguments.new(self)
    unless bound_events.empty?
        raise ArgumentError, "expected bound_events to be empty when setting the proxy up"
    end

    STATE_PREDICATES.each do |predicate_name|
        instance_variable_set "@#{predicate_name[0..-2]}", object.send(predicate_name)
    end

    object.arguments.each do |key, value|
        if value.kind_of?(Roby::PlanObject)
            arguments.update!(key, transaction[value])
        else
            arguments.update!(key, value)
        end
    end

    proxied_events = []
    events = object.each_event.to_a
    transaction.plan.each_event_relation_graph do |g|
        next unless g.root_relation?

        events.delete_if do |event|
            should_proxy =
                g.each_in_neighbour(event).any? { |e| !e.respond_to?(:task) || e.task != object } ||
                g.each_out_neighbour(event).any? { |e| !e.respond_to?(:task) || e.task != object }
            if should_proxy
                proxied_events << event
            end
        end
        break if events.empty?
    end
    proxied_events.each do |ev|
        transaction.create_and_register_proxy_event(ev)
    end
end

#to_sObject



9
10
11
# File 'lib/roby/transaction/task_proxy.rb', line 9

def to_s
    "tProxy(#{__getobj__.name})#{arguments}"
end