Skip to content

Commit

Permalink
Merge pull request #111 from rock-core/update_dalex_pull_request
Browse files Browse the repository at this point in the history
merge #37
  • Loading branch information
doudou authored Sep 4, 2018
2 parents 471b226 + 5395c34 commit f385de9
Show file tree
Hide file tree
Showing 18 changed files with 238 additions and 111 deletions.
33 changes: 31 additions & 2 deletions lib/roby/actions/models/method_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@ module Actions
module Models
# Action defined by a method on an {Interface}
class MethodAction < Action
class InvalidReturnedType < RuntimeError
def initialize(action_interface_model, method_name,
returned_task, expected_type)
@action_interface_model = action_interface_model
@method_name = method_name
@returned_task = returned_task
@expected_type = expected_type
end

def pretty_print(pp)
pp.text "method '#{@method_name}' of #{@action_interface_model}"
pp.breakable
pp.text "was expected to return a task of type "
@expected_type.pretty_print(pp)
pp.text ","
pp.breakable
pp.text "but returned "
@returned_task.pretty_print(pp)
end
end

# The action interface on which this action is defined
attr_accessor :action_interface_model

Expand All @@ -14,7 +35,7 @@ def initialize(action_interface_model, doc = nil)
def to_s
"#{super} of #{action_interface_model}"
end

def ==(other)
other.kind_of?(self.class) &&
other.action_interface_model == action_interface_model &&
Expand Down Expand Up @@ -43,6 +64,15 @@ def instanciate(plan, arguments = Hash.new)
end
result = action_interface.send(name, arguments).as_plan
end

unless result.fullfills?(returned_task_type)
raise InvalidReturnedType.new(
action_interface_model, name, result, returned_task_type),
"method '#{name}' of #{action_interface_model} was expected "\
"to return a task of type #{returned_task_type}, but "\
"returned #{result}"
end

# Make the planning task inherit the model/argument flags
if planning_task = result.planning_task
if planning_task.respond_to?(:action_model=)
Expand Down Expand Up @@ -87,4 +117,3 @@ def to_s
end
end
end

7 changes: 3 additions & 4 deletions lib/roby/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,6 @@ def created_log_dir?
def log_save_metadata(append: true)
path = File.join(log_dir, 'info.yml')

info = Array.new
current =
if File.file?(path)
YAML.load(File.read(path)) || Array.new
Expand Down Expand Up @@ -1716,7 +1715,7 @@ def require_planners
end

def auto_require_planners
search_path = self.auto_load_search_path
self.auto_load_search_path

prefixes = ['actions']
if backward_compatible_naming?
Expand Down Expand Up @@ -1945,7 +1944,7 @@ def run(thread_priority: 0, &block)
def join
@thread.join

rescue Exception => e
rescue Exception
if @thread.alive? && execution_engine.running?
if execution_engine.forced_exit?
raise
Expand All @@ -1967,7 +1966,7 @@ def running?
#
# Simply execs the same command line
def restart!
Kernel.exec *@restart_cmdline
Kernel.exec(*@restart_cmdline)
end

# Indicates to whomever is managing this app that {#restart} should be
Expand Down
2 changes: 1 addition & 1 deletion lib/roby/cli/gen/roby_app/config/robots/robot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#
# Add use statements here, as e.g.
#
# use <%= Roby.app.module_name %>::Actions::MyActionInterface
# use_library <%= Roby.app.module_name %>::Actions::MyActionInterface
#
# or, if you're using syskit
#
Expand Down
12 changes: 7 additions & 5 deletions lib/roby/coordination/models/action_state_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ module Models
# stand = state move(speed: 0)
# # This monitor triggers each time the system moves more than
# # 0.1 meters
# d_monitor = task monitor_movement_threshold(d: 0.1)
# d_monitor = task monitor_movement_threshold(d: 0.1)
# # This monitor triggers after 20 seconds
# t_monitor = task monitor_time_threshold(t: 20)
# t_monitor = task monitor_time_threshold(t: 20)
# # Make the distance monitor run in the move state
# move.depends_on d_monitor
# # Make the time monitor run in the stand state
Expand Down Expand Up @@ -89,6 +89,10 @@ def parse_names
# Declares the starting state
def start(state)
parse_names
if @starting_state
raise ArgumentError, "this state machine already has a starting "\
"state, use #depends_on to run more than one task at startup"
end
@starting_state = validate_task(state)
end

