Module: Roby
- Included in:
- Test
- Defined in:
- lib/roby.rb,
lib/roby.rb,
lib/roby/app.rb,
lib/roby/plan.rb,
lib/roby/task.rb,
lib/roby/yard.rb,
lib/roby/droby.rb,
lib/roby/event.rb,
lib/roby/hooks.rb,
lib/roby/actions.rb,
lib/roby/cli/log.rb,
lib/roby/promise.rb,
lib/roby/queries.rb,
lib/roby/support.rb,
lib/roby/version.rb,
lib/roby/app/base.rb,
lib/roby/app/rake.rb,
lib/roby/cli/main.rb,
lib/roby/test/dsl.rb,
lib/roby/app/debug.rb,
lib/roby/interface.rb,
lib/roby/relations.rb,
lib/roby/test/self.rb,
lib/roby/test/spec.rb,
lib/roby/exceptions.rb,
lib/roby/gui/styles.rb,
lib/roby/singletons.rb,
lib/roby/state/task.rb,
lib/roby/task_event.rb,
lib/roby/tasks/null.rb,
lib/roby/test/error.rb,
lib/roby/test/tools.rb,
lib/roby/app/scripts.rb,
lib/roby/app/vagrant.rb,
lib/roby/cli/display.rb,
lib/roby/models/task.rb,
lib/roby/plan_object.rb,
lib/roby/queries/any.rb,
lib/roby/test/common.rb,
lib/roby/transaction.rb,
lib/roby/actions/task.rb,
lib/roby/cli/gen_main.rb,
lib/roby/coordination.rb,
lib/roby/gui/stepping.rb,
lib/roby/or_generator.rb,
lib/roby/plan_service.rb,
lib/roby/queries/none.rb,
lib/roby/state/events.rb,
lib/roby/task_service.rb,
lib/roby/tasks/simple.rb,
lib/roby/tasks/thread.rb,
lib/roby/and_generator.rb,
lib/roby/droby/logfile.rb,
lib/roby/droby/marshal.rb,
lib/roby/droby/peer_id.rb,
lib/roby/interface/job.rb,
lib/roby/interface/tcp.rb,
lib/roby/queries/index.rb,
lib/roby/queries/query.rb,
lib/roby/tasks/timeout.rb,
lib/roby/tasks/virtual.rb,
lib/roby/template_plan.rb,
lib/roby/test/testcase.rb,
lib/roby/actions/action.rb,
lib/roby/cli/exceptions.rb,
lib/roby/droby/droby_id.rb,
lib/roby/task_arguments.rb,
lib/roby/test/assertion.rb,
lib/roby/actions/library.rb,
lib/roby/app/robot_names.rb,
lib/roby/app/test_server.rb,
lib/roby/cli/gen/helpers.rb,
lib/roby/event_generator.rb,
lib/roby/executable_plan.rb,
lib/roby/gui/log_display.rb,
lib/roby/interface/async.rb,
lib/roby/relations/graph.rb,
lib/roby/relations/space.rb,
lib/roby/schedulers/null.rb,
lib/roby/standard_errors.rb,
lib/roby/test/assertions.rb,
lib/roby/test/tasks/goto.rb,
lib/roby/until_generator.rb,
lib/roby/app/plugins/rake.rb,
lib/roby/app/robot_config.rb,
lib/roby/decision_control.rb,
lib/roby/droby/exceptions.rb,
lib/roby/droby/timepoints.rb,
lib/roby/droby/v5/builtin.rb,
lib/roby/droby/v5/peer_id.rb,
lib/roby/execution_engine.rb,
lib/roby/filter_generator.rb,
lib/roby/interface/client.rb,
lib/roby/interface/server.rb,
lib/roby/models/arguments.rb,
lib/roby/schedulers/basic.rb,
lib/roby/schedulers/state.rb,
lib/roby/state/conf_model.rb,
lib/roby/state/goal_model.rb,
lib/roby/actions/interface.rb,
lib/roby/app/test_reporter.rb,
lib/roby/coordination/base.rb,
lib/roby/coordination/task.rb,
lib/roby/droby/v5/droby_id.rb,
lib/roby/event_constraints.rb,
lib/roby/gui/task_state_at.rb,
lib/roby/interface/command.rb,
lib/roby/models/task_event.rb,
lib/roby/state/open_struct.rb,
lib/roby/state/state_model.rb,
lib/roby/test/run_planners.rb,
lib/roby/app/cucumber/world.rb,
lib/roby/coordination/child.rb,
lib/roby/coordination/event.rb,
lib/roby/distributed_object.rb,
lib/roby/droby/event_logger.rb,
lib/roby/droby/identifiable.rb,
lib/roby/droby/marshallable.rb,
lib/roby/droby/rebuilt_plan.rb,
lib/roby/gui/chronicle_view.rb,
lib/roby/gui/exception_view.rb,
lib/roby/gui/relations_view.rb,
lib/roby/gui/scheduler_view.rb,
lib/roby/interface/rest/api.rb,
lib/roby/models/plan_object.rb,
lib/roby/queries/op_matcher.rb,
lib/roby/queries/or_matcher.rb,
lib/roby/coordination/script.rb,
lib/roby/droby/event_logging.rb,
lib/roby/droby/logfile/index.rb,
lib/roby/droby/v5/droby_dump.rb,
lib/roby/gui/plan_dot_layout.rb,
lib/roby/interface/async/log.rb,
lib/roby/interface/interface.rb,
lib/roby/models/task_service.rb,
lib/roby/queries/and_matcher.rb,
lib/roby/queries/not_matcher.rb,
lib/roby/schedulers/temporal.rb,
lib/roby/test/aruba_minitest.rb,
lib/roby/test/event_reporter.rb,
lib/roby/test/teardown_plans.rb,
lib/roby/app/cucumber/helpers.rb,
lib/roby/coordination/actions.rb,
lib/roby/droby/logfile/client.rb,
lib/roby/droby/logfile/reader.rb,
lib/roby/droby/logfile/server.rb,
lib/roby/droby/logfile/writer.rb,
lib/roby/droby/object_manager.rb,
lib/roby/droby/plan_rebuilder.rb,
lib/roby/droby/timepoints_ctf.rb,
lib/roby/droby/v5/droby_class.rb,
lib/roby/droby/v5/droby_model.rb,
lib/roby/gui/chronicle_widget.rb,
lib/roby/gui/model_views/task.rb,
lib/roby/gui/object_info_view.rb,
lib/roby/interface/exceptions.rb,
lib/roby/queries/matcher_base.rb,
lib/roby/queries/task_matcher.rb,
lib/roby/schedulers/reporting.rb,
lib/roby/task_event_generator.rb,
lib/roby/transaction/proxying.rb,
lib/roby/actions/models/action.rb,
lib/roby/coordination/calculus.rb,
lib/roby/droby/remote_droby_id.rb,
lib/roby/interface/rest/server.rb,
lib/roby/test/expect_execution.rb,
lib/roby/test/minitest_helpers.rb,
lib/roby/test/roby_app_helpers.rb,
lib/roby/test/tasks/empty_task.rb,
lib/roby/actions/models/library.rb,
lib/roby/coordination/task_base.rb,
lib/roby/event_structure/signal.rb,
lib/roby/interface/rest/helpers.rb,
lib/roby/interface/shell_client.rb,
lib/roby/relations/models/graph.rb,
lib/roby/tasks/external_process.rb,
lib/roby/transaction/task_proxy.rb,
lib/roby/app/cucumber/controller.rb,
lib/roby/droby/null_event_logger.rb,
lib/roby/droby/v5/droby_constant.rb,
lib/roby/interface/droby_channel.rb,
lib/roby/state/open_struct_model.rb,
lib/roby/actions/models/interface.rb,
lib/roby/coordination/models/base.rb,
lib/roby/coordination/models/root.rb,
lib/roby/coordination/models/task.rb,
lib/roby/coordination/task_script.rb,
lib/roby/droby/v5/remote_droby_id.rb,
lib/roby/task_structure/conflicts.rb,
lib/roby/coordination/models/child.rb,
lib/roby/coordination/models/event.rb,
lib/roby/gui/plan_rebuilder_widget.rb,
lib/roby/interface/async/interface.rb,
lib/roby/interface/command_library.rb,
lib/roby/task_structure/dependency.rb,
lib/roby/task_structure/planned_by.rb,
lib/roby/coordination/action_script.rb,
lib/roby/coordination/fault_handler.rb,
lib/roby/coordination/models/script.rb,
lib/roby/event_structure/forwarding.rb,
lib/roby/event_structure/precedence.rb,
lib/roby/interface/command_argument.rb,
lib/roby/interface/shell_subcommand.rb,
lib/roby/queries/code_error_matcher.rb,
lib/roby/task_structure/executed_by.rb,
lib/roby/cli/log/flamegraph_renderer.rb,
lib/roby/coordination/models/actions.rb,
lib/roby/coordination/models/capture.rb,
lib/roby/event_structure/causal_link.rb,
lib/roby/interface/async/job_monitor.rb,
lib/roby/interface/subcommand_client.rb,
lib/roby/queries/plan_object_matcher.rb,
lib/roby/test/execution_expectations.rb,
lib/roby/test/validate_state_machine.rb,
lib/roby/actions/models/method_action.rb,
lib/roby/coordination/models/variable.rb,
lib/roby/interface/async/ui_connector.rb,
lib/roby/relations/fork_merge_visitor.rb,
lib/roby/actions/models/interface_base.rb,
lib/roby/app/autotest_console_reporter.rb,
lib/roby/coordination/models/arguments.rb,
lib/roby/relations/task_relation_graph.rb,
lib/roby/transaction/plan_object_proxy.rb,
lib/roby/coordination/models/exceptions.rb,
lib/roby/gui/task_display_configuration.rb,
lib/roby/interface/async/action_monitor.rb,
lib/roby/relations/event_relation_graph.rb,
lib/roby/transaction/plan_service_proxy.rb,
lib/roby/coordination/script_instruction.rb,
lib/roby/coordination/task_state_machine.rb,
lib/roby/queries/event_generator_matcher.rb,
lib/roby/queries/localized_error_matcher.rb,
lib/roby/coordination/fault_handling_task.rb,
lib/roby/gui/model_views/action_interface.rb,
lib/roby/interface/async/new_job_listener.rb,
lib/roby/coordination/action_state_machine.rb,
lib/roby/coordination/fault_response_table.rb,
lib/roby/coordination/models/action_script.rb,
lib/roby/coordination/models/fault_handler.rb,
lib/roby/transaction/event_generator_proxy.rb,
lib/roby/actions/models/coordination_action.rb,
lib/roby/gui/relations_view/relations_canvas.rb,
lib/roby/queries/execution_exception_matcher.rb,
lib/roby/relations/directed_relation_support.rb,
lib/roby/coordination/models/task_from_action.rb,
lib/roby/event_structure/temporal_constraints.rb,
lib/roby/queries/task_event_generator_matcher.rb,
lib/roby/relations/models/task_relation_graph.rb,
lib/roby/coordination/models/task_from_as_plan.rb,
lib/roby/coordination/models/task_from_variable.rb,
lib/roby/transaction/task_event_generator_proxy.rb,
lib/roby/coordination/models/action_state_machine.rb,
lib/roby/coordination/models/fault_response_table.rb,
lib/roby/coordination/models/task_with_dependencies.rb,
lib/roby/relations/models/directed_relation_support.rb,
lib/roby/relations/bidirectional_directed_adjacency_graph.rb,
lib/roby/coordination/models/task_from_instanciation_object.rb,
lib/roby/droby/enable.rb
Overview
The main namespace for the Roby library. The namespace is divided as follows:
- Roby
-
core namespace for the Roby kernel
- Roby::Actions
-
basic tools for plan generation
- Roby::Transactions
-
implementation of transactions. Transactions represent a
change in the main plan, and can be distributed among different plan managers.
- Roby::EventStructure
-
main namespace for event relations. The methods listed
in the documentation of EventStructure are actually methods of Roby::EventGenerator
- Roby::TaskStructure
-
main namespace for task relations. The methods listed in
the documentation of TaskStructure are actually methods of Roby::Task
Defined Under Namespace
Modules: Actions, App, CLI, Coordination, DRoby, EventConstraints, EventStructure, ExceptionHandlingObject, GUI, Hooks, Interface, Models, Pos, Queries, Rake, Relations, Schedulers, TaskStateHelper, TaskStructure, Tasks, Test, Tools, UserExceptionWrapper, YARD Classes: Aborting, ActionStateTransitionFailed, AndGenerator, Application, BacktraceFormatter, ChildFailedError, CodeError, CommandFailed, CommandRejected, ConfModel, ConfigError, Control, DecisionControl, DefaultArgument, DelayedArgumentFromObject, DelayedArgumentFromState, DeltaEvent, DistributedObject, EmissionFailed, EmissionRejected, Event, EventCanceled, EventGenerator, EventHandlerError, EventNotControlable, EventNotExecutable, EventPreconditionFailed, ExceptionBase, ExecutablePlan, ExecutionEngine, ExecutionException, ExecutionQuitError, FailedExceptionHandler, FilterGenerator, FinalizedPlanObject, GoalModel, GoalSpace, GoalVariableModel, InternalError, InvalidReplace, InvalidTransaction, LocalizedError, MissionFailedError, ModelViolation, NoSuchChild, NotMarshallable, OpenStruct, OpenStructModel, OrGenerator, OwnershipError, PermanentTaskError, PhaseMismatch, Plan, PlanObject, PlanService, PlanningFailedError, PosDeltaEvent, Promise, PromiseInFinishedTask, PropagationError, RelationFailedError, RemotePeerMismatch, ReusingGarbage, StateConditionEvent, StateDataSourceField, StateEvent, StateField, StateLastValueField, StateMachineDefinitionContext, StateModel, StateSpace, StateVariableModel, SynchronousEventProcessingMultipleErrors, Task, TaskArguments, TaskEmergencyTermination, TaskEvent, TaskEventGenerator, TaskEventNotExecutable, TaskNotExecutable, TaskStateMachine, TemplatePlan, ThreadMismatch, TimeDeltaEvent, ToplevelTaskError, Transaction, UnreachableEvent, UntilGenerator, UserError, YawDeltaEvent
Constant Summary collapse
- BIN_DIR =
File.(File.join("..", "bin"), __dir__)
- RX_IN_FRAMEWORK =
Regular expression that matches backtrace paths that are within the Roby framework
/^((?:\s*\(druby:\/\/.+\)\s*)?#{Regexp.quote(ROBY_LIB_DIR)}\/)|^\(eval\)|^\/usr\/lib\/ruby/- RX_IN_METARUBY =
/^(?:\s*\(druby:\/\/.+\)\s*)?#{Regexp.quote(MetaRuby::LIB_DIR)}\//- RX_IN_UTILRB =
/^(?:\s*\(druby:\/\/.+\)\s*)?#{Regexp.quote(Utilrb::LIB_DIR)}\//- RX_REQUIRE =
Regular expression that matches backtrace paths that are require lines
/in `(gem_original_)?require'$/- VERSION =
"3.0.0"- ROBY_LIB_DIR =
File.( File.join(File.dirname(__FILE__), '..') )
- ROBY_ROOT_DIR =
File.( File.join(ROBY_LIB_DIR, '..') )
- SelfTest =
Test::Self
- LOG_SYMBOLIC_TO_NUMERIC =
- State =
The main state object
Roby.state
- Conf =
The main configuration object
Roby.conf
- NullTask =
For backward-compatibility only
Tasks::Null
- TaskService =
Models::TaskServiceModel.new
- VirtualTask =
For backward-compatibility
Tasks::Virtual
Class Attribute Summary collapse
-
.colorizer ⇒ Object
readonly
Returns the value of attribute colorizer.
-
.conf ⇒ Object
readonly
The one and only ConfModel object.
-
.deprecation_warnings_are_errors ⇒ Object
Returns the value of attribute deprecation_warnings_are_errors.
-
.enable_deprecation_warnings ⇒ Object
Returns the value of attribute enable_deprecation_warnings.
-
.state ⇒ Object
readonly
The one and only StateSpace object.
Class Method Summary collapse
-
.app ⇒ Object
The one and only Application object.
- .color(string, *colors) ⇒ Object
-
.control(object) ⇒ Object
Sets the control / policy object.
- .disable_colors ⇒ Object
- .display_exception(io = STDOUT, e = nil, filter_backtraces = nil) ⇒ Object
- .do_display_exception(io, e) ⇒ Object
- .do_display_exception_formatted(io, e) ⇒ Object
- .do_display_exception_raw(io, e) ⇒ Object
-
.each_cycle(&block) ⇒ Object
Make the main engine call
blockduring each propagation step. - .enable_colors ⇒ Object
- .enable_colors_if_available ⇒ Object
-
.engine ⇒ Object
deprecated
Deprecated.
use Roby.execution_engine instead
- .error_deprecated(msg, caller_depth = 1) ⇒ Object
-
.every(duration, options = Hash.new, &block) ⇒ Object
Install a periodic handler on the main engine.
-
.execute ⇒ Object
Execute the given block during the event propagation step of the main engine.
-
.execution_engine ⇒ ExecutionEngine
The main execution engine.
- .filter_backtrace(original_backtrace = nil, force: false, display_full_framework_backtraces: false) ⇒ Object
- .flatten_exception(e) ⇒ Object
- .format_backtrace(e, filter: Roby.app.filter_backtraces?) ⇒ Object
- .format_exception(exception, with_original_exceptions: true) ⇒ Object
- .format_one_exception(exception) ⇒ Object
- .format_time(time, format = 'hms') ⇒ Object
-
.from(object) ⇒ Object
Use to specify that a task argument should be initialized from an object’s attribute.
-
.from_conf ⇒ Object
Use to specify that a task argument should be initialized from a value in the Conf object.
-
.from_state(state_object = State) ⇒ Object
Use to specify that a task argument should be initialized from a value in the State.
-
.inside_control? ⇒ Boolean
True if the current thread is the execution thread of the main engine.
- .log_backtrace(e, logger, level, filter: Roby.app.filter_backtraces?) ⇒ Object
- .log_error(e, logger, level, with_backtrace: true) ⇒ Object
- .log_exception(e, logger, level, with_original_exceptions: true) ⇒ Object
- .log_exception_with_backtrace(e, logger, level, filter: Roby.app.filter_backtraces?, with_original_exceptions: true) ⇒ Object
- .log_level_enabled?(logger, level) ⇒ Boolean
- .log_pp(obj, logger, level) ⇒ Object
-
.on_exception(matcher, &handler) ⇒ Object
Defines a global exception handler on the main plan.
-
.once ⇒ Object
Execute the given block in the main plan’s propagation context, but don’t wait for its completion like Roby.execute does.
-
.outside_control? ⇒ Boolean
True if the current thread is not the execution thread of the main engine.
-
.plan ⇒ Plan
The main plan.
-
.poll_state_events(plan) ⇒ Object
Registered on the execution engines to call the #poll method of state events.
- .pretty_print_backtrace(pp, backtrace, **options) ⇒ Object
-
.RelationSpace(klass) ⇒ Object
Creates a new relation space which applies on
klass. -
.scheduler ⇒ Object
The main scheduler.
-
.scheduler=(scheduler) ⇒ Object
Sets the main scheduler.
-
.wait_one_cycle ⇒ Object
Blocks until the main engine has executed at least one cycle.
-
.wait_until(ev, &block) ⇒ Object
Stops the current thread until the given even is emitted.
- .warn_deprecated(msg, caller_depth = 1) ⇒ Object
Class Attribute Details
.colorizer ⇒ Object (readonly)
Returns the value of attribute colorizer.
11 12 13 |
# File 'lib/roby/exceptions.rb', line 11 def colorizer @colorizer end |
.conf ⇒ Object (readonly)
The one and only ConfModel object
15 16 17 |
# File 'lib/roby/singletons.rb', line 15 def conf @conf end |
.deprecation_warnings_are_errors ⇒ Object
Returns the value of attribute deprecation_warnings_are_errors.
115 116 117 |
# File 'lib/roby/support.rb', line 115 def deprecation_warnings_are_errors @deprecation_warnings_are_errors end |
.enable_deprecation_warnings ⇒ Object
Returns the value of attribute enable_deprecation_warnings.
114 115 116 |
# File 'lib/roby/support.rb', line 114 def enable_deprecation_warnings @enable_deprecation_warnings end |
.state ⇒ Object (readonly)
The one and only StateSpace object
12 13 14 |
# File 'lib/roby/singletons.rb', line 12 def state @state end |
Class Method Details
.app ⇒ Object
The one and only Application object
7 8 9 |
# File 'lib/roby/singletons.rb', line 7 def app @app ||= Application.new end |
.color(string, *colors) ⇒ Object
14 15 16 |
# File 'lib/roby/exceptions.rb', line 14 def self.color(string, *colors) colorizer.decorate(string, *colors) end |
.control(object) ⇒ Object
Sets the control / policy object
This is the object that defines the core execution policies (e.g. what to do if the dependency of a non-running task stops). See DecisionControl
54 55 56 |
# File 'lib/roby/singletons.rb', line 54 def control app.plan.execution_engine.control end |
.disable_colors ⇒ Object
18 19 20 |
# File 'lib/roby/exceptions.rb', line 18 def self.disable_colors @colorizer = Pastel.new(enabled: false) end |
.display_exception(io = STDOUT, e = nil, filter_backtraces = nil) ⇒ Object
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 |
# File 'lib/roby/exceptions.rb', line 493 def self.display_exception(io = STDOUT, e = nil, filter_backtraces = nil) if !filter_backtraces.nil? old_filter_backtraces = Roby.app.filter_backtraces? Roby.app.filter_backtraces = filter_backtraces end if !block_given? if !e raise ArgumentError, "expected an exception object as no block was given" end do_display_exception(io, e) e else yield false end rescue Interrupt, SystemExit raise rescue Exception => e if e.user_error? io.print color(e., :bold, :red) else do_display_exception(io, e) end e ensure if !filter_backtraces.nil? Roby.app.filter_backtraces = old_filter_backtraces end end |
.do_display_exception(io, e) ⇒ Object
439 440 441 442 443 444 445 446 447 448 449 450 451 |
# File 'lib/roby/exceptions.rb', line 439 def self.do_display_exception(io, e) if colorizer.enabled? do_display_exception_formatted(io, e) else do_display_exception_raw(io, e) end if e.respond_to?(:original_exceptions) e.original_exceptions.each do |original_e| do_display_exception(io, original_e) end end end |
.do_display_exception_formatted(io, e) ⇒ Object
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 |
# File 'lib/roby/exceptions.rb', line 470 def self.do_display_exception_formatted(io, e) first_line = true io.puts "" format_exception(e).each do |line| if first_line io.print color("= ", :bold, :red) io.puts color(line, :bold, :red) first_line = false else io.print color("| ", :bold, :red) io.puts line end end io.puts color("= Backtrace", :bold, :red) format_exception(BacktraceFormatter.new(e)).each do |line| io.print color("| ", :bold, :red) io.puts line end io.puts color("= ", :bold, :red) true end |
.do_display_exception_raw(io, e) ⇒ Object
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
# File 'lib/roby/exceptions.rb', line 453 def self.do_display_exception_raw(io, e) first_line = true io.puts format_exception(e).each do |line| if first_line io.puts line first_line = false else io.puts " #{line}" end end format_exception(BacktraceFormatter.new(e)).each do |line| io.puts line end true end |
.each_cycle(&block) ⇒ Object
Make the main engine call block during each propagation step. See ExecutionEngine#each_cycle
2617 |
# File 'lib/roby/execution_engine.rb', line 2617 def self.each_cycle(&block); execution_engine.each_cycle(&block) end |
.enable_colors ⇒ Object
26 27 28 |
# File 'lib/roby/exceptions.rb', line 26 def self.enable_colors @colorizer = Pastel.new(enabled: true) end |
.enable_colors_if_available ⇒ Object
22 23 24 |
# File 'lib/roby/exceptions.rb', line 22 def self.enable_colors_if_available @colorizer = Pastel.new end |
.engine ⇒ Object
use execution_engine instead
68 69 70 71 |
# File 'lib/roby/singletons.rb', line 68 def engine Roby.warn_deprecated "Roby.engine is deprecated, use Roby.execution_engine instead" app.execution_engine end |
.error_deprecated(msg, caller_depth = 1) ⇒ Object
128 129 130 131 |
# File 'lib/roby/support.rb', line 128 def self.error_deprecated(msg, caller_depth = 1) Roby.fatal "Deprecation Error: #{msg} at #{caller[1, caller_depth].join("\n")}" raise NotImplementedError end |
.every(duration, options = Hash.new, &block) ⇒ Object
Install a periodic handler on the main engine
2620 |
# File 'lib/roby/execution_engine.rb', line 2620 def self.every(duration, = Hash.new, &block); execution_engine.every(duration, , &block) end |
.execute ⇒ Object
Execute the given block during the event propagation step of the main engine. See ExecutionEngine#execute
2634 2635 2636 2637 2638 |
# File 'lib/roby/execution_engine.rb', line 2634 def self.execute execution_engine.execute do yield end end |
.execution_engine ⇒ ExecutionEngine
The main execution engine
It is always the same as Roby.plan.execution_engine
Note that it is nil until the Roby application is configured
31 32 33 |
# File 'lib/roby/singletons.rb', line 31 def execution_engine app.execution_engine end |
.filter_backtrace(original_backtrace = nil, force: false, display_full_framework_backtraces: false) ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/roby/exceptions.rb', line 208 def self.filter_backtrace(original_backtrace = nil, force: false, display_full_framework_backtraces: false) filter_out = Roby.app.filter_out_patterns if !original_backtrace && block_given? begin return yield rescue Exception => e filtered = filter_backtrace( e.backtrace, force: force, display_full_framework_backtraces: display_full_framework_backtraces) raise e, e., filtered end end if (Roby.app.filter_backtraces? || force) && original_backtrace app_dir = Roby.app.app_dir original_backtrace = original_backtrace.dup # First, read out the "bottom" of the backtrace: search for the # first backtrace line that is within the framework backtrace_bottom = [] while !original_backtrace.empty? && !filter_out.any? { |rx| rx =~ original_backtrace.last } backtrace_bottom.unshift original_backtrace.pop end got_user_line = false backtrace = original_backtrace.enum_for(:each_with_index).map do |line, idx| case line when /in `poll_handler'$/ got_user_line = true line.gsub(/:in.*/, ':in the polling handler') when /in `event_command_(\w+)'$/ got_user_line = true line.gsub(/:in.*/, ":in command for '#{$1}'") when /in `event_handler_(\w+)_(?:[a-f0-9]+)'$/ got_user_line = true line.gsub(/:in.*/, ":in event handler for '#{$1}'") else if original_backtrace.size > idx + 4 && original_backtrace[idx + 1] =~ /in `call'$/ && original_backtrace[idx + 2] =~ /in `call_handlers'$/ && original_backtrace[idx + 3] =~ /`each'$/ && original_backtrace[idx + 4] =~ /`each_handler'$/ got_user_line = true line.gsub(/:in /, ":in event handler, ") else is_user = !filter_out.any? { |rx| rx =~ line } got_user_line ||= is_user if !got_user_line || is_user case line when /^\(eval\):\d+:in `each(?:_handler)?'/ else line end end end end end backtrace.compact! if app_dir backtrace = backtrace.map do |line| line.gsub(/^#{app_dir}\/?/, './') end end backtrace.concat backtrace_bottom if original_backtrace.size == backtrace.size && !display_full_framework_backtraces # The backtrace is only within the framework, make it empty backtrace = [] end end backtrace || original_backtrace || [] end |
.flatten_exception(e) ⇒ Object
526 527 528 529 530 531 532 533 534 |
# File 'lib/roby/exceptions.rb', line 526 def self.flatten_exception(e) result = [e].to_set if e.respond_to?(:original_exceptions) e.original_exceptions.each do |orig_e| result.merge(flatten_exception(orig_e)) end end result end |
.format_backtrace(e, filter: Roby.app.filter_backtraces?) ⇒ Object
379 380 381 382 383 384 385 386 |
# File 'lib/roby/exceptions.rb', line 379 def self.format_backtrace(e, filter: Roby.app.filter_backtraces?) backtrace = e.backtrace if filter backtrace = filter_backtrace(backtrace) end format_exception(BacktraceFormatter.new(e, backtrace)) end |
.format_exception(exception, with_original_exceptions: true) ⇒ Object
314 315 316 317 318 319 320 321 322 |
# File 'lib/roby/exceptions.rb', line 314 def self.format_exception(exception, with_original_exceptions: true) = format_one_exception(exception) if with_original_exceptions && exception.respond_to?(:original_exceptions) exception.original_exceptions.each do |original_e| .concat(format_exception(original_e, with_original_exceptions: true)) end end end |
.format_one_exception(exception) ⇒ Object
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/roby/exceptions.rb', line 296 def self.format_one_exception(exception) = begin PP.pp(exception, "") rescue Exception => formatting_error begin "error formatting exception\n" + exception. + "\nplease report the formatting error: \n" + formatting_error. rescue Exception => formatting_error "\nerror formatting exception\n" + formatting_error. end end .split("\n") end |
.format_time(time, format = 'hms') ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/roby/support.rb', line 101 def self.format_time(time, format = 'hms') if format == 'sec' time.to_f.to_s elsif format == 'hms' "#{time.strftime('%H:%M:%S.%3N')}" else "#{time.strftime(format)}" end end |
.from(object) ⇒ Object
Use to specify that a task argument should be initialized from an object’s attribute.
For instance,
task.new(goal: Roby.from(State).pose.position))
will set the task’s ‘goal’ argument from State.pose.position *at the time the task is started*
It can also be used as default argument values (in which case Task.from can be used instead of Roby.from):
class MyTask < Roby::Task
argument :goal, default: from(State).pose.position
end
If the provided object is nil, the receiver will be the task itself.
402 403 404 |
# File 'lib/roby/task_arguments.rb', line 402 def self.from(object) DelayedArgumentFromObject.new(object) end |
.from_conf ⇒ Object
Use to specify that a task argument should be initialized from a value in the Conf object. The value will be taken at the point in time where the task is executed.
For instance:
task.new(goal: Roby.from_state.pose.position))
425 426 427 |
# File 'lib/roby/task_arguments.rb', line 425 def self.from_conf from_state(Conf) end |
.from_state(state_object = State) ⇒ Object
Use to specify that a task argument should be initialized from a value in the State
For instance:
task.new(goal: Roby.from_state.pose.position))
413 414 415 |
# File 'lib/roby/task_arguments.rb', line 413 def self.from_state(state_object = State) DelayedArgumentFromState.new(state_object) end |
.inside_control? ⇒ Boolean
True if the current thread is the execution thread of the main engine
See ExecutionEngine#inside_control?
2625 |
# File 'lib/roby/execution_engine.rb', line 2625 def self.inside_control?; execution_engine.inside_control? end |
.log_backtrace(e, logger, level, filter: Roby.app.filter_backtraces?) ⇒ Object
388 389 390 391 392 |
# File 'lib/roby/exceptions.rb', line 388 def self.log_backtrace(e, logger, level, filter: Roby.app.filter_backtraces?) format_backtrace(e, filter: filter).each do |line| logger.send(level, line) end end |
.log_error(e, logger, level, with_backtrace: true) ⇒ Object
417 418 419 420 421 422 423 |
# File 'lib/roby/exceptions.rb', line 417 def self.log_error(e, logger, level, with_backtrace: true) if e.respond_to?(:backtrace) && with_backtrace log_exception_with_backtrace(e, logger, level) else log_exception(e, logger, level) end end |
.log_exception(e, logger, level, with_original_exceptions: true) ⇒ Object
366 367 368 369 370 371 372 373 374 375 376 377 |
# File 'lib/roby/exceptions.rb', line 366 def self.log_exception(e, logger, level, with_original_exceptions: true) return if !log_level_enabled?(logger, level) first_line = true format_exception(e, with_original_exceptions: with_original_exceptions).each do |line| if first_line line = color(line, :bold, :red) first_line = false end logger.send(level, line) end end |
.log_exception_with_backtrace(e, logger, level, filter: Roby.app.filter_backtraces?, with_original_exceptions: true) ⇒ Object
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
# File 'lib/roby/exceptions.rb', line 394 def self.log_exception_with_backtrace(e, logger, level, filter: Roby.app.filter_backtraces?, with_original_exceptions: true) log_exception(e, logger, level, with_original_exceptions: false) logger.send level, color("= Backtrace", :bold, :red) backtrace = e.backtrace if filter backtrace = filter_backtrace(backtrace) end if !backtrace || backtrace.empty? logger.send level, color("= No backtrace", :bold, :red) else logger.send level, color("= ", :bold, :red) log_backtrace(e, logger, level) logger.send level, color("= ", :bold, :red) end if with_original_exceptions && e.respond_to?(:original_exceptions) e.original_exceptions.each do |orig_e| log_exception_with_backtrace(orig_e, logger, level, with_original_exceptions: true) end end end |
.log_level_enabled?(logger, level) ⇒ Boolean
332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/roby/exceptions.rb', line 332 def self.log_level_enabled?(logger, level) logger_level = if logger.respond_to?(:log_level) logger.log_level else logger.level end if numeric_level = LOG_SYMBOLIC_TO_NUMERIC.index(level.to_sym) logger_level <= numeric_level else raise ArgumentError, "#{level} is not a valid log level, log levels are #{LOG_SYMBOLIC_TO_NUMERIC.map(&:inspect).join(", ")}" end end |
.log_pp(obj, logger, level) ⇒ Object
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
# File 'lib/roby/exceptions.rb', line 345 def self.log_pp(obj, logger, level) return if !log_level_enabled?(logger, level) = begin PP.pp(obj, "") rescue Exception => formatting_error begin "error formatting object\n" + obj + "\nplease report the formatting error: \n" + formatting_error. rescue Exception => formatting_error "\nerror formatting object\n" + formatting_error. end end .split("\n").each do |line| logger.send(level, line) end end |
.on_exception(matcher, &handler) ⇒ Object
Defines a global exception handler on the main plan. See also Plan#on_exception
76 |
# File 'lib/roby/singletons.rb', line 76 def self.on_exception(matcher, &handler); Roby.app.plan.on_exception(matcher, &handler) end |
.once ⇒ Object
Execute the given block in the main plan’s propagation context, but don’t wait for its completion like Roby.execute does
See ExecutionEngine#once
2613 |
# File 'lib/roby/execution_engine.rb', line 2613 def self.once; execution_engine.once { yield } end |
.outside_control? ⇒ Boolean
True if the current thread is not the execution thread of the main engine
See ExecutionEngine#outside_control?
2630 |
# File 'lib/roby/execution_engine.rb', line 2630 def self.outside_control?; execution_engine.outside_control? end |
.plan ⇒ Plan
The main plan
It is always the same as Roby.app.plan
22 |
# File 'lib/roby/singletons.rb', line 22 def plan; app.plan end |
.poll_state_events(plan) ⇒ Object
Registered on the execution engines to call the #poll method of state events
100 101 102 103 104 105 106 |
# File 'lib/roby/state/events.rb', line 100 def self.poll_state_events(plan) # :nodoc: for ev in plan.free_events if ev.kind_of?(StateEvent) && ev.enabled? ev.poll end end end |
.pretty_print_backtrace(pp, backtrace, **options) ⇒ Object
285 286 287 288 289 290 291 292 293 294 |
# File 'lib/roby/exceptions.rb', line 285 def self.pretty_print_backtrace(pp, backtrace, **) if backtrace && !backtrace.empty? pp.nest(2) do filter_backtrace(backtrace, **).each do |line| pp.breakable pp.text line end end end end |
.RelationSpace(klass) ⇒ Object
Creates a new relation space which applies on klass. If a block is given, it is eval’d in the context of the new relation space instance
57 58 59 60 61 62 63 |
# File 'lib/roby/relations.rb', line 57 def self.RelationSpace(klass) klass.include Relations::DirectedRelationSupport klass.extend Relations::Models::DirectedRelationSupport relation_space = Relations::Space.new relation_space.apply_on klass relation_space end |
.scheduler ⇒ Object
The main scheduler
It is always the same as Roby.plan.execution_engine.scheduler
38 39 40 |
# File 'lib/roby/singletons.rb', line 38 def scheduler app.plan.execution_engine.scheduler end |
.scheduler=(scheduler) ⇒ Object
Sets the main scheduler
It is always the same as Roby.plan.execution_engine.scheduler
45 46 47 |
# File 'lib/roby/singletons.rb', line 45 def scheduler=(scheduler) app.plan.execution_engine.scheduler = scheduler end |
.wait_one_cycle ⇒ Object
Blocks until the main engine has executed at least one cycle. See ExecutionEngine#wait_one_cycle
2642 |
# File 'lib/roby/execution_engine.rb', line 2642 def self.wait_one_cycle; execution_engine.wait_one_cycle end |
.wait_until(ev, &block) ⇒ Object
Stops the current thread until the given even is emitted. If the event becomes unreachable, an UnreachableEvent exception is raised.
See ExecutionEngine#wait_until
2648 |
# File 'lib/roby/execution_engine.rb', line 2648 def self.wait_until(ev, &block); execution_engine.wait_until(ev, &block) end |
.warn_deprecated(msg, caller_depth = 1) ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/roby/support.rb', line 120 def self.warn_deprecated(msg, caller_depth = 1) if deprecation_warnings_are_errors error_deprecated(msg, caller_depth) elsif enable_deprecation_warnings Roby.warn "Deprecation Warning: #{msg} at #{caller[1, caller_depth].join("\n")}" end end |