module Roby::Coordination::Models::Actions

Metamodel for Coordination::Actions

Attributes

action_interface[RW]

The action interface model this state machine model is defined on @return [Actions::Models::Interface,Actions::Models::Library]

Public Instance Methods

depends_on(task, role: nil) click to toggle source

Adds a toplevel dependency

This declares that the given task should always run while self is running

@param [Task] task @return [Task] the task itself

# File lib/roby/coordination/models/actions.rb, line 135
def depends_on(task, role: nil)
    task = validate_task(task)
    dependencies << [task, role]
    task
end
event_active_in_state?(event, state) click to toggle source

@api private

Raise if an event is not “active” while in a particular state

# File lib/roby/coordination/models/actions.rb, line 116
def event_active_in_state?(event, state)
    event.task == root ||
        required_tasks_for(state).has_key?(event.task)
end
forward(*spec) click to toggle source

Declares that the given event on the root task of the state should be forwarded to an event on this task

@overload forward(state.my_event, target_event)

declares that, while in state 'state', forward 'my_event' to the
given event name on the state machine task

@overload forward(state, event, target_event)

declares that, while in state 'state', forward 'event' to the
given event name on the state machine task
# File lib/roby/coordination/models/actions.rb, line 86
def forward(*spec)
    if spec.size == 2
        state_event, target_event = *spec
        forward(state_event.task, state_event, target_event)
    elsif spec.size != 3
        raise ArgumentError, "expected 2 or 3 arguments, got #{spec.size}"
    else
        state, event, target_event = *spec
        if !toplevel_state?(state)
            raise NotToplevelState, "cannot specify #{state} as the state to forward from as it is not a toplevel state"
        elsif !event_active_in_state?(event, state)
            raise EventNotActiveInState, "cannot forward from #{event} while in state #{state} as the event is not active in this state"
        elsif !root_event?(target_event)
            raise NotRootEvent, "can only forward to a root event"
        end

        forwards << [state, event, target_event]
    end
end
from(object) click to toggle source

Helper to build delayed arguments

# File lib/roby/coordination/models/actions.rb, line 163
def from(object)
    Roby::Task.from(object)
end
from_state(state_object = State) click to toggle source

Helper to build delayed arguments

# File lib/roby/coordination/models/actions.rb, line 168
def from_state(state_object = State)
    Roby::Task.from_state(state_object)
end
map_tasks(mapping) click to toggle source

(see Base#map_tasks)

# File lib/roby/coordination/models/actions.rb, line 30
def map_tasks(mapping)
    super

    @forwards = forwards.map do |state, event, target_event|
        state = mapping[state]
        event = mapping[event.task].find_event(event.symbol)
        target_event = mapping[target_event.task].find_event(target_event.symbol)
        [state, event, target_event]
    end

    @dependencies = dependencies.map do |task, role|
        [mapping[task], role]
    end

    @captures = captures.map_value do |capture, (state, event)|
        [mapping[state], mapping[event.task].find_event(event.symbol)]
    end
end
method_missing(m, *args) click to toggle source
# File lib/roby/coordination/models/actions.rb, line 181
def method_missing(m, *args)
    if action = action_interface.find_action_by_name(m.to_s)
        action.new(*args)
    else return super
    end
end
parse(&block) click to toggle source

Evaluates a state machine definition block

# File lib/roby/coordination/models/actions.rb, line 173
def parse(&block)
    class_eval(&block)
end
rebind(action_interface) click to toggle source

Create a new coordination model based on a different action interface

# File lib/roby/coordination/models/actions.rb, line 16
def rebind(action_interface)
    m = dup
    m.action_interface = action_interface

    task_mapping = Hash.new
    task_mapping[root] = root.rebind(m)
    tasks.each do |task|
        task_mapping[task] = task.rebind(m)
    end
    m.map_tasks(task_mapping)
    m
end
required_tasks_for(task) click to toggle source

Returns the set of actions that should be active when the given task is active, as a mapping from the {Task} object to the roles that this object has (as “dependency roles”)

It includes task itself, as task should run when it is active @return [{Task=>Set<String>}]

# File lib/roby/coordination/models/actions.rb, line 147
def required_tasks_for(task)
    result = Hash.new
    task.dependencies.each do |action, role|
        result[action] ||= Set.new
        result[action] << role if role
    end
    each_dependency do |action, role|
        result[action] ||= Set.new
        result[action] << role if role
    end
    result[task] ||= Set.new
    result[task] << 'current_task'
    result
end
respond_to_missing?(m, include_private) click to toggle source
# File lib/roby/coordination/models/actions.rb, line 177
def respond_to_missing?(m, include_private)
    (action_interface && action_interface.find_action_by_name(m.to_s)) || super
end
root_event?(event) click to toggle source

@api private

Raises if the event is not an event of the root task

# File lib/roby/coordination/models/actions.rb, line 124
def root_event?(event)
    event.task == root
end
setup_submodel(submodel, action_interface: nil, **super_options) click to toggle source

Creates a new state machine model as a submodel of self

@param [Model<Coordination::Actions>] submodel the submodel that

is being setup

@option options [Model<Actions::Interface>] :action_interface the action

interface model on which this state machine is defined

@option options [Model<Roby::Task>] :root the task model that is

going to be used as a toplevel task for the state machine
# File lib/roby/coordination/models/actions.rb, line 70
def setup_submodel(submodel, action_interface: nil, **super_options)
    super(submodel, **super_options)
    submodel.action_interface = action_interface
    submodel
end
toplevel_state?(state) click to toggle source

@api private

Raise if the given state is not a toplevel state

# File lib/roby/coordination/models/actions.rb, line 109
def toplevel_state?(state)
    true
end