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
The set of deployed tasks
@return [{String=>TaskContext}] mapping from the deployed task name as
defined in {model} to the actual ruby task object
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]
The task context class that should be used on the client side
Defaults to {TaskContext}, another option is {StubTaskContext}
@return [Class]
Public Class Methods
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
# 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
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
# 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
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
# File lib/orocos/ruby_tasks/process.rb, line 119 def join raise NotImplementedError, "RemoteProcess#join is not implemented" end
# 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
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
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
# 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
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
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
# 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
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