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

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

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?



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/roby/task_structure/executed_by.rb', line 157

def added_execution_agent(child, info)
    super
    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
    if !child.used_as_execution_agent?
        if !child.ready_event.emitted?
            child.ready_event.when_unreachable(
                true, &ExecutionAgent.method(:execution_agent_failed_to_start))
        end
        child.stop_event.on(
            &ExecutionAgent.method(:pending_execution_agent_failed))
        child.used_as_execution_agent = true
    end
end

#adding_execution_agent(child, info) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/roby/task_structure/executed_by.rb', line 140

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

    super

    if model_agent = model.execution_agent
        if !child.fullfills?(*model_agent)
            raise Roby::ModelViolation, "execution agent #{child} does not fullfill the expected #{model_agent}"
        end
    end
end

#executed_by(agent) ⇒ Object

Defines a new execution agent for this task.



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/roby/task_structure/executed_by.rb', line 120

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

    return if execution_agent == agent

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

    old_agent = execution_agent
    if old_agent && old_agent != agent
        remove_execution_agent old_agent
    end

    add_execution_agent(agent)
    agent
end