Module: Roby::TaskStructure::ExecutionAgent::Extension

Defined in:
lib/roby/task_structure/executed_by.rb

Overview

Module mixed-in Roby::Task in support for execution agent handling

Instance Method Summary collapse

Instance Method Details

#added_execution_agent(child, info) ⇒ Object

Installs the handlers needed for fault handling

See the documentation of #used_with_an_execution_agent?



149
150
151
152
153
154
155
156
# File 'lib/roby/task_structure/executed_by.rb', line 149

def added_execution_agent(child, info)
    super

    setup_as_executed_task_if_needed
    child.setup_as_execution_agent_if_needed

    nil
end

#adding_execution_agent(child, info) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/roby/task_structure/executed_by.rb', line 130

def adding_execution_agent(child, info)
    if running?
        raise ExecutedTaskAlreadyRunning,
              "#{self} is already running, cannot add or change its agent"
    end

    super

    return unless (model_agent = model.execution_agent)
    return if child.fullfills?(*model_agent)

    raise Roby::ModelViolation,
          "execution agent #{child} does not fullfill "\
          "the expected #{model_agent}"
end

#executed_by(agent) ⇒ Object

Defines a new execution agent for this task.



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/roby/task_structure/executed_by.rb', line 114

def executed_by(agent)
    agent = agent.as_plan if agent.respond_to?(:as_plan)
    return if execution_agent == agent

    unless agent.has_event?(:ready)
        raise ArgumentError,
              "execution agent tasks should define the :ready event"
    end

    # Remove the current agent if there is one
    remove_execution_agent execution_agent if execution_agent

    add_execution_agent(agent)
    agent
end

#setup_as_executed_task_if_neededObject



158
159
160
161
162
163
164
165
166
167
168
# File 'lib/roby/task_structure/executed_by.rb', line 158

def setup_as_executed_task_if_needed
    return if used_with_an_execution_agent?

    start_event.on(
        &ExecutionAgent.method(:establish_agent_aborted_relation)
    )
    stop_event.on(
        &ExecutionAgent.method(:remove_agent_aborted_relation)
    )
    self.used_with_an_execution_agent = true
end

#setup_as_execution_agent_if_neededObject



170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/roby/task_structure/executed_by.rb', line 170

def setup_as_execution_agent_if_needed
    return if used_as_execution_agent?

    unless ready_event.emitted?
        ready_event.when_unreachable(
            true,
            &ExecutionAgent.method(:execution_agent_failed_to_start)
        )
    end
    stop_event.on(
        &ExecutionAgent.method(:pending_execution_agent_failed)
    )
    self.used_as_execution_agent = true
end