class Syskit::Deployment

In oroGen, a deployment is a Unix process that holds a certain number of task contexts. This Roby task represents the unix process itself. Once it gets instanciated, the associated task contexts can be accessed with task(name)

Constants

STATE_READER_BUFFER_SIZE

The size of the buffered connection created between this object and the remote task's state port

Attributes

orocos_process[R]

The underlying process object

remote_task_handles[R]

Handles to all remote tasks from this deployment

@return [Hash<String,RemoteTaskHandles>]

Public Class Methods

all_deployments() click to toggle source
# File lib/syskit/deployment.rb, line 62
def all_deployments; @@all_deployments end
new(options = Hash.new) click to toggle source
Calls superclass method
# File lib/syskit/deployment.rb, line 44
def initialize(options = Hash.new)
    super

    @quit_ready_event_monitor = Concurrent::Event.new
    @remote_task_handles = Hash.new
    if !self.spawn_options
        self.spawn_options = Hash.new
    end
    if !self.name_mappings
        self.name_mappings = Hash.new
    end
    model.each_default_name_mapping do |k, v|
        self.name_mappings[k] ||= v
    end
end

Public Instance Methods

create_deployed_task(orogen_task_deployment_model, syskit_task_model, scheduler_task, auto_conf: false) click to toggle source

@api private

Create and add a task model supported by this deployment

@param [OroGen::Spec::TaskDeployment] orogen_task_deployment_model

the orogen model that describes this
deployment

@param [Models::TaskContext,nil] syskit_task_model the expected syskit task model, or nil

if it is meant to use the basic model. This is useful in specialized models (e.g. dynamic
services)

@param [Deployment,TaskContext] syskit_execution_agent the task that will be used as an execution agent.

this is usually self, but may be a task in master/slave relationships.

@param [Boolean] auto_conf if true, the method will attempt to select

a configuration that matches the task's orocos name (if it exists). This
is mostly used for scheduling tasks, which are automatically instanciated
by Syskit.

@see #find_or_create_task task

# File lib/syskit/deployment.rb, line 161
def create_deployed_task(orogen_task_deployment_model,
    syskit_task_model, scheduler_task, auto_conf: false)

    mapped_name = name_mappings[orogen_task_deployment_model.name]
    base_syskit_task_model = TaskContext.
        model_for(orogen_task_deployment_model.task_model)
    if syskit_task_model
        if !(syskit_task_model <= base_syskit_task_model)
            raise ArgumentError, "incompatible explicit selection of task "                             "model #{syskit_task_model} for the model of #{mapped_name} "                             " in #{self}"
        end
    else
        syskit_task_model = base_syskit_task_model
    end

    plan.add(task = syskit_task_model.new(orocos_name: mapped_name))
    task.executed_by self
    if scheduler_task
        task.depends_on scheduler_task, role: 'scheduler'
        task.should_configure_after scheduler_task.start_event
    end

    task.orogen_model = orogen_task_deployment_model
    if ready?
        if remote_task = remote_task_handles[mapped_name]
            task.initialize_remote_handles(remote_task)
        else
            raise InternalError, "no remote handle describing #{mapped_name} in #{self} for #{task} (got #{remote_task_handles.keys.sort.join(", ")})"
        end
    end
    auto_select_conf(task) if auto_conf
    task
end
each_orogen_deployed_task_context_model(&block) click to toggle source

The list of deployed task contexts for this particular deployment

It takes into account deployment prefix

# File lib/syskit/deployment.rb, line 104
def each_orogen_deployed_task_context_model(&block)
    model.each_orogen_deployed_task_context_model(&block)
end
find_or_create_task(name, syskit_task_model = nil, auto_conf: false) click to toggle source

Either find the existing task that matches the given deployment specification, or creates and adds it.

@param (see task)

# File lib/syskit/deployment.rb, line 112
def find_or_create_task(name, syskit_task_model = nil, auto_conf: false)
    orogen_task_deployment_model = each_orogen_deployed_task_context_model.
        find { |act| name == name_mappings[act.name] }
    if orogen_master = orogen_task_deployment_model.master
        mapped_master = name_mappings[orogen_master.name]
        scheduler_task = find_or_create_task(
            mapped_master, auto_conf: true)
        candidates = scheduler_task.each_parent_task
    else
        candidates = each_executed_task
    end

    # I don't know why name_mappings[orogen.name] would not be
    # equal to 'name' and I couldn't find a reason for this in the
    # git history when I refactored this.
    #
    # I keep it here for now, just in case, but that would need to
    # be investigated
    #
    # TODO
    mapped_name = name_mappings[orogen_task_deployment_model.name]
    candidates.each do |task|
        return task if task.orocos_name == mapped_name
    end

    create_deployed_task(
        orogen_task_deployment_model,
        syskit_task_model,
        scheduler_task, auto_conf: auto_conf)
end
has_orocos_name?(orocos_name) click to toggle source
# File lib/syskit/deployment.rb, line 91
def has_orocos_name?(orocos_name)
    name_mappings.each_value.any? { |n| n == orocos_name }
end
instanciate_all_tasks() click to toggle source
# File lib/syskit/deployment.rb, line 95
def instanciate_all_tasks
    model.each_orogen_deployed_task_context_model.map do |act|
        task(name_mappings[act.name])
    end
end
pid() click to toggle source

The PID of this process

# File lib/syskit/deployment.rb, line 66
def pid
    if running?
        @pid ||= orocos_process.pid
    end
end
process_server_config() click to toggle source

An object describing the underlying pocess server

@return [RobyApp::Configuration::ProcessServerConfig]

# File lib/syskit/deployment.rb, line 40
def process_server_config
    @process_server_config ||= Syskit.conf.process_server_config_for(process_server_name)
end
task(name, syskit_task_model = nil) click to toggle source

Returns an task instance that represents the given task in this deployment.

@param [String] name the unmapped name of the task @param [Models::TaskContext,nil] syskit_task_model the Syskit

model that should be used to create the task, if it is not the
same as the base model. This is used for specialized models (e.g.
dynamic services)
# File lib/syskit/deployment.rb, line 204
def task(name, syskit_task_model = nil)
    if finishing? || finished?
        raise InvalidState, "#{self} is either finishing or already "                         "finished, you cannot call #task"
    end

    orogen_task_deployment_model = each_orogen_deployed_task_context_model.
        find { |act| name == name_mappings[act.name] }
    if !orogen_task_deployment_model
        available = each_orogen_deployed_task_context_model.
            map { |act| name_mappings[act.name] }.sort.join(", ")
        mappings  = name_mappings.map { |k,v| "#{k} => #{v}" }.join(", ")
        raise ArgumentError, "no task called #{name} in "                         "#{self.class.deployment_name}, available tasks are #{available}"                         " using name mappings #{mappings}"
    end

    if orogen_master = orogen_task_deployment_model.master
        scheduler_task = find_or_create_task(
            orogen_master.name, auto_conf: true)
    end
    create_deployed_task(orogen_task_deployment_model,
        syskit_task_model, scheduler_task)
end