class Orocos::RubyTasks::Process

Representation and management of a set of ruby tasks

This provides a {Orocos::Process}-compatible API to ruby tasks. It allows to define tasks in an oroGen deployment model and “spawn” them all at once, as well as dispose of them all at once.

Attributes

deployed_tasks[R]

The set of deployed tasks

@return [{String=>TaskContext}] mapping from the deployed task name as

defined in {model} to the actual ruby task object
ruby_process_server[R]

The Ruby process server that spawned this process

If non-nil, the object's dead_deployment will be called when self is stopped

@return [#dead_deployment,nil]

task_context_class[R]

The task context class that should be used on the client side

Defaults to {TaskContext}, another option is {StubTaskContext}

@return [Class]

Public Class Methods

new(ruby_process_server, name, model, task_context_class: TaskContext) click to toggle source

Creates a new ruby task process

@param [nil,#dead_deployment] #ruby_process_server the process manager

which creates this process. If non-nil, its #dead_deployment method
will be called when this process stops

@param [String] name the process name @param [OroGen::Spec::Deployment] model the deployment model

Calls superclass method Orocos::ProcessBase.new
# File lib/orocos/ruby_tasks/process.rb, line 63
def initialize(ruby_process_server, name, model, task_context_class: TaskContext)
    @ruby_process_server = ruby_process_server
    @deployed_tasks = Hash.new
    @task_context_class = task_context_class
    super(name, model)
end

Public Instance Methods

alive?() click to toggle source

True if the process is running. This is an alias for running?

# File lib/orocos/ruby_tasks/process.rb, line 124
def alive?; @alive end
dead!(status = ProcessManager::Status.new(:exit_code => 0)) click to toggle source
# File lib/orocos/ruby_tasks/process.rb, line 112
def dead!(status = ProcessManager::Status.new(:exit_code => 0))
    @alive = false
    if ruby_process_server
        ruby_process_server.dead_deployment(name, status)
    end
end
host_id() click to toggle source

The host on which this process' tasks run

This is always 'localhost' as ruby tasks are instanciated inside the ruby process

@return [String]

# File lib/orocos/ruby_tasks/process.rb, line 30
def host_id; 'localhost' end
join() click to toggle source
# File lib/orocos/ruby_tasks/process.rb, line 119
def join
    raise NotImplementedError, "RemoteProcess#join is not implemented"
end
kill(wait = true, status = ProcessManager::Status.new(:exit_code => 0)) click to toggle source
# File lib/orocos/ruby_tasks/process.rb, line 105
def kill(wait = true, status = ProcessManager::Status.new(:exit_code => 0))
    deployed_tasks.each_value do |task|
        task.dispose
    end
    dead!(status)
end
on_localhost?() click to toggle source

Whether the tasks in this process are running on the same machine than the ruby process

This is always true as ruby tasks are instanciated inside the ruby process

@return [Boolean]

# File lib/orocos/ruby_tasks/process.rb, line 39
def on_localhost?; true end
pid() click to toggle source

The PID of the process in which the tasks run

This is always #pid as ruby tasks are instanciated inside the ruby process

@return [Integer]

# File lib/orocos/ruby_tasks/process.rb, line 47
def pid; ::Process.pid end
resolve_all_tasks(cache = Hash.new) click to toggle source
# File lib/orocos/ruby_tasks/process.rb, line 99
def resolve_all_tasks(cache = Hash.new)
    Orocos::Process.resolve_all_tasks(self, cache) do |task_name|
        task(task_name)
    end
end
running?() click to toggle source

True if the process is running. This is an alias for alive?

# File lib/orocos/ruby_tasks/process.rb, line 126
def running?; @alive end
spawn(options = Hash.new) click to toggle source

Deploys the tasks defined in {model} as ruby tasks

@return [void]

# File lib/orocos/ruby_tasks/process.rb, line 73
def spawn(options = Hash.new)
    model.task_activities.each do |deployed_task|
        name = get_mapped_name(deployed_task.name)
        Orocos.allow_blocking_calls do
            deployed_tasks[name] = task_context_class.
                from_orogen_model(name, deployed_task.task_model)
        end
    end
    @alive = true
end
task(task_name) click to toggle source
# File lib/orocos/ruby_tasks/process.rb, line 92
def task(task_name)
    if t = deployed_tasks[task_name]
        t
    else raise ArgumentError, "#{self} has no task called #{task_name}, known tasks: #{deployed_tasks.keys.sort.join(", ")}"
    end
end
wait_running(blocking = false) click to toggle source

Waits for the tasks to be ready

This is a no-op for ruby tasks as they are ready as soon as they are created

# File lib/orocos/ruby_tasks/process.rb, line 88
def wait_running(blocking = false)
    true
end