roby 0.7.3 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -5
- data/Manifest.txt +91 -16
- data/README.txt +24 -24
- data/Rakefile +92 -64
- data/app/config/app.yml +42 -43
- data/app/config/init.rb +26 -0
- data/benchmark/alloc_misc.rb +123 -0
- data/benchmark/discovery_latency.rb +67 -0
- data/benchmark/garbage_collection.rb +48 -0
- data/benchmark/genom.rb +31 -0
- data/benchmark/transactions.rb +62 -0
- data/bin/roby +1 -1
- data/bin/roby-log +16 -6
- data/doc/guide/.gitignore +2 -0
- data/doc/guide/config.yaml +34 -0
- data/doc/guide/ext/init.rb +14 -0
- data/doc/guide/ext/previous_next.rb +40 -0
- data/doc/guide/ext/rdoc_links.rb +33 -0
- data/doc/guide/index.rdoc +16 -0
- data/doc/guide/overview.rdoc +62 -0
- data/doc/guide/plan_modifications.rdoc +67 -0
- data/doc/guide/src/abstraction/achieve_with.page +8 -0
- data/doc/guide/src/abstraction/forwarding.page +8 -0
- data/doc/guide/src/abstraction/hierarchy.page +19 -0
- data/doc/guide/src/abstraction/index.page +28 -0
- data/doc/guide/src/abstraction/task_models.page +13 -0
- data/doc/guide/src/basics.template +6 -0
- data/doc/guide/src/basics/app.page +139 -0
- data/doc/guide/src/basics/code_examples.page +33 -0
- data/doc/guide/src/basics/dry.page +69 -0
- data/doc/guide/src/basics/errors.page +443 -0
- data/doc/guide/src/basics/events.page +179 -0
- data/doc/guide/src/basics/hierarchy.page +275 -0
- data/doc/guide/src/basics/index.page +11 -0
- data/doc/guide/src/basics/log_replay/goForward_1.png +0 -0
- data/doc/guide/src/basics/log_replay/goForward_2.png +0 -0
- data/doc/guide/src/basics/log_replay/goForward_3.png +0 -0
- data/doc/guide/src/basics/log_replay/goForward_4.png +0 -0
- data/doc/guide/src/basics/log_replay/goForward_5.png +0 -0
- data/doc/guide/src/basics/log_replay/hierarchy_error_1.png +0 -0
- data/doc/guide/src/basics/log_replay/hierarchy_error_2.png +0 -0
- data/doc/guide/src/basics/log_replay/hierarchy_error_3.png +0 -0
- data/doc/guide/src/basics/log_replay/plan_repair_1.png +0 -0
- data/doc/guide/src/basics/log_replay/plan_repair_2.png +0 -0
- data/doc/guide/src/basics/log_replay/plan_repair_3.png +0 -0
- data/doc/guide/src/basics/log_replay/plan_repair_4.png +0 -0
- data/doc/guide/src/basics/log_replay/roby_log_main_window.png +0 -0
- data/doc/guide/src/basics/log_replay/roby_log_relation_window.png +0 -0
- data/doc/guide/src/basics/log_replay/roby_replay_event_representation.png +0 -0
- data/doc/guide/src/basics/plan_objects.page +71 -0
- data/doc/guide/src/basics/relations_display.page +203 -0
- data/doc/guide/src/basics/roby_cycle_overview.png +0 -0
- data/doc/guide/src/basics/shell.page +102 -0
- data/doc/guide/src/basics/summary.page +32 -0
- data/doc/guide/src/basics/tasks.page +357 -0
- data/doc/guide/src/basics_shell_header.txt +16 -0
- data/doc/guide/src/cycle/cycle-overview.png +0 -0
- data/doc/guide/src/cycle/cycle-overview.svg +208 -0
- data/doc/guide/src/cycle/error_handling.page +168 -0
- data/doc/guide/src/cycle/error_instantaneous_repair.png +0 -0
- data/doc/guide/src/cycle/error_instantaneous_repair.svg +1224 -0
- data/doc/guide/src/cycle/garbage_collection.page +10 -0
- data/doc/guide/src/cycle/index.page +23 -0
- data/doc/guide/src/cycle/propagation.page +154 -0
- data/doc/guide/src/cycle/propagation_diamond.png +0 -0
- data/doc/guide/src/cycle/propagation_diamond.svg +1279 -0
- data/doc/guide/src/default.css +319 -0
- data/doc/guide/src/default.template +74 -0
- data/doc/guide/src/htmldoc.metainfo +20 -0
- data/doc/guide/src/htmldoc.virtual +18 -0
- data/doc/guide/src/images/bodybg.png +0 -0
- data/doc/guide/src/images/contbg.png +0 -0
- data/doc/guide/src/images/footerbg.png +0 -0
- data/doc/guide/src/images/gradient1.png +0 -0
- data/doc/guide/src/images/gradient2.png +0 -0
- data/doc/guide/src/index.page +7 -0
- data/doc/guide/src/introduction/index.page +29 -0
- data/doc/guide/src/introduction/install.page +133 -0
- data/doc/{papers.rdoc → guide/src/introduction/publications.page} +5 -2
- data/doc/{videos.rdoc → guide/src/introduction/videos.page} +4 -2
- data/doc/guide/src/plugins/fault_tolerance.page +44 -0
- data/doc/guide/src/plugins/index.page +11 -0
- data/doc/guide/src/plugins/subsystems.page +45 -0
- data/doc/guide/src/relations/dependency.page +89 -0
- data/doc/guide/src/relations/index.page +12 -0
- data/doc/misc/update_github +24 -0
- data/doc/tutorials/02-GoForward.rdoc +3 -3
- data/ext/graph/graph.cc +46 -0
- data/lib/roby.rb +57 -22
- data/lib/roby/app.rb +132 -112
- data/lib/roby/app/plugins/rake.rb +21 -0
- data/lib/roby/app/rake.rb +0 -7
- data/lib/roby/app/run.rb +1 -1
- data/lib/roby/app/scripts/distributed.rb +1 -2
- data/lib/roby/app/scripts/generate/bookmarks.rb +1 -1
- data/lib/roby/app/scripts/results.rb +2 -1
- data/lib/roby/app/scripts/run.rb +6 -2
- data/lib/roby/app/scripts/shell.rb +11 -11
- data/lib/roby/config.rb +1 -1
- data/lib/roby/decision_control.rb +62 -3
- data/lib/roby/distributed.rb +4 -0
- data/lib/roby/distributed/base.rb +8 -0
- data/lib/roby/distributed/communication.rb +12 -8
- data/lib/roby/distributed/connection_space.rb +61 -44
- data/lib/roby/distributed/distributed_object.rb +1 -1
- data/lib/roby/distributed/notifications.rb +22 -30
- data/lib/roby/distributed/peer.rb +13 -8
- data/lib/roby/distributed/proxy.rb +5 -5
- data/lib/roby/distributed/subscription.rb +4 -4
- data/lib/roby/distributed/transaction.rb +3 -3
- data/lib/roby/event.rb +176 -110
- data/lib/roby/exceptions.rb +12 -4
- data/lib/roby/execution_engine.rb +1604 -0
- data/lib/roby/external_process_task.rb +225 -0
- data/lib/roby/graph.rb +0 -6
- data/lib/roby/interface.rb +221 -137
- data/lib/roby/log/console.rb +5 -3
- data/lib/roby/log/data_stream.rb +94 -16
- data/lib/roby/log/dot.rb +8 -8
- data/lib/roby/log/event_stream.rb +13 -3
- data/lib/roby/log/file.rb +43 -18
- data/lib/roby/log/gui/basic_display_ui.rb +89 -0
- data/lib/roby/log/gui/chronicle_view_ui.rb +90 -0
- data/lib/roby/log/gui/data_displays.rb +4 -5
- data/lib/roby/log/gui/data_displays_ui.rb +146 -0
- data/lib/roby/log/gui/relations.rb +18 -18
- data/lib/roby/log/gui/relations_ui.rb +120 -0
- data/lib/roby/log/gui/relations_view_ui.rb +144 -0
- data/lib/roby/log/gui/replay.rb +41 -13
- data/lib/roby/log/gui/replay_controls.rb +3 -0
- data/lib/roby/log/gui/replay_controls.ui +133 -110
- data/lib/roby/log/gui/replay_controls_ui.rb +249 -0
- data/lib/roby/log/hooks.rb +19 -18
- data/lib/roby/log/logger.rb +7 -6
- data/lib/roby/log/notifications.rb +4 -4
- data/lib/roby/log/plan_rebuilder.rb +20 -22
- data/lib/roby/log/relations.rb +44 -16
- data/lib/roby/log/server.rb +1 -4
- data/lib/roby/log/timings.rb +88 -19
- data/lib/roby/plan-object.rb +135 -11
- data/lib/roby/plan.rb +408 -224
- data/lib/roby/planning/loops.rb +32 -25
- data/lib/roby/planning/model.rb +157 -51
- data/lib/roby/planning/task.rb +47 -20
- data/lib/roby/query.rb +128 -92
- data/lib/roby/relations.rb +254 -136
- data/lib/roby/relations/conflicts.rb +6 -9
- data/lib/roby/relations/dependency.rb +358 -0
- data/lib/roby/relations/ensured.rb +0 -1
- data/lib/roby/relations/error_handling.rb +0 -1
- data/lib/roby/relations/events.rb +0 -2
- data/lib/roby/relations/executed_by.rb +26 -11
- data/lib/roby/relations/planned_by.rb +14 -14
- data/lib/roby/robot.rb +46 -0
- data/lib/roby/schedulers/basic.rb +34 -0
- data/lib/roby/standalone.rb +4 -0
- data/lib/roby/standard_errors.rb +21 -15
- data/lib/roby/state/events.rb +5 -4
- data/lib/roby/support.rb +107 -6
- data/lib/roby/task-operations.rb +23 -19
- data/lib/roby/task.rb +522 -148
- data/lib/roby/task_index.rb +80 -0
- data/lib/roby/test/common.rb +283 -44
- data/lib/roby/test/distributed.rb +53 -37
- data/lib/roby/test/testcase.rb +9 -204
- data/lib/roby/test/tools.rb +3 -3
- data/lib/roby/transactions.rb +154 -111
- data/lib/roby/transactions/proxy.rb +40 -7
- data/manifest.xml +20 -0
- data/plugins/fault_injection/README.txt +0 -3
- data/plugins/fault_injection/Rakefile +2 -8
- data/plugins/fault_injection/app.rb +1 -1
- data/plugins/fault_injection/fault_injection.rb +3 -3
- data/plugins/fault_injection/test/test_fault_injection.rb +19 -25
- data/plugins/subsystems/README.txt +0 -3
- data/plugins/subsystems/Rakefile +2 -7
- data/plugins/subsystems/app.rb +27 -16
- data/plugins/subsystems/test/app/config/init.rb +3 -0
- data/plugins/subsystems/test/app/planners/main.rb +1 -1
- data/plugins/subsystems/test/app/tasks/services.rb +1 -1
- data/plugins/subsystems/test/test_subsystems.rb +23 -16
- data/test/distributed/test_communication.rb +32 -15
- data/test/distributed/test_connection.rb +28 -26
- data/test/distributed/test_execution.rb +59 -54
- data/test/distributed/test_mixed_plan.rb +34 -34
- data/test/distributed/test_plan_notifications.rb +26 -26
- data/test/distributed/test_protocol.rb +57 -48
- data/test/distributed/test_query.rb +11 -7
- data/test/distributed/test_remote_plan.rb +71 -71
- data/test/distributed/test_transaction.rb +50 -47
- data/test/mockups/external_process +28 -0
- data/test/planning/test_loops.rb +163 -119
- data/test/planning/test_model.rb +3 -3
- data/test/planning/test_task.rb +27 -7
- data/test/relations/test_conflicts.rb +3 -3
- data/test/relations/test_dependency.rb +324 -0
- data/test/relations/test_ensured.rb +2 -2
- data/test/relations/test_executed_by.rb +94 -19
- data/test/relations/test_planned_by.rb +11 -9
- data/test/suite_core.rb +6 -3
- data/test/suite_distributed.rb +1 -0
- data/test/suite_planning.rb +1 -0
- data/test/suite_relations.rb +2 -2
- data/test/tasks/test_external_process.rb +126 -0
- data/test/{test_thread_task.rb → tasks/test_thread_task.rb} +17 -20
- data/test/test_bgl.rb +21 -1
- data/test/test_event.rb +229 -155
- data/test/test_exceptions.rb +79 -80
- data/test/test_execution_engine.rb +987 -0
- data/test/test_gui.rb +1 -1
- data/test/test_interface.rb +11 -5
- data/test/test_log.rb +18 -7
- data/test/test_log_server.rb +1 -0
- data/test/test_plan.rb +229 -395
- data/test/test_query.rb +193 -35
- data/test/test_relations.rb +88 -8
- data/test/test_state.rb +55 -37
- data/test/test_support.rb +1 -1
- data/test/test_task.rb +371 -218
- data/test/test_testcase.rb +32 -16
- data/test/test_transactions.rb +211 -170
- data/test/test_transactions_proxy.rb +37 -19
- metadata +169 -71
- data/.gitignore +0 -29
- data/doc/styles/allison.css +0 -314
- data/doc/styles/allison.js +0 -316
- data/doc/styles/allison.rb +0 -276
- data/doc/styles/jamis.rb +0 -593
- data/lib/roby/control.rb +0 -746
- data/lib/roby/executives/simple.rb +0 -30
- data/lib/roby/propagation.rb +0 -562
- data/lib/roby/relations/hierarchy.rb +0 -239
- data/lib/roby/transactions/updates.rb +0 -139
- data/test/relations/test_hierarchy.rb +0 -158
- data/test/test_control.rb +0 -399
- data/test/test_propagation.rb +0 -210
@@ -1,30 +0,0 @@
|
|
1
|
-
module Roby
|
2
|
-
module Executives
|
3
|
-
class Simple
|
4
|
-
attr_reader :query
|
5
|
-
def initialize
|
6
|
-
@query = Roby.plan.find_tasks.
|
7
|
-
executable.
|
8
|
-
pending.
|
9
|
-
self_owned
|
10
|
-
end
|
11
|
-
def initial_events
|
12
|
-
query.reset.each do |task|
|
13
|
-
next unless task.event(:start).root? && task.event(:start).controlable?
|
14
|
-
root_task = task.enum_for(:each_relation).all? do |rel|
|
15
|
-
if task.root?(rel)
|
16
|
-
true
|
17
|
-
elsif rel == TaskStructure::PlannedBy
|
18
|
-
task.planned_tasks.all? { |t| !t.executable? }
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
if root_task
|
23
|
-
task.start!
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
data/lib/roby/propagation.rb
DELETED
@@ -1,562 +0,0 @@
|
|
1
|
-
require 'roby/support'
|
2
|
-
require 'roby/exceptions'
|
3
|
-
require 'utilrb/exception/full_message'
|
4
|
-
require 'utilrb/unbound_method'
|
5
|
-
require 'roby/relations/error_handling'
|
6
|
-
|
7
|
-
# This module contains all code necessary for the propagation steps during
|
8
|
-
# execution. This includes event and exception propagation
|
9
|
-
#
|
10
|
-
# == Event propagation
|
11
|
-
# Event propagation is based on three event relations:
|
12
|
-
#
|
13
|
-
# * Signal describes the commands that must be called when an event occurs. The
|
14
|
-
# signalled event command is called when the signalling events are emitted. If
|
15
|
-
# more than one event are signalling the same event in the same execution
|
16
|
-
# cycle, the command will be called only once
|
17
|
-
# * Forwarding describes the events that must be emitted whenever a source
|
18
|
-
# event is. It is to be used as a way to define event aliases (for instance
|
19
|
-
# 'stop' is an alias for 'success'), because a task is stopped when it has
|
20
|
-
# finished with success. Unlike with signals, if more than one event is
|
21
|
-
# forwarded to the same event in the same cycle, the target event will be
|
22
|
-
# emitted as many times as the incoming events.
|
23
|
-
# * Precedence is a graph which constrains the order in which propagation is
|
24
|
-
# done. If there is a a => b edge in Precedence, and if both events are either
|
25
|
-
# called and/or forwarded in the same cycle, then 'a' will be propagated before
|
26
|
-
# 'b'. All edges in Signal and Forwarding are present in Precedence
|
27
|
-
#
|
28
|
-
# == Exception propagation
|
29
|
-
#
|
30
|
-
module Roby::Propagation
|
31
|
-
extend Logger::Hierarchy
|
32
|
-
extend Logger::Forward
|
33
|
-
|
34
|
-
@@propagation_id = 0
|
35
|
-
def self.propagation_id; Thread.current[:propagation_id] end
|
36
|
-
|
37
|
-
# If we are currently in the propagation stage
|
38
|
-
def self.gathering?; !!Thread.current[:propagation] end
|
39
|
-
# The set of source events for the current propagation action. This is a
|
40
|
-
# mix of EventGenerator and Event objects.
|
41
|
-
def self.sources; Thread.current[:propagation_sources] end
|
42
|
-
# The set of events extracted from PropagationException.sources
|
43
|
-
def self.source_events
|
44
|
-
result = ValueSet.new
|
45
|
-
for ev in Thread.current[:propagation_sources]
|
46
|
-
if ev.respond_to?(:generator)
|
47
|
-
result << ev
|
48
|
-
end
|
49
|
-
end
|
50
|
-
result
|
51
|
-
end
|
52
|
-
|
53
|
-
# The set of generators extracted from Propagation.sources
|
54
|
-
def self.source_generators
|
55
|
-
result = ValueSet.new
|
56
|
-
for ev in Thread.current[:propagation_sources]
|
57
|
-
result << if ev.respond_to?(:generator)
|
58
|
-
ev.generator
|
59
|
-
else
|
60
|
-
ev
|
61
|
-
end
|
62
|
-
end
|
63
|
-
result
|
64
|
-
end
|
65
|
-
|
66
|
-
@@delayed_events = []
|
67
|
-
def self.delayed_events; @@delayed_events end
|
68
|
-
def self.add_event_delay(time, forward, source, signalled, context)
|
69
|
-
delayed_events << [time, forward, source, signalled, context]
|
70
|
-
end
|
71
|
-
def self.execute_delayed_events
|
72
|
-
reftime = Time.now
|
73
|
-
delayed_events.delete_if do |time, forward, source, signalled, context|
|
74
|
-
if time < reftime
|
75
|
-
add_event_propagation(forward, [source], signalled, context, nil)
|
76
|
-
true
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
module RemoveDelayedOnFinalized
|
81
|
-
def finalized_event(event)
|
82
|
-
super if defined? super
|
83
|
-
Roby::Propagation.delayed_events.delete_if { |_, _, _, signalled, _| signalled == event }
|
84
|
-
end
|
85
|
-
end
|
86
|
-
Roby::Plan.include RemoveDelayedOnFinalized
|
87
|
-
Roby::Control.event_processing << Roby::Propagation.method(:execute_delayed_events)
|
88
|
-
|
89
|
-
# Begin an event propagation stage
|
90
|
-
def self.gather_propagation(initial_set = Hash.new)
|
91
|
-
raise InternalError, "nested call to #gather_propagation" if gathering?
|
92
|
-
Thread.current[:propagation] = initial_set
|
93
|
-
|
94
|
-
propagation_context(nil) { yield }
|
95
|
-
|
96
|
-
return Thread.current[:propagation]
|
97
|
-
ensure
|
98
|
-
Thread.current[:propagation] = nil
|
99
|
-
end
|
100
|
-
|
101
|
-
def self.to_execution_exception(error)
|
102
|
-
Roby::ExecutionException.new(error)
|
103
|
-
end
|
104
|
-
|
105
|
-
def self.add_error(e)
|
106
|
-
if Thread.current[:propagation_exceptions]
|
107
|
-
plan_exception = to_execution_exception(e)
|
108
|
-
Thread.current[:propagation_exceptions] << plan_exception
|
109
|
-
else
|
110
|
-
if e.respond_to?(:error) && e.error
|
111
|
-
add_framework_error(e.error, "error outside error handling")
|
112
|
-
else
|
113
|
-
add_framework_error(e, "error outside error handling")
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def self.gather_framework_errors(source)
|
119
|
-
yield
|
120
|
-
rescue Exception => e
|
121
|
-
add_framework_error(e, source)
|
122
|
-
end
|
123
|
-
|
124
|
-
def self.add_framework_error(error, source)
|
125
|
-
if Thread.current[:application_exceptions]
|
126
|
-
Thread.current[:application_exceptions] << [error, source]
|
127
|
-
elsif Roby.control.abort_on_application_exception || error.kind_of?(SignalException)
|
128
|
-
raise error, "in #{source}: #{error.message}", error.backtrace
|
129
|
-
else
|
130
|
-
Roby.error "Application error in #{source}: #{error.full_message}"
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
# Sets the source_event and source_generator variables according
|
135
|
-
# to +source+. +source+ is the +from+ argument of #add_event_propagation
|
136
|
-
def self.propagation_context(sources)
|
137
|
-
raise InternalError, "not in a gathering context in #fire" unless gathering?
|
138
|
-
|
139
|
-
if sources
|
140
|
-
current_sources = sources
|
141
|
-
Thread.current[:propagation_sources] = sources
|
142
|
-
else
|
143
|
-
Thread.current[:propagation_sources] = []
|
144
|
-
end
|
145
|
-
|
146
|
-
yield Thread.current[:propagation]
|
147
|
-
|
148
|
-
ensure
|
149
|
-
Thread.current[:propagation_sources] = sources
|
150
|
-
end
|
151
|
-
|
152
|
-
# Adds a propagation to the next propagation step. More specifically, it
|
153
|
-
# adds either forwarding or signalling the set of Event objects +from+ to
|
154
|
-
# the +signalled+ event generator, with the context +context+
|
155
|
-
def self.add_event_propagation(forward, from, signalled, context, timespec)
|
156
|
-
if signalled.plan != Roby.plan
|
157
|
-
raise Roby::EventNotExecutable.new(signalled), "#{signalled} not in main plan"
|
158
|
-
end
|
159
|
-
|
160
|
-
step = (Thread.current[:propagation][signalled] ||= [nil, nil])
|
161
|
-
from = [nil] unless from && !from.empty?
|
162
|
-
|
163
|
-
step = if forward then (step[0] ||= [])
|
164
|
-
else (step[1] ||= [])
|
165
|
-
end
|
166
|
-
|
167
|
-
from.each do |ev|
|
168
|
-
step << ev << context << timespec
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
# Calls its block in a #gather_propagation context and propagate events
|
173
|
-
# that have been called and/or emitted by the block
|
174
|
-
#
|
175
|
-
# If a block is given, it is called with the initial set of events: the
|
176
|
-
# events we should consider as already emitted in the following propagation.
|
177
|
-
# +seeds+ si a list of procs which should be called to initiate the propagation
|
178
|
-
# (i.e. build an initial set of events)
|
179
|
-
def self.propagate_events(seeds = [])
|
180
|
-
if Thread.current[:propagation_exceptions]
|
181
|
-
raise InternalError, "recursive call to propagate_events"
|
182
|
-
end
|
183
|
-
|
184
|
-
Thread.current[:propagation_id] = (@@propagation_id += 1)
|
185
|
-
Thread.current[:propagation_exceptions] = []
|
186
|
-
|
187
|
-
initial_set = []
|
188
|
-
next_step = gather_propagation do
|
189
|
-
gather_framework_errors('initial set setup') { yield(initial_set) } if block_given?
|
190
|
-
gather_framework_errors('distributed events') { Roby::Distributed.process_pending }
|
191
|
-
seeds.each do |s|
|
192
|
-
gather_framework_errors("seed #{s}") { s.call }
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
# Problem with postponed: the object is included in already_seen while it
|
197
|
-
# has not been fired
|
198
|
-
already_seen = initial_set.to_set
|
199
|
-
|
200
|
-
while !next_step.empty?
|
201
|
-
next_step = event_propagation_step(next_step, already_seen)
|
202
|
-
end
|
203
|
-
Thread.current[:propagation_exceptions]
|
204
|
-
|
205
|
-
ensure
|
206
|
-
Thread.current[:propagation_id] = nil
|
207
|
-
Thread.current[:propagation_exceptions] = nil
|
208
|
-
end
|
209
|
-
|
210
|
-
def self.validate_timespec(timespec)
|
211
|
-
if timespec
|
212
|
-
timespec = validate_options timespec, [:delay, :at]
|
213
|
-
end
|
214
|
-
end
|
215
|
-
def self.make_delay(timeref, source, signalled, timespec)
|
216
|
-
if delay = timespec[:delay] then timeref + delay
|
217
|
-
elsif at = timespec[:at] then at
|
218
|
-
else
|
219
|
-
raise ArgumentError, "invalid timespec #{timespec}"
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
@event_ordering = Array.new
|
224
|
-
@event_priorities = Hash.new
|
225
|
-
class << self
|
226
|
-
# The topological ordering of events w.r.t. the Precedence relation
|
227
|
-
attr_reader :event_ordering
|
228
|
-
# The event => index hash which give the propagation priority for each
|
229
|
-
# event
|
230
|
-
attr_reader :event_priorities
|
231
|
-
end
|
232
|
-
|
233
|
-
# This module hooks in plan modifications to clear the event ordering cache
|
234
|
-
# (Propagation.event_ordering) when needed.
|
235
|
-
#
|
236
|
-
# It is included in the main plan by Control#initialize
|
237
|
-
module ExecutablePlanChanged
|
238
|
-
def discovered_events(objects)
|
239
|
-
super if defined? super
|
240
|
-
Roby::Propagation.event_ordering.clear
|
241
|
-
end
|
242
|
-
def discovered_tasks(objects)
|
243
|
-
super if defined? super
|
244
|
-
Roby::Propagation.event_ordering.clear
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
# This module hooks in event relation modifications to clear the event
|
249
|
-
# ordering cache (Propagation.event_ordering) when needed.
|
250
|
-
module EventPrecedenceChanged
|
251
|
-
def added_child_object(child, relations, info)
|
252
|
-
super if defined? super
|
253
|
-
if relations.include?(Roby::EventStructure::Precedence) && plan == Roby.plan
|
254
|
-
Roby::Propagation.event_ordering.clear
|
255
|
-
end
|
256
|
-
end
|
257
|
-
def removed_child_object(child, relations)
|
258
|
-
super if defined? super
|
259
|
-
if relations.include?(Roby::EventStructure::Precedence) && plan == Roby.plan
|
260
|
-
Roby::Propagation.event_ordering.clear
|
261
|
-
end
|
262
|
-
end
|
263
|
-
end
|
264
|
-
Roby::EventGenerator.include EventPrecedenceChanged
|
265
|
-
|
266
|
-
# Determines the event in +current_step+ which should be signalled now.
|
267
|
-
# Removes it from the set and returns the event and the associated
|
268
|
-
# propagation information
|
269
|
-
def self.next_event(pending)
|
270
|
-
if event_ordering.empty?
|
271
|
-
Roby::EventStructure::Precedence.topological_sort(event_ordering)
|
272
|
-
event_priorities.clear
|
273
|
-
i = 0
|
274
|
-
for ev in event_ordering
|
275
|
-
event_priorities[ev] = i
|
276
|
-
i += 1
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
signalled, min = nil, event_ordering.size
|
281
|
-
for propagation_step in pending
|
282
|
-
event = propagation_step[0]
|
283
|
-
if priority = event_priorities[event]
|
284
|
-
if priority < min
|
285
|
-
signalled = event
|
286
|
-
min = priority
|
287
|
-
end
|
288
|
-
else
|
289
|
-
signalled = event
|
290
|
-
break
|
291
|
-
end
|
292
|
-
end
|
293
|
-
[signalled, *pending.delete(signalled)]
|
294
|
-
end
|
295
|
-
|
296
|
-
def self.prepare_propagation(signalled, forward, info)
|
297
|
-
timeref = Time.now
|
298
|
-
|
299
|
-
source_events, source_generators, context = ValueSet.new, ValueSet.new, []
|
300
|
-
|
301
|
-
delayed = true
|
302
|
-
info.each_slice(3) do |src, ctxt, time|
|
303
|
-
if time && (delay = make_delay(timeref, src, signalled, time))
|
304
|
-
add_event_delay(delay, forward, src, signalled, ctxt)
|
305
|
-
next
|
306
|
-
end
|
307
|
-
|
308
|
-
delayed = false
|
309
|
-
|
310
|
-
# Merge identical signals. Needed because two different event handlers
|
311
|
-
# can both call #emit, and two signals are set up
|
312
|
-
if src
|
313
|
-
if src.respond_to?(:generator)
|
314
|
-
source_events << src
|
315
|
-
source_generators << src.generator
|
316
|
-
else
|
317
|
-
source_generators << src
|
318
|
-
end
|
319
|
-
end
|
320
|
-
if ctxt
|
321
|
-
context.concat ctxt
|
322
|
-
end
|
323
|
-
end
|
324
|
-
|
325
|
-
unless delayed
|
326
|
-
[source_events, source_generators, (context unless context.empty?)]
|
327
|
-
end
|
328
|
-
end
|
329
|
-
|
330
|
-
# Propagate one step
|
331
|
-
#
|
332
|
-
# +current_step+ describes all pending emissions and calls. +already_seen+
|
333
|
-
# is obsolete and is not used anymore.
|
334
|
-
#
|
335
|
-
# This method calls Propagation.next_event to get the description of the
|
336
|
-
# next event to call. If there are signals going to this event, they are
|
337
|
-
# processed and the forwardings will be treated in the next step.
|
338
|
-
#
|
339
|
-
# The method returns the next set of pending emissions and calls, adding
|
340
|
-
# the forwardings and signals that the propagation of the considered event
|
341
|
-
# have added.
|
342
|
-
def self.event_propagation_step(current_step, already_seen)
|
343
|
-
signalled, forward_info, call_info = next_event(current_step)
|
344
|
-
|
345
|
-
next_step = nil
|
346
|
-
if call_info
|
347
|
-
source_events, source_generators, context = prepare_propagation(signalled, false, call_info)
|
348
|
-
if source_events
|
349
|
-
for source_ev in source_events
|
350
|
-
source_ev.generator.signalling(source_ev, signalled)
|
351
|
-
end
|
352
|
-
|
353
|
-
if signalled.self_owned?
|
354
|
-
next_step = gather_propagation(current_step) do
|
355
|
-
propagation_context(source_events | source_generators) do |result|
|
356
|
-
begin
|
357
|
-
signalled.call_without_propagation(context)
|
358
|
-
rescue Roby::LocalizedError => e
|
359
|
-
add_error(e)
|
360
|
-
rescue Exception => e
|
361
|
-
add_error(Roby::CommandFailed.new(e, signalled))
|
362
|
-
end
|
363
|
-
end
|
364
|
-
end
|
365
|
-
end
|
366
|
-
end
|
367
|
-
|
368
|
-
if forward_info
|
369
|
-
next_step ||= Hash.new
|
370
|
-
next_step[signalled] ||= []
|
371
|
-
next_step[signalled][0] ||= []
|
372
|
-
next_step[signalled][0].concat forward_info
|
373
|
-
end
|
374
|
-
|
375
|
-
elsif forward_info
|
376
|
-
source_events, source_generators, context = prepare_propagation(signalled, true, forward_info)
|
377
|
-
if source_events
|
378
|
-
for source_ev in source_events
|
379
|
-
source_ev.generator.forwarding(source_ev, signalled)
|
380
|
-
end
|
381
|
-
|
382
|
-
# If the destination event is not owned, but if the peer is not
|
383
|
-
# connected, the event is our responsibility now.
|
384
|
-
if signalled.self_owned? || !signalled.owners.any? { |peer| peer != Roby::Distributed && peer.connected? }
|
385
|
-
next_step = gather_propagation(current_step) do
|
386
|
-
propagation_context(source_events | source_generators) do |result|
|
387
|
-
begin
|
388
|
-
signalled.emit_without_propagation(context)
|
389
|
-
rescue Roby::LocalizedError => e
|
390
|
-
add_error(e)
|
391
|
-
rescue Exception => e
|
392
|
-
add_error(Roby::EmissionFailed.new(e, signalled))
|
393
|
-
end
|
394
|
-
end
|
395
|
-
end
|
396
|
-
end
|
397
|
-
end
|
398
|
-
end
|
399
|
-
|
400
|
-
current_step.merge!(next_step) if next_step
|
401
|
-
current_step
|
402
|
-
end
|
403
|
-
|
404
|
-
# Checks if +error+ is being repaired in the corresponding plan. Note that
|
405
|
-
# +error+ is supposed to be the original exception, not the corresponding
|
406
|
-
# ExecutionException object
|
407
|
-
def self.remove_inhibited_exceptions(exceptions)
|
408
|
-
exceptions.find_all do |e, _|
|
409
|
-
error = e.exception
|
410
|
-
if !error.respond_to?(:failed_event) ||
|
411
|
-
!(failure_point = error.failed_event)
|
412
|
-
true
|
413
|
-
else
|
414
|
-
Roby.plan.repairs_for(failure_point).empty?
|
415
|
-
end
|
416
|
-
end
|
417
|
-
end
|
418
|
-
|
419
|
-
def self.remove_useless_repairs
|
420
|
-
plan = Roby.plan
|
421
|
-
|
422
|
-
finished_repairs = plan.repairs.dup.delete_if { |_, task| task.starting? || task.running? }
|
423
|
-
for repair in finished_repairs
|
424
|
-
plan.remove_repair(repair[1])
|
425
|
-
end
|
426
|
-
|
427
|
-
finished_repairs
|
428
|
-
end
|
429
|
-
|
430
|
-
# Performs exception propagation for the given ExecutionException objects
|
431
|
-
# Returns all exceptions which have found no handlers in the task hierarchy
|
432
|
-
def self.propagate_exceptions(exceptions)
|
433
|
-
fatal = [] # the list of exceptions for which no handler has been found
|
434
|
-
|
435
|
-
# Remove finished repairs. Those are still considered during this cycle,
|
436
|
-
# as it is possible that some actions have been scheduled for the
|
437
|
-
# beginning of the next cycle through Roby.once
|
438
|
-
finished_repairs = remove_useless_repairs
|
439
|
-
# Remove remove exceptions for which a repair exists
|
440
|
-
exceptions = remove_inhibited_exceptions(exceptions)
|
441
|
-
|
442
|
-
# Install new repairs based on the HandledBy task relation. If a repair
|
443
|
-
# is installed, remove the exception from the set of errors to handle
|
444
|
-
exceptions.delete_if do |e, _|
|
445
|
-
# Check for handled_by relations which would be able to handle +e+
|
446
|
-
error = e.exception
|
447
|
-
next unless (failed_event = error.failed_event)
|
448
|
-
next unless (failed_task = error.failed_task)
|
449
|
-
next if finished_repairs.has_key?(failed_event)
|
450
|
-
|
451
|
-
failed_generator = error.failed_generator
|
452
|
-
|
453
|
-
repair = failed_task.find_error_handler do |repairing_task, event_set|
|
454
|
-
event_set.find do |repaired_generator|
|
455
|
-
repaired_generator = failed_task.event(repaired_generator)
|
456
|
-
|
457
|
-
!repairing_task.finished? &&
|
458
|
-
(repaired_generator == failed_generator ||
|
459
|
-
Roby::EventStructure::Forwarding.reachable?(failed_generator, repaired_generator))
|
460
|
-
end
|
461
|
-
end
|
462
|
-
|
463
|
-
if repair
|
464
|
-
failed_task.plan.add_repair(failed_event, repair)
|
465
|
-
true
|
466
|
-
else
|
467
|
-
false
|
468
|
-
end
|
469
|
-
end
|
470
|
-
|
471
|
-
while !exceptions.empty?
|
472
|
-
by_task = Hash.new { |h, k| h[k] = Array.new }
|
473
|
-
by_task = exceptions.inject(by_task) do |by_task, (e, parents)|
|
474
|
-
unless e.task
|
475
|
-
Roby.log_exception(e.exception, Roby, :fatal)
|
476
|
-
raise NotImplementedError, "we do not yet handle exceptions from external event generators. Got #{e.exception.full_message}"
|
477
|
-
end
|
478
|
-
parents ||= e.task.parent_objects(Roby::TaskStructure::Hierarchy)
|
479
|
-
|
480
|
-
has_parent = false
|
481
|
-
[*parents].each do |parent|
|
482
|
-
next if parent.finished?
|
483
|
-
|
484
|
-
if has_parent # we have more than one parent
|
485
|
-
e = e.fork
|
486
|
-
end
|
487
|
-
|
488
|
-
parent_exceptions = by_task[parent]
|
489
|
-
if s = parent_exceptions.find { |s| s.siblings.include?(e) }
|
490
|
-
s.merge(e)
|
491
|
-
else parent_exceptions << e
|
492
|
-
end
|
493
|
-
|
494
|
-
has_parent = true
|
495
|
-
end
|
496
|
-
|
497
|
-
# Add unhandled exceptions to the fatal set. Merge siblings
|
498
|
-
# exceptions if possible
|
499
|
-
unless has_parent
|
500
|
-
if s = fatal.find { |s| s.siblings.include?(e) }
|
501
|
-
s.merge(e)
|
502
|
-
else fatal << e
|
503
|
-
end
|
504
|
-
end
|
505
|
-
|
506
|
-
by_task
|
507
|
-
end
|
508
|
-
|
509
|
-
parent_trees = by_task.map do |task, _|
|
510
|
-
[task, task.reverse_generated_subgraph(Roby::TaskStructure::Hierarchy)]
|
511
|
-
end
|
512
|
-
|
513
|
-
# Handle the exception in all tasks that are in no other parent trees
|
514
|
-
new_exceptions = ValueSet.new
|
515
|
-
by_task.each do |task, task_exceptions|
|
516
|
-
if parent_trees.find { |t, tree| t != task && tree.include?(task) }
|
517
|
-
task_exceptions.each { |e| new_exceptions << [e, [task]] }
|
518
|
-
next
|
519
|
-
end
|
520
|
-
|
521
|
-
task_exceptions.each do |e|
|
522
|
-
next if e.handled?
|
523
|
-
handled = task.handle_exception(e)
|
524
|
-
|
525
|
-
if handled
|
526
|
-
Roby::Control.handled_exception(e, task)
|
527
|
-
e.handled = true
|
528
|
-
else
|
529
|
-
# We do not have the framework to handle concurrent repairs
|
530
|
-
# For now, the first handler is the one ...
|
531
|
-
new_exceptions << e
|
532
|
-
e.trace << task
|
533
|
-
end
|
534
|
-
end
|
535
|
-
end
|
536
|
-
|
537
|
-
exceptions = new_exceptions
|
538
|
-
end
|
539
|
-
|
540
|
-
# Call global exception handlers for exceptions in +fatal+. Return the
|
541
|
-
# set of still unhandled exceptions
|
542
|
-
fatal.
|
543
|
-
find_all { |e| !e.handled? }.
|
544
|
-
reject { |e| Roby.handle_exception(e) }
|
545
|
-
end
|
546
|
-
end
|
547
|
-
|
548
|
-
module Roby
|
549
|
-
@exception_handlers = Array.new
|
550
|
-
class << self
|
551
|
-
attr_reader :exception_handlers
|
552
|
-
def each_exception_handler(&iterator); exception_handlers.each(&iterator) end
|
553
|
-
# define_method(:each_exception_handler, &Roby::Propagation.exception_handlers.method(:each))
|
554
|
-
def on_exception(*matchers, &handler)
|
555
|
-
check_arity(handler, 2)
|
556
|
-
exception_handlers.unshift [matchers, handler]
|
557
|
-
end
|
558
|
-
include ExceptionHandlingObject
|
559
|
-
end
|
560
|
-
end
|
561
|
-
|
562
|
-
|