Module: Roby::ExecutionEngine::PropagationHandlerMethods Private

Included in:
Roby::ExecutionEngine, Roby::ExecutionEngine
Defined in:
lib/roby/execution_engine.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Add/remove propagation handler methods that are shared between the instance and the class

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#external_events_handlersArray<PollBlockDefinition> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Code blocks that get called at the beginning of each cycle



259
260
261
# File 'lib/roby/execution_engine.rb', line 259

def external_events_handlers
  @external_events_handlers
end

#propagation_handlersArray<PollBlockDefinition> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Code blocks that get called during propagation to handle some internal propagation mechanism



264
265
266
# File 'lib/roby/execution_engine.rb', line 264

def propagation_handlers
  @propagation_handlers
end

Instance Method Details

#add_propagation_handler(type: :external_events, description: 'propagation handler', **poll_options, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The propagation handlers are blocks that should be called at various places during propagation for all plans. These objects are called in propagation context, which means that the events they would call or emit are injected in the propagation process itself.



316
317
318
319
320
321
322
323
324
# File 'lib/roby/execution_engine.rb', line 316

def add_propagation_handler(type: :external_events, description: 'propagation handler', **poll_options, &block)
    type, handler = create_propagation_handler(type: type, description: description, **poll_options, &block)
    if type == :propagation
        propagation_handlers << handler
    elsif type == :external_events
        external_events_handlers << handler
    end
    handler.id
end

#at_cycle_begin(description: 'at_cycle_begin', **options, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Add a handler that is called at the beginning of the execution cycle



338
339
340
# File 'lib/roby/execution_engine.rb', line 338

def at_cycle_begin(description: 'at_cycle_begin', **options, &block)
    add_propagation_handler(description: description, type: :external_events, **options, &block)
end

#create_propagation_handler(type: :external_events, description: 'propagation handler', **poll_options, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Helper method that gets the arguments necessary top create a propagation handler, sanitizes and normalizes them, and returns both the propagation type and the Roby::ExecutionEngine::PollBlockDefinition object



278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/roby/execution_engine.rb', line 278

def create_propagation_handler(type: :external_events, description: 'propagation handler', **poll_options, &block)
    check_arity block, 1
    handler = PollBlockDefinition.new(description, block, **poll_options)

    if type == :external_events
        if handler.late?
            raise ArgumentError, "only :propagation handlers can be marked as 'late', the external event handlers cannot"
        end
    elsif type != :propagation
        raise ArgumentError, "invalid value for the :type option. Expected :propagation or :external_events, got #{type}"
    end
    return type, handler
end

#each_cycle(description: 'each_cycle', &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Execute the given block at the beginning of each cycle, in propagation context.



347
348
349
# File 'lib/roby/execution_engine.rb', line 347

def each_cycle(description: 'each_cycle', &block)
    add_propagation_handler(description: description, &block)
end

#remove_propagation_handler(id) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method removes a propagation handler which has been added by #add_propagation_handler.



331
332
333
334
335
# File 'lib/roby/execution_engine.rb', line 331

def remove_propagation_handler(id)
    propagation_handlers.delete_if { |p| p.id == id }
    external_events_handlers.delete_if { |p| p.id == id }
    nil
end