Expand Down Expand Up @@ -123,7 +127,7 @@ def capture(state, event = nil, &block)
if block
lambda(&block)
else
lambda { |event| event.context.first }
lambda { |ev| ev.context.first }
end

capture = Capture.new(filter)
Expand Down Expand Up @@ -220,5 +224,3 @@ def to_s
end
end
end


5 changes: 4 additions & 1 deletion lib/roby/coordination/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ def execute(script)
event.resolve.emit
script.jump_to(timeout_stop)
else
raise TimedOut.new(script.root_task, script.current_instruction), "#{script.current_instruction} timed out"
e = TimedOut.new(
script.root_task, script.current_instruction).
exception("#{script.current_instruction} timed out")
script.root_task.execution_engine.add_error(e)
end
end
end
Expand Down
9 changes: 3 additions & 6 deletions lib/roby/coordination/task_script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def resolve_event(event)
raise ArgumentError, "#{model.root} has no event called #{symbol}"
end
end
script_task, model_task = resolve_task(event.task)
_, model_task = resolve_task(event.task)
model_event = model_task.find_event(event.symbol)
script_event = instance_for(model_event)
return script_event, model_event
Expand Down Expand Up @@ -191,7 +191,7 @@ def transition!
# emit an event (and quit the block)
#
# @param [Hash] options
# @option options [Event] :event (nil) if set, the given event will
# @option options [Event] :emit (nil) if set, the given event will
# be emitted when the timeout is reached. Otherwise, a
# Script::TimedOut exception is generated with the script's
# supporting task as origin
Expand All @@ -207,7 +207,7 @@ def timeout(seconds, options = Hash.new, &block)
def timeout_start(seconds, options = Hash.new)
options, timeout_options = Kernel.filter_options options, emit: nil
if event = options[:emit]
script_event, model_event = resolve_event(event)
_, model_event = resolve_event(event)
end
model.timeout_start(seconds, timeout_options.merge(emit: model_event))
end
Expand Down Expand Up @@ -288,6 +288,3 @@ def transition!
end
end
end



15 changes: 7 additions & 8 deletions lib/roby/execution_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,6 @@ def gather_propagation(initial_set = Hash.new)
@propagation_sources = nil
@propagation_step_id = 0

before = @propagation
propagation_context([]) do
yield
end
Expand Down Expand Up @@ -855,7 +854,7 @@ def error_handling_phase(events_errors)

# Compute the set of unhandled fatal exceptions
def compute_kill_tasks_for_unhandled_fatal_errors(fatal_errors)
kill_tasks = fatal_errors.inject(Set.new) do |tasks, (exception, affected_tasks)|
kill_tasks = fatal_errors.inject(Set.new) do |tasks, (_exception, affected_tasks)|
tasks.merge(affected_tasks)
end
# Tasks might have been finalized during exception handling, filter
Expand Down Expand Up @@ -1052,7 +1051,7 @@ def prepare_propagation(target, is_forward, info)
# the forwardings and signals that the propagation of the considered event
# have added.
def event_propagation_step(current_step, propagation_info)
signalled, step_id, forward_info, call_info = next_event(current_step)
signalled, _step_id, forward_info, call_info = next_event(current_step)

next_step = nil
if !call_info.empty?
Expand Down Expand Up @@ -2008,15 +2007,15 @@ def self.call_every(plan) # :nodoc:
# Check if the nearest timepoint is the beginning of
# this cycle or of the next cycle
if !last_call || (duration - (now - last_call)) < length / 2
if !handler.call(engine, engine.plan)
unless handler.call(engine, engine.plan)
next
end

next if handler.once?
next if handler.disposed?
last_call = now
end
unless handler.disposed?
[handler, last_call, duration]
end
[handler, last_call, duration]
end.compact!
end

Expand Down Expand Up @@ -2440,7 +2439,7 @@ def execute(catch: [], type: :external_events)
when :ret
return value
when :throw
throw *value
throw(*value)
else
raise value
end
Expand Down
10 changes: 7 additions & 3 deletions lib/roby/interface/rest/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ class Server
# @param [Integer] port the port the server should bind to if it
# is a TCP server. Set to zero to auto-allocate. Ignored if 'host'
# is the path to a UNIX socket.
def initialize(app, host: '0.0.0.0', port: Roby::Interface::DEFAULT_REST_PORT,
api: REST::API)
def initialize(app,
host: '0.0.0.0',
port: Roby::Interface::DEFAULT_REST_PORT,
api: REST::API, **thin_options)

@app = app
@host = host
@interface = Interface.new(app)
Expand All @@ -42,7 +45,8 @@ def initialize(app, host: '0.0.0.0', port: Roby::Interface::DEFAULT_REST_PORT,
run api
end
end
@server = Thin::Server.new(host, port, rack_app, signals: false)
@server = Thin::Server.new(host, port, rack_app,
signals: false, **thin_options)
@server.silent = true
if @server.backend.respond_to?(:port)
@original_port = port
Expand Down
21 changes: 10 additions & 11 deletions lib/roby/plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Plan < DistributedObject
extend Logger::Hierarchy
extend Logger::Forward
include DRoby::EventLogging

# The Peer ID of the local owner (i.e. of the local process / execution
# engine)
attr_accessor :local_owner
Expand Down Expand Up @@ -219,7 +219,7 @@ def merge_base(plan)
task_index.merge(plan.task_index)
task_events.merge(plan.task_events)
end

def merge_relation_graphs(plan)
# Now merge the relation graphs
#
Expand Down Expand Up @@ -607,7 +607,7 @@ def add_permanent_event(event)

# True if the given event is registered as a permanent event on self
def permanent_event?(generator)
@permanent_events.include?(generator)
@permanent_events.include?(generator)
end

# Removes a task from the set of permanent tasks
Expand Down Expand Up @@ -677,7 +677,7 @@ def handle_force_replace(from, to)
elsif to.plan != self
raise ArgumentError, "trying to replace #{to} but its plan is #{to.plan}, expected #{self}"
elsif from == to
return
return
end

# Swap the subplans of +from+ and +to+
Expand Down Expand Up @@ -758,7 +758,7 @@ def exclude_tasks(tasks)
@tasks.merge(tasks)
self
end

# Exclude a single task
#
# @param [Task] task the task to be excluded
Expand All @@ -767,7 +767,7 @@ def exclude_task(task)
@tasks << task
self
end

# Tests whether a task is to be excluded
#
# @param [Task] task
Expand Down Expand Up @@ -1378,7 +1378,7 @@ def each_task
return enum_for(__method__) if !block_given?
@tasks.each { |t| yield(t) }
end

# Returns +object+ if object is a plan object from this plan, or if
# it has no plan yet (in which case it is added to the plan first).
# Otherwise, raises ArgumentError.
Expand Down Expand Up @@ -1592,15 +1592,15 @@ def replan(task)
return task.create_fresh_copy
end

planner = replan(old_planner = task.planning_task)
planner = replan(task.planning_task)
planned = task.create_fresh_copy
planned.abstract = true
planned.planned_by planner
replace(task, planned)
planned
end


# The set of blocks that should be called to check the structure of the
# plan.
#
Expand Down Expand Up @@ -1635,7 +1635,7 @@ def self.check_failed_missions(plan)
result
end
structure_checks << method(:check_failed_missions)

# @api private
#
# Normalize the value returned by one of the {#structure_checks}, by
Expand Down Expand Up @@ -1909,4 +1909,3 @@ def each_object_in_transaction_stack(object)
end
end
end

Loading

0 comments on commit f385de9

Please sign in to comment